diff --git a/Dockerfile b/Dockerfile index 318e5fd..0a597a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN set -ex; \ COPY --chown=codewarrior:codewarrior workspace/package.json /workspace/package.json COPY --chown=codewarrior:codewarrior workspace/package-lock.json /workspace/package-lock.json -COPY --chown=codewarrior:codewarrior workspace/files.js /workspace/files.js +COPY --chown=codewarrior:codewarrior workspace/lc-test.js /workspace/lc-test.js USER codewarrior WORKDIR /workspace diff --git a/example/test.js b/example/test.js index b97fd50..cf32b90 100644 --- a/example/test.js +++ b/example/test.js @@ -1,11 +1,7 @@ -import { assert, config as chaiConfig } from "chai"; -chaiConfig.truncateThreshold = 0; - -import * as LC from "@codewars/lambda-calculus"; -import { solution } from "./files.js"; // /workspace/files.js +import { assert, LC, getSolution } from "./lc-test.js"; LC.configure({ purity: "Let", numEncoding: "Church" }); -const { counter } = LC.compile(solution()); +const { counter } = LC.compile(getSolution()); const T = t => _ => t; const F = _ => f => f; diff --git a/workspace/files.js b/workspace/files.js deleted file mode 100644 index 0a0353c..0000000 --- a/workspace/files.js +++ /dev/null @@ -1,9 +0,0 @@ -import { readFileSync } from "fs"; - -const read = (path) => readFileSync(new URL(path, import.meta.url), {encoding: "utf8"}); - -/** Return the contents of the solution file */ -export const solution = () => read("./solution.lc"); - -/** Return the contents of the optional preloaded file */ -export const preloaded = () => read("./preloaded.lc"); diff --git a/workspace/lc-test.js b/workspace/lc-test.js new file mode 100644 index 0000000..2aac362 --- /dev/null +++ b/workspace/lc-test.js @@ -0,0 +1,15 @@ +import { readFileSync } from "fs"; + +export { assert, config } from "chai"; +export * as LC from "@codewars/lambda-calculus"; + +const read = (path) => readFileSync(new URL(path, import.meta.url), {encoding: "utf8"}); + +/** Return the contents of the solution file */ +export const getSolution = () => read("./solution.lc"); + +/** Return the contents of the optional preloaded file */ +export const getPreloaded = () => read("./preloaded.lc"); + +/** Return the contents of the preloaded file and the solution file combined */ +export const getSolutionWithPreloaded = () => getPreloaded() + "\n" + getSolution(); diff --git a/workspace/package-lock.json b/workspace/package-lock.json index 5c89b44..043d67d 100644 --- a/workspace/package-lock.json +++ b/workspace/package-lock.json @@ -8,7 +8,7 @@ "name": "@codewars/lc-challenge", "version": "1.0.0", "dependencies": { - "@codewars/lambda-calculus": "^1.0.0-rc.3" + "@codewars/lambda-calculus": "^1.0.0-rc.4" }, "devDependencies": { "@codewars/mocha-reporter": "^1.0.0", @@ -17,9 +17,9 @@ } }, "node_modules/@codewars/lambda-calculus": { - "version": "1.0.0-rc.3", - "resolved": "https://registry.npmjs.org/@codewars/lambda-calculus/-/lambda-calculus-1.0.0-rc.3.tgz", - "integrity": "sha512-kQPH45O325p/7ooOkuCJ4FLCOT9+Ou+BWewd/sOubEsrQjjVLS7jNNOC9ylzPumKhDmCmJu71Am/mPGAjAkioA==" + "version": "1.0.0-rc.4", + "resolved": "https://registry.npmjs.org/@codewars/lambda-calculus/-/lambda-calculus-1.0.0-rc.4.tgz", + "integrity": "sha512-/k9kVI/Scpgc3EjPJ7wU9fo0CwXKsFCVceNoXNn0wF/sKEwL+DxAPC5+0AMiClmynbs9TMbHEN3ct9/ic0XkUA==" }, "node_modules/@codewars/mocha-reporter": { "version": "1.0.0", @@ -1035,9 +1035,9 @@ }, "dependencies": { "@codewars/lambda-calculus": { - "version": "1.0.0-rc.3", - "resolved": "https://registry.npmjs.org/@codewars/lambda-calculus/-/lambda-calculus-1.0.0-rc.3.tgz", - "integrity": "sha512-kQPH45O325p/7ooOkuCJ4FLCOT9+Ou+BWewd/sOubEsrQjjVLS7jNNOC9ylzPumKhDmCmJu71Am/mPGAjAkioA==" + "version": "1.0.0-rc.4", + "resolved": "https://registry.npmjs.org/@codewars/lambda-calculus/-/lambda-calculus-1.0.0-rc.4.tgz", + "integrity": "sha512-/k9kVI/Scpgc3EjPJ7wU9fo0CwXKsFCVceNoXNn0wF/sKEwL+DxAPC5+0AMiClmynbs9TMbHEN3ct9/ic0XkUA==" }, "@codewars/mocha-reporter": { "version": "1.0.0", diff --git a/workspace/package.json b/workspace/package.json index 51ffcf1..8fa7b39 100644 --- a/workspace/package.json +++ b/workspace/package.json @@ -11,7 +11,7 @@ "timeout": 0 }, "dependencies": { - "@codewars/lambda-calculus": "^1.0.0-rc.3" + "@codewars/lambda-calculus": "^1.0.0-rc.4" }, "devDependencies": { "@codewars/mocha-reporter": "^1.0.0", diff --git a/workspace/solution.lc b/workspace/solution.lc index fe748cf..96d26da 100644 --- a/workspace/solution.lc +++ b/workspace/solution.lc @@ -2,7 +2,6 @@ true = \ a b . a false = \ a b . b -%invalid = \a b . b zero = false succ = \ n f x . f (n f x) diff --git a/workspace/test.js b/workspace/test.js index 79db78d..e112641 100644 --- a/workspace/test.js +++ b/workspace/test.js @@ -1,21 +1,15 @@ -import { assert, config as chaiConfig } from "chai"; -chaiConfig.truncateThreshold = 0; +import { assert, LC, getSolution } from "./lc-test.js"; -import * as LC from "@codewars/lambda-calculus"; -import { solution } from "./files.js"; // /workspace/files.js - -LC.config.purity = "Let"; -LC.config.numEncoding = "Church"; -const toInt = LC.toIntWith(LC.config); -const { counter } = LC.compile(solution()); +LC.configure({purity: "Let", numEncoding: "Church"}); +const { counter } = LC.compile(getSolution()); const T = t => _ => t; const F = _ => f => f; describe("counter", () => { it("fixed tests", () => { - assert.strictEqual(toInt(counter(T)(T)(T)(F)), 3); - assert.strictEqual(toInt(counter(T)(F)), 1); - assert.strictEqual(toInt(counter(T)(T)(T)(T)(T)(T)(T)(F)), 7); + assert.equal(counter(T)(T)(T)(F), 3); + assert.equal(counter(T)(F), 1); + assert.equal(counter(T)(T)(T)(T)(T)(T)(T)(F), 7); }); });