lib.js (1254B)
1 import { run } from "../../index.js"; 2 import { blue, bold, green, red } from "../../cli/colors.js"; 3 const testRun = async (x) => { 4 const outputR = await run(x, { 5 environment: { sampleCount: 100, xyPointLength: 100 }, 6 }); 7 if (outputR.ok) { 8 return outputR.value.result; 9 } 10 else { 11 throw Error("Expected squiggle expression to evaluate but got error: " + 12 outputR.value.toString()); 13 } 14 }; 15 export function test(name, fn) { 16 console.log(bold(name)); 17 fn(); 18 } 19 export async function expectEqual(expression1, expression2) { 20 const result1 = await testRun(expression1); 21 const result2 = await testRun(expression2); 22 if (result1.tag === "Number" && result2.tag === "Number") { 23 const logloss = Math.log(Math.abs(result1.value - result2.value)); 24 const isBadLogless = logloss > 1; 25 console.log(blue(`${expression1} = ${expression2}`)); 26 console.log(`${result1.value} = ${result2.value}`); 27 console.log(`logloss = ${isBadLogless ? red(logloss.toFixed(2)) : green(logloss.toFixed(2))}`); 28 console.log(); 29 } 30 else { 31 throw Error(`Expected both to be number, but got ${result1.tag} and ${result2.tag}`); 32 } 33 } 34 //# sourceMappingURL=lib.js.map