Skip to content

Commit e1e27d5

Browse files
authored
Merge pull request #108 from JohanWiltink/main
add `mul`, `dbl` to negabinary-scott-test
2 parents 9fcb1c3 + 065fe7a commit e1e27d5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/negabinary-scott/solution.lc

+4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ pred = snd Enum
5050
add = \ m n . m n
5151
( \ zm . n m ( \ zn . nega-dbl (add zm zn) ) ( \ zn . Bit1 (add zm zn) ) )
5252
( \ zm . n m ( \ zn . Bit1 (add zm zn) ) ( \ zn . nega-dbl (pred (add zm zn)) ) )
53+
mul = \ m n . m 0
54+
( \ zm . n 0 ( \ zn . Bit0 (Bit0 (mul zm zn)) ) ( \ _z . Bit0 (mul zm n) ) )
55+
( \ zm . n 0 ( \ zn . Bit0 (mul m zn) ) ( \ zn . Bit1 (add (nega-dbl (mul zm zn)) (add zm zn)) ) )
5356

5457
negate = \ n . add n (nega-dbl n)
5558
sub = \ m n . add m (negate n)
59+
dbl = \ m . m 0 ( \ n . Bit0 (dbl n) ) ( \ n . nega-dbl (pred (dbl n)) )
5660
zero = \ n . n True (K False) (K False)
5761

5862
Ord = Y4 (Quad (T \ lt0 le0 ge0 gt0 . \ n . n False gt0 gt0) # lt0

tests/negabinary-scott/test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LC.configure({ purity: "LetRec", numEncoding: { fromInt, toInt } });
1919

2020
const solutionText = readFileSync(new URL("./solution.lc", import.meta.url), {encoding: "utf8"});
2121
const solution = LC.compile(solutionText);
22-
const { succ,pred, add,negate,sub, zero, lt0,le0,ge0,gt0,compare } = solution;
22+
const { succ,pred, add,mul,negate,sub,dbl, zero, lt0,le0,ge0,gt0,compare } = solution;
2323

2424
const toBoolean = p => p (true) (false) ;
2525
const toOrdering = cmp => cmp ("LT") ("EQ") ("GT") ;
@@ -43,6 +43,11 @@ describe("NegaBinaryScott", () => {
4343
for ( let n=-10; n<=10; n++ )
4444
assert.strictEqual( toInt(add(m)(n)), m+n, `add ${ m } ${ n }` );
4545
});
46+
it("mul", () => {
47+
for ( let m=-10; m<=10; m++ )
48+
for ( let n=-10; n<=10; n++ )
49+
assert.strictEqual( toInt(mul(m)(n)), m*n, `mul ${ m } ${ n }` );
50+
});
4651
it("negate", () => {
4752
for ( let n=-10; n<=10; n++ )
4853
assert.strictEqual( toInt(negate(n)), -n, `negate ${ n }` );
@@ -56,6 +61,10 @@ describe("NegaBinaryScott", () => {
5661
for ( let n=-10; n<=10; n++ )
5762
assert.strictEqual( toInt(sub(m)(n)), m-n, `sub ${ m } ${ n }` );
5863
});
64+
it("dbl", () => {
65+
for ( let n=-10; n<=10; n++ )
66+
assert.strictEqual( toInt(dbl(n)), 2*n, `dbl ${ n }` );
67+
});
5968
it("eq, uneq", () => {
6069
for ( let n=-10; n<=10; n++ )
6170
assert.strictEqual(toBoolean(zero(n)),n===0,`zero ${ n }`),

0 commit comments

Comments
 (0)