Skip to content

Commit 67121e8

Browse files
committed
add negate . negate testing
1 parent 406668a commit 67121e8

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

tests/negabinary-scott/test.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ LC.configure({ purity: "LetRec", numEncoding: { fromInt, toInt } });
2020
const solutionText = readFileSync(new URL("./solution.lc", import.meta.url), {encoding: "utf8"});
2121
const solution = LC.compile(solutionText);
2222
const { succ,pred, add,negate,sub, zero, lt0,le0,ge0,gt0,compare } = solution;
23-
const { True,False, LT,EQ,GT } = solution;
2423

2524
const toBoolean = p => p (true) (false) ;
2625
const toOrdering = cmp => cmp ("LT") ("EQ") ("GT") ;
@@ -33,46 +32,41 @@ describe("NegaBinaryScott", () => {
3332
});
3433
it("succ", () => {
3534
for ( let n=-10; n<=10; n++ )
36-
assert.strictEqual( toInt(succ(fromInt(n))), n+1, `succ ${ n }` );
37-
// assert.strictEqual( toInt(pred(fromInt(n))), n-1, `pred ${ n }` );
35+
assert.strictEqual( toInt(succ(n)), n+1, `succ ${ n }` );
3836
});
3937
it("pred", () => {
4038
for ( let n=-10; n<=10; n++ )
41-
// assert.strictEqual( toInt(succ(fromInt(n))), n+1, `succ ${ n }` ),
42-
assert.strictEqual( toInt(pred(fromInt(n))), n-1, `pred ${ n }` );
39+
assert.strictEqual( toInt(pred(n)), n-1, `pred ${ n }` );
4340
});
4441
it("add", () => {
4542
for ( let m=-10; m<=10; m++ )
46-
for ( let n=-10; n<=10; n++ ) {
47-
const actual = toInt(add(fromInt(m))(fromInt(n)));
48-
assert.strictEqual(actual,m+n,`add ${ m } ${ n }`);
49-
}
43+
for ( let n=-10; n<=10; n++ )
44+
assert.strictEqual( toInt(add(m)(n)), m+n, `add ${ m } ${ n }` );
5045
});
5146
it("negate", () => {
5247
for ( let n=-10; n<=10; n++ )
53-
assert.strictEqual( toInt(negate(fromInt(n))), -n, `negate ${ n }` );
48+
assert.strictEqual( toInt(negate(n)), -n, `negate ${ n }` );
49+
});
50+
it("negate . negate", () => {
51+
for ( let n=-10; n<=10; n++ )
52+
assert.strictEqual( toInt(negate(negate(n))), n, `negate (negate ${ n })` );
5453
});
5554
it("sub", () => {
5655
for ( let m=-10; m<=10; m++ )
57-
for ( let n=-10; n<=10; n++ ) {
58-
const actual = toInt(sub(fromInt(m))(fromInt(n)));
59-
assert.strictEqual(actual,m-n,`sub ${ m } ${ n }`);
60-
}
56+
for ( let n=-10; n<=10; n++ )
57+
assert.strictEqual( toInt(sub(m)(n)), m-n, `sub ${ m } ${ n }` );
6158
});
6259
it("eq, uneq", () => {
6360
for ( let n=-10; n<=10; n++ )
64-
assert.equal(toBoolean(zero(fromInt(n))),n===0,`zero ${ n }`),
65-
assert.equal(toBoolean(lt0(fromInt(n))),n<0,`lt0 ${ n }`),
66-
assert.equal(toBoolean(le0(fromInt(n))),n<=0,`le0 ${ n }`),
67-
assert.equal(toBoolean(ge0(fromInt(n))),n>=0,`ge0 ${ n }`),
68-
assert.equal(toBoolean(gt0(fromInt(n))),n>0,`gt0 ${ n }`);
61+
assert.strictEqual(toBoolean(zero(n)),n===0,`zero ${ n }`),
62+
assert.strictEqual(toBoolean(lt0(n)),n<0,`lt0 ${ n }`),
63+
assert.strictEqual(toBoolean(le0(n)),n<=0,`le0 ${ n }`),
64+
assert.strictEqual(toBoolean(ge0(n)),n>=0,`ge0 ${ n }`),
65+
assert.strictEqual(toBoolean(gt0(n)),n>0,`gt0 ${ n }`);
6966
});
7067
it("compare", () => {
7168
for ( let m=-10; m<=10; m++ )
72-
for ( let n=-10; n<=10; n++ ) {
73-
const actual = toOrdering(compare(fromInt(m))(fromInt(n)));
74-
const expected = m > n ? "GT" : m < n ? "LT" : "EQ" ;
75-
assert.equal(actual,expected,`compare ${ m } ${ n }`);
76-
}
69+
for ( let n=-10; n<=10; n++ )
70+
assert.strictEqual( toOrdering(compare(m)(n)), m > n ? "GT" : m < n ? "LT" : "EQ" , `compare ${ m } ${ n }` );
7771
});
7872
});

0 commit comments

Comments
 (0)