How to perform unittest for floating point outputs? - python
问题 Let's say I am writing a unit test for a function that returns a floating point number, I can do it as such in full precision as per my machine: >>> import unittest >>> def div(x,y): return x/float(y) ... >>> >>> class Testdiv(unittest.TestCase): ... def testdiv(self): ... assert div(1,9) == 0.1111111111111111 ... >>> unittest.main() . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK Will the same full floating point precision be the same across