When we considered the roundFix special function, which required using state to accumulate the differences due to rounding, we produced a new version by providing the current state as an added parameter, and by having the function return two values: the rounded one, and the updated state:
const roundFix2 = (a, n) => { let r = a > 0 ? Math.ceil(n) : Math.floor(n); a += n - r; return {a, r};};
This function is now pure, but testing it requires validating not only the returned values but also the updated states. We can base our tests on the experiments we did previously. Once again, we have to use toBeCloseTo() for dealing with floating point numbers but we can use toBe() with integers, which produce no rounding errors: ...