UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

22 lines 911 B
/** * Expects that testValue is equal to expectedValue or optionally within percentage (defaults to .01 or 1%) */ export const testWithinPerc = (testValue, expectedValue, options) => { const { withinPerc, debug } = { withinPerc: 0.01, debug: false, ...options }; if (expectedValue === 0) { if (testValue === 0) { if (debug) console.log(`test: ${testValue}, expected: ${expectedValue}, skipped`); return; } else { // Zero edge case still worth testing, get it just up off of 0 expectedValue = testValue * 0.000_000_000_01; } } const percDiff = Math.abs(testValue - expectedValue) / expectedValue; if (debug) console.log(`test: ${testValue}, expected: ${expectedValue}, percDiff: ${percDiff}`); expect(percDiff).toBeLessThan(withinPerc); }; //# sourceMappingURL=testWithinPerc.js.map