Initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/** The smallest test harness that gives a useful failure message. */
|
||||
|
||||
let failures = 0;
|
||||
let checks = 0;
|
||||
|
||||
export function ok(cond, msg) {
|
||||
checks++;
|
||||
if (!cond) {
|
||||
failures++;
|
||||
console.error(' FAIL ' + msg);
|
||||
}
|
||||
}
|
||||
|
||||
export function near(actual, expected, tol, msg) {
|
||||
ok(Math.abs(actual - expected) <= tol, `${msg} (got ${actual}, want ${expected} ±${tol})`);
|
||||
}
|
||||
|
||||
export function section(name) {
|
||||
console.log('· ' + name);
|
||||
}
|
||||
|
||||
export function done(name) {
|
||||
if (failures) {
|
||||
console.error(`\n${name}: ${failures} of ${checks} checks failed`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`${name}: ${checks} checks passed`);
|
||||
}
|
||||
Reference in New Issue
Block a user