Improve some unrelated tests while we're here.

This commit is contained in:
zkldi
2022-01-19 16:22:28 +00:00
parent 003c41b870
commit d5f03b0d60
5 changed files with 247 additions and 42 deletions
+14 -6
View File
@@ -1,18 +1,26 @@
import { rootLogger } from "lib/logger/logger";
import Prudence, { PrudenceSchema } from "prudence";
import t from "tap";
export function isApproximately(number: number, target: number, message?: string, lenience = 0.01) {
const result = t.ok(Math.abs(number - target) < lenience, message);
export function isApproximately(
t: Tap.Test,
number: number,
target: number,
message?: string,
lenience = 0.01
) {
const result = Math.abs(number - target) < lenience;
if (!result) {
rootLogger.error(`${number} was not close enough to ${target}`);
return t.fail(`${number} was not close enough to ${target}`, {
errmsg: `${number} was not close enough to ${target}`,
});
}
t.pass(message);
// return true;
}
export function prAssert(
t: Tap.Test,
obj: Record<string, unknown> | unknown,
schema: PrudenceSchema,
message = "Unnamed Prudence Assertion"