From aa3902885c683b6cbd132d598b2b616939909962 Mon Sep 17 00:00:00 2001 From: kazk Date: Wed, 16 Feb 2022 23:51:32 -0800 Subject: [PATCH 1/5] Add lc-test.js --- Dockerfile | 2 +- example/test.js | 6 +----- workspace/{files.js => lc-test.js} | 5 +++++ workspace/solution.lc | 1 - workspace/test.js | 16 +++++----------- 5 files changed, 12 insertions(+), 18 deletions(-) rename workspace/{files.js => lc-test.js} (68%) 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..9c56335 100644 --- a/example/test.js +++ b/example/test.js @@ -1,8 +1,4 @@ -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, solution } from "./lc-test.js"; LC.configure({ purity: "Let", numEncoding: "Church" }); const { counter } = LC.compile(solution()); diff --git a/workspace/files.js b/workspace/lc-test.js similarity index 68% rename from workspace/files.js rename to workspace/lc-test.js index 0a0353c..5734d7a 100644 --- a/workspace/files.js +++ b/workspace/lc-test.js @@ -1,5 +1,10 @@ import { readFileSync } from "fs"; +import { assert, config as chaiConfig } from "chai"; +chaiConfig.truncateThreshold = 0; +export { assert }; +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 */ 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..96ff694 100644 --- a/workspace/test.js +++ b/workspace/test.js @@ -1,12 +1,6 @@ -import { assert, config as chaiConfig } from "chai"; -chaiConfig.truncateThreshold = 0; +import { assert, LC, solution } 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); +LC.configure({purity: "Let", numEncoding: "Church"}); const { counter } = LC.compile(solution()); const T = t => _ => t; @@ -14,8 +8,8 @@ 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); }); }); From 42c4637fa8830b97f9667cdd4fc0c2fcb1c10f47 Mon Sep 17 00:00:00 2001 From: kazk Date: Thu, 17 Feb 2022 00:45:46 -0800 Subject: [PATCH 2/5] Rename to getSolution/getPreloaded --- example/test.js | 4 ++-- workspace/lc-test.js | 4 ++-- workspace/test.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/example/test.js b/example/test.js index 9c56335..cf32b90 100644 --- a/example/test.js +++ b/example/test.js @@ -1,7 +1,7 @@ -import { assert, LC, solution } from "./lc-test.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/lc-test.js b/workspace/lc-test.js index 5734d7a..396c1c8 100644 --- a/workspace/lc-test.js +++ b/workspace/lc-test.js @@ -8,7 +8,7 @@ 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 solution = () => read("./solution.lc"); +export const getSolution = () => read("./solution.lc"); /** Return the contents of the optional preloaded file */ -export const preloaded = () => read("./preloaded.lc"); +export const getPreloaded = () => read("./preloaded.lc"); diff --git a/workspace/test.js b/workspace/test.js index 96ff694..e112641 100644 --- a/workspace/test.js +++ b/workspace/test.js @@ -1,7 +1,7 @@ -import { assert, LC, solution } from "./lc-test.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; From 533e25c3dc3698ac242fec04bc280fdaf25e79f7 Mon Sep 17 00:00:00 2001 From: kazk Date: Thu, 17 Feb 2022 00:47:01 -0800 Subject: [PATCH 3/5] Add getSolutionWithPreloaded --- workspace/lc-test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/workspace/lc-test.js b/workspace/lc-test.js index 396c1c8..37fc475 100644 --- a/workspace/lc-test.js +++ b/workspace/lc-test.js @@ -12,3 +12,6 @@ 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(); From 0482c49e4280f6c698ec646261192ae4d035beb7 Mon Sep 17 00:00:00 2001 From: kazk Date: Thu, 17 Feb 2022 11:59:05 -0800 Subject: [PATCH 4/5] Update to v1.0.0-rc.4 --- workspace/package-lock.json | 14 +++++++------- workspace/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) 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", From 460110c9e120ce3a1690a90d0f6b2ffa1e365aff Mon Sep 17 00:00:00 2001 From: kazk Date: Thu, 17 Feb 2022 12:28:45 -0800 Subject: [PATCH 5/5] Export `chai.config` --- workspace/lc-test.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/workspace/lc-test.js b/workspace/lc-test.js index 37fc475..2aac362 100644 --- a/workspace/lc-test.js +++ b/workspace/lc-test.js @@ -1,8 +1,6 @@ import { readFileSync } from "fs"; -import { assert, config as chaiConfig } from "chai"; -chaiConfig.truncateThreshold = 0; -export { assert }; +export { assert, config } from "chai"; export * as LC from "@codewars/lambda-calculus"; const read = (path) => readFileSync(new URL(path, import.meta.url), {encoding: "utf8"});