How do I assert correct decimal value with a bit of tolerance?
Lets say I want to assert this: 1 / 3
I don’t want to assert this with a long string like this: equal(1 / 3, 0.3333333333333333)
I would like to specify tolerance for it like this: equal(1 / 3, 0.33, 0.01) // As in… value can be from 0.32 to 0.34
Is this possible in q-unit? One possible solution to this would be if i multiplied the result by like 1000 and cut away all the decimal places… But i will be writing many such tests and would prefer to use any already implemented feature of q-unit is possible.
There is close-enough addon for qunit. It extends qunit with 2 assertion methods which do exactly what you need:
https://github.com/jquery/qunit/tree/master/addons/close-enough