Skip to content

Commit efc6c87

Browse files
author
Johan Wiltink
committed
add multiply to tests
1 parent 33a6bb2 commit efc6c87

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

tests/multiply/solution.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
multiply = \ m n . n (m s ) z

tests/multiply/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const {assert} = require("chai");
2+
3+
const LC = require("../../src/lambda-calculus.js");
4+
LC.config.purity = "LetRec";
5+
LC.config.numEncoding = "Church";
6+
LC.config.verbosity = "Concise";
7+
8+
const {multiply} = LC.compile();
9+
10+
describe("Multiply",function(){
11+
it("example tests",()=>{
12+
assert.equal( multiply(7)(7), 49 );
13+
assert.equal( multiply(11)(11), 121 );
14+
});
15+
it("random tests",()=>{
16+
const rnd = (m,n=0) => Math.random() * (n-m) + m | 0 ;
17+
for ( let i=1; i<=100; i++ ) {
18+
const m = rnd(i), n = rnd(i);
19+
assert.equal( multiply(m)(n), m*n );
20+
}
21+
});
22+
});

tests/run-tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const examples = [ "basics-binary-scott"
1010
, "is-prime"
1111
, "is-prime-scott"
1212
, "prime-sieve"
13+
, "multiply"
1314
];
1415

1516
try {

0 commit comments

Comments
 (0)