|
1 |
| -const chai = require("chai"); |
2 |
| -chai.config.truncateThreshold = 0; |
3 |
| -const {assert} = chai; |
| 1 | +import {readFileSync} from "fs"; |
| 2 | +import {assert, config as chaiConfig} from "chai"; |
| 3 | +chaiConfig.truncateThreshold = 0; |
4 | 4 |
|
5 |
| -const LC = require("../../src/lambda-calculus.js"); |
| 5 | +import * as LC from "../../src/lambda-calculus.js"; |
6 | 6 | LC.config.purity = "LetRec";
|
7 | 7 | LC.config.numEncoding = "Scott";
|
8 | 8 |
|
9 |
| -const {isPrime} = LC.compile(); |
| 9 | +const solutionText = readFileSync(new URL("./solution.txt", import.meta.url), {encoding: "utf8"}); |
| 10 | +const {isPrime} = LC.compile(solutionText); |
10 | 11 | const fromInt = LC.fromIntWith(LC.config);
|
11 | 12 |
|
12 |
| -it("fixed tests", function() { |
13 |
| - this.timeout(12e3); |
14 |
| - assert.equal( isPrime(fromInt( 0)) (true)(false), false ); |
15 |
| - assert.equal( isPrime(fromInt( 1)) (true)(false), false ); |
16 |
| - assert.equal( isPrime(fromInt( 2)) (true)(false), true ); |
17 |
| - assert.equal( isPrime(fromInt( 3)) (true)(false), true ); |
18 |
| - assert.equal( isPrime(fromInt( 4)) (true)(false), false ); |
19 |
| - assert.equal( isPrime(fromInt( 5)) (true)(false), true ); |
20 |
| - assert.equal( isPrime(fromInt( 6)) (true)(false), false ); |
21 |
| - assert.equal( isPrime(fromInt( 7)) (true)(false), true ); |
22 |
| - assert.equal( isPrime(fromInt( 8)) (true)(false), false ); |
23 |
| - assert.equal( isPrime(fromInt( 9)) (true)(false), false ); |
24 |
| - assert.equal( isPrime(fromInt(10)) (true)(false), false ); |
25 |
| - assert.equal( isPrime(fromInt(11)) (true)(false), true ); |
26 |
| - assert.equal( isPrime(fromInt(12)) (true)(false), false ); |
27 |
| - assert.equal( isPrime(fromInt(13)) (true)(false), true ); |
28 |
| - assert.equal( isPrime(fromInt(14)) (true)(false), false ); |
29 |
| - assert.equal( isPrime(fromInt(15)) (true)(false), false ); |
30 |
| - assert.equal( isPrime(fromInt(16)) (true)(false), false ); |
31 |
| - assert.equal( isPrime(fromInt(17)) (true)(false), true ); |
32 |
| - assert.equal( isPrime(fromInt(18)) (true)(false), false ); |
33 |
| - assert.equal( isPrime(fromInt(19)) (true)(false), true ); |
| 13 | +describe("is-prime-scott", () => { |
| 14 | + it("fixed tests", function() { |
| 15 | + this.timeout(12e3); |
| 16 | + assert.equal( isPrime(fromInt( 0)) (true)(false), false ); |
| 17 | + assert.equal( isPrime(fromInt( 1)) (true)(false), false ); |
| 18 | + assert.equal( isPrime(fromInt( 2)) (true)(false), true ); |
| 19 | + assert.equal( isPrime(fromInt( 3)) (true)(false), true ); |
| 20 | + assert.equal( isPrime(fromInt( 4)) (true)(false), false ); |
| 21 | + assert.equal( isPrime(fromInt( 5)) (true)(false), true ); |
| 22 | + assert.equal( isPrime(fromInt( 6)) (true)(false), false ); |
| 23 | + assert.equal( isPrime(fromInt( 7)) (true)(false), true ); |
| 24 | + assert.equal( isPrime(fromInt( 8)) (true)(false), false ); |
| 25 | + assert.equal( isPrime(fromInt( 9)) (true)(false), false ); |
| 26 | + assert.equal( isPrime(fromInt(10)) (true)(false), false ); |
| 27 | + assert.equal( isPrime(fromInt(11)) (true)(false), true ); |
| 28 | + assert.equal( isPrime(fromInt(12)) (true)(false), false ); |
| 29 | + assert.equal( isPrime(fromInt(13)) (true)(false), true ); |
| 30 | + assert.equal( isPrime(fromInt(14)) (true)(false), false ); |
| 31 | + assert.equal( isPrime(fromInt(15)) (true)(false), false ); |
| 32 | + assert.equal( isPrime(fromInt(16)) (true)(false), false ); |
| 33 | + assert.equal( isPrime(fromInt(17)) (true)(false), true ); |
| 34 | + assert.equal( isPrime(fromInt(18)) (true)(false), false ); |
| 35 | + assert.equal( isPrime(fromInt(19)) (true)(false), true ); |
| 36 | + }); |
34 | 37 | });
|
0 commit comments