feat: math.ts 单测

This commit is contained in:
allenve 2023-07-07 14:13:37 +08:00
parent 035f6ceeee
commit f97e1800d5

View File

@ -0,0 +1,15 @@
import {safeAdd, safeSub} from '../../src/utils/math';
test(`math safeAdd:test`, () => {
expect(safeAdd(0.1, 0.2)).toEqual(0.3);
expect(safeAdd(0.111, 0.455)).toEqual(0.566);
expect(safeAdd(NaN, 1)).toEqual(NaN);
expect(safeAdd(NaN, NaN)).toEqual(NaN);
});
test(`math safeSub:test`, () => {
expect(safeSub(0.8, 0.1)).toEqual(0.7);
expect(safeSub(0.1, 0.111111)).toEqual(-0.011111);
expect(safeAdd(NaN, 1)).toEqual(NaN);
expect(safeAdd(NaN, NaN)).toEqual(NaN);
});