I have a function that returns a tuple that, among other things, contains a float value. I usually use assertAlmostEquals for comparison, but this does not work with tuples. In addition, the tuple contains other data types. Currently, I approve each element of a tuple individually, but this is too much for a list of such tuples. Is there a good way to write statements for such cases? Consider this function:
def f(a): return [(1.0/x, x * 2) for x in a]
Now I want to write a test for it:
def testF(self): self.assertEqual(f(range(1,3)), [(1.0, 2), (0.5, 4)])
This will not succeed, because the result of 1.0/2 does not correspond to 0.5 . Can anyone recommend a good way to write such a statement in a readable way?
Edit : Actually 1.0/2 exactly 0.5 , but you will get my value.
python floating-point assert unit-testing tuples
Björn pollex
source share