From 065fe7aa7fd91f6df879267368982244ad6a1bb4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 4 Feb 2024 03:44:07 +0100 Subject: [PATCH] add `mul`, `dbl` to negabinary-scott-test --- tests/negabinary-scott/solution.lc | 4 ++++ tests/negabinary-scott/test.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/negabinary-scott/solution.lc b/tests/negabinary-scott/solution.lc index b70aabd..4a3f8b8 100644 --- a/tests/negabinary-scott/solution.lc +++ b/tests/negabinary-scott/solution.lc @@ -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 diff --git a/tests/negabinary-scott/test.js b/tests/negabinary-scott/test.js index 303ab61..19ddf91 100644 --- a/tests/negabinary-scott/test.js +++ b/tests/negabinary-scott/test.js @@ -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") ; @@ -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 }` ); @@ -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 }`),