diff --git a/src/lambda-calculus.js b/src/lambda-calculus.js index bc6976a..08e2203 100644 --- a/src/lambda-calculus.js +++ b/src/lambda-calculus.js @@ -147,7 +147,7 @@ export function toInt(term) { } else if ( config.numEncoding === "None" ) return term; else - return numEncoding.toInt(term); // Custom encoding + return config.numEncoding.toInt(term); // Custom encoding } catch (e) { if ( config.verbosity >= "Concise" ) console.error(`toInt: ${ term } is not a number in numEncoding ${ numEncoding }`); throw e; diff --git a/workspace/lc-test.js b/workspace/lc-test.js index da921d9..89dcdbe 100644 --- a/workspace/lc-test.js +++ b/workspace/lc-test.js @@ -1,7 +1,9 @@ import { readFileSync } from "fs"; -export { assert, config } from "chai"; -export * as LC from "@codewars/lambda-calculus"; +import { assert, config } from "chai"; +import * as LC from "../src/lambda-calculus.js"; + +export { assert, config, LC }; const read = (path) => readFileSync(new URL(path, import.meta.url), {encoding: "utf8"}); @@ -13,3 +15,16 @@ export const getPreloaded = () => read("./preloaded.lc"); /** Return the contents of the preloaded file and the solution file combined */ export const getSolutionWithPreloaded = () => getPreloaded() + "\n_ = ()\n" + getSolution(); + + +/** Custom assertions */ + +function numEql(got, exp, msg) { + if ( got?.term && got?.env ) got = LC.toInt(got); + if ( exp?.term && exp?.env ) exp = LC.toInt(exp); + return this.equal(got, exp, msg); +} + +Object.assign(assert, { + numEql +});