Skip to content

Commit 2e79518

Browse files
committed
Fix multiply
1 parent e6983ab commit 2e79518

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

tests/multiply/initialSolution.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
multiply = \ m n . n (m s ) z

tests/multiply/solution.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
multiply = \ m n . n (m s ) z
1+
multiply = \ m n s . n ( m s )

tests/multiply/test.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ chaiConfig.truncateThreshold = 0;
66
import * as LC from "../../src/lambda-calculus.js";
77
LC.config.purity = "LetRec";
88
LC.config.numEncoding = "Church";
9-
// LC.config.verbosity = "Concise"; // reinstate for production
9+
LC.config.verbosity = "Concise";
1010

1111
const solutionText = readFileSync(new URL("./solution.txt", import.meta.url), {encoding: "utf8"});
12+
const {multiply} = LC.compile(solutionText);
13+
const fromInt = LC.fromIntWith(LC.config);
14+
const toInt = LC.toIntWith(LC.config);
1215

13-
describe("Multiply",function(){
14-
// REVIEW Is this intentional? If so, it should be tested that `compile` throws
15-
// and remove other test cases.
16-
try {
17-
const {multiply} = LC.compile(solutionText);
18-
it("example tests",()=>{
19-
assert.equal( multiply(7)(7), 49 );
20-
assert.equal( multiply(11)(11), 121 );
16+
describe("Multiply",()=>{
17+
18+
it("example tests",function(){
19+
assert.equal( toInt(multiply(fromInt(7))(fromInt(7))), 49 );
20+
assert.equal( toInt(multiply(fromInt(11))(fromInt(11))), 121 );
2121
});
22-
it("random tests",()=>{
22+
23+
it("random tests",function(){
2324
const rnd = (m,n=0) => Math.random() * (n-m) + m | 0 ;
2425
for ( let i=1; i<=100; i++ ) {
2526
const m = rnd(i), n = rnd(i);
26-
assert.equal( multiply(m)(n), m*n );
27+
assert.equal( toInt(multiply(fromInt(m))(fromInt(n))), m*n );
2728
}
2829
});
29-
} catch (e) {
30-
console.error(e);
31-
}
3230
});

0 commit comments

Comments
 (0)