Skip to content

Add lc-test.js #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions example/test.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 0 additions & 9 deletions workspace/files.js

This file was deleted.

15 changes: 15 additions & 0 deletions workspace/lc-test.js
Original file line number Diff line number Diff line change
@@ -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();
14 changes: 7 additions & 7 deletions workspace/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion workspace/solution.lc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 6 additions & 12 deletions workspace/test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});