Skip to content

Commit b30b8b9

Browse files
authored
Merge pull request #70 from Kacarott/dev
Custom assertion
2 parents bd7288b + 964ffab commit b30b8b9

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/lambda-calculus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export function toInt(term) {
147147
} else if ( config.numEncoding === "None" )
148148
return term;
149149
else
150-
return numEncoding.toInt(term); // Custom encoding
150+
return config.numEncoding.toInt(term); // Custom encoding
151151
} catch (e) {
152152
if ( config.verbosity >= "Concise" ) console.error(`toInt: ${ term } is not a number in numEncoding ${ numEncoding }`);
153153
throw e;

workspace/lc-test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { readFileSync } from "fs";
22

3-
export { assert, config } from "chai";
4-
export * as LC from "@codewars/lambda-calculus";
3+
import { assert, config } from "chai";
4+
import * as LC from "../src/lambda-calculus.js";
5+
6+
export { assert, config, LC };
57

68
const read = (path) => readFileSync(new URL(path, import.meta.url), {encoding: "utf8"});
79

@@ -13,3 +15,16 @@ export const getPreloaded = () => read("./preloaded.lc");
1315

1416
/** Return the contents of the preloaded file and the solution file combined */
1517
export const getSolutionWithPreloaded = () => getPreloaded() + "\n_ = ()\n" + getSolution();
18+
19+
20+
/** Custom assertions */
21+
22+
function numEql(got, exp, msg) {
23+
if ( got?.term && got?.env ) got = LC.toInt(got);
24+
if ( exp?.term && exp?.env ) exp = LC.toInt(exp);
25+
return this.equal(got, exp, msg);
26+
}
27+
28+
Object.assign(assert, {
29+
numEql
30+
});

0 commit comments

Comments
 (0)