Skip to content

Commit

Permalink
Merge pull request #108 from JohanWiltink/main
Browse files Browse the repository at this point in the history
add `mul`, `dbl` to negabinary-scott-test
  • Loading branch information
JohanWiltink authored Feb 4, 2024
2 parents 9fcb1c3 + 065fe7a commit e1e27d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/negabinary-scott/solution.lc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ pred = snd Enum
add = \ m n . m n
( \ zm . n m ( \ zn . nega-dbl (add zm zn) ) ( \ zn . Bit1 (add zm zn) ) )
( \ zm . n m ( \ zn . Bit1 (add zm zn) ) ( \ zn . nega-dbl (pred (add zm zn)) ) )
mul = \ m n . m 0
( \ zm . n 0 ( \ zn . Bit0 (Bit0 (mul zm zn)) ) ( \ _z . Bit0 (mul zm n) ) )
( \ zm . n 0 ( \ zn . Bit0 (mul m zn) ) ( \ zn . Bit1 (add (nega-dbl (mul zm zn)) (add zm zn)) ) )

negate = \ n . add n (nega-dbl n)
sub = \ m n . add m (negate n)
dbl = \ m . m 0 ( \ n . Bit0 (dbl n) ) ( \ n . nega-dbl (pred (dbl n)) )
zero = \ n . n True (K False) (K False)

Ord = Y4 (Quad (T \ lt0 le0 ge0 gt0 . \ n . n False gt0 gt0) # lt0
Expand Down
11 changes: 10 additions & 1 deletion tests/negabinary-scott/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LC.configure({ purity: "LetRec", numEncoding: { fromInt, toInt } });

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

const toBoolean = p => p (true) (false) ;
const toOrdering = cmp => cmp ("LT") ("EQ") ("GT") ;
Expand All @@ -43,6 +43,11 @@ describe("NegaBinaryScott", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(add(m)(n)), m+n, `add ${ m } ${ n }` );
});
it("mul", () => {
for ( let m=-10; m<=10; m++ )
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(mul(m)(n)), m*n, `mul ${ m } ${ n }` );
});
it("negate", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(negate(n)), -n, `negate ${ n }` );
Expand All @@ -56,6 +61,10 @@ describe("NegaBinaryScott", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(sub(m)(n)), m-n, `sub ${ m } ${ n }` );
});
it("dbl", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual( toInt(dbl(n)), 2*n, `dbl ${ n }` );
});
it("eq, uneq", () => {
for ( let n=-10; n<=10; n++ )
assert.strictEqual(toBoolean(zero(n)),n===0,`zero ${ n }`),
Expand Down

0 comments on commit e1e27d5

Please sign in to comment.