I am attempting to test scientific software written in TypeScript using Jest.
I want to test all my floating point results to 8 significant figures, but it seems the only test method available in ts-jest, "toBeCloseTo", works on matching figures after the decimal point in decimal notation.
https://jestjs.io/docs/en/expect#tobeclosetonumber-numdigits
The scientific and engineering community works to significant figures, rather than numbers after the decimal point. Have I overlooked some functionality. If not, is there a plan to add it?
In the meantime, I have a workaround which would only work for numbers where the significant figures after the decimal point in decimal notation are within the range of the significant figures required in scientific notation.
test("MyFunction", () =>{
let sigAfterDecimal = SIG_FIG - Math.floor((Math.log(ExpectedResult)/Math.log(10)));
expect(IF97_B23T(functionInput)).toBeCloseTo(SigAfterDecimal, thisTestAccuracy);
});
But this wouldn't work for checking eg. the Avogadro constant, 6.02214076×10^23 to 8 significant figures, as none of the relevant significant figures appear after the decimal point in decimal notation.