Skip to content
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
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
15 changes: 9 additions & 6 deletions workspace/lc-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// lc-test.js
import { readFileSync } from "fs";

export { assert, config } from "chai";
export * as LC from "@codewars/lambda-calculus";

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 getSolution = () => read("./solution.lc");
export const getPreloaded = () => read("./preloaded.lc");
export const getPreloadedAndSolution = () => getPreloaded() + '\n' + getSolution() ; // this might as well check solution doesn't start with a continued line

export {assert,config} from "chai";
/** Return the contents of the optional preloaded file */
export const getPreloaded = () => read("./preloaded.lc");

export * as LC from "@codewars/lambda-calculus";
/** 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
16 changes: 6 additions & 10 deletions workspace/test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// test.js
import { assert, LC, getSolution } from "./lc-test.js";

import * as LC from "./lc-test.js";
LC.config.truncateThreshold = 0;
LC.configure({ purity: "Let", numEncoding: "Church" });

const {counter} = LC.compile(getSolution());
const {toInt} = LC;
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);
});
});