I have a function that returns a tuple that, among others, contains a float value. Usually I use assertAlmostEquals
to compare those, but this does not work with tuples. Also, the tuple contains other data-types as well. Currently I am asserting every element of the tuple individually, but that gets too much for a list of such tuples. Is there any good way to write assertions for such cases?
Consider this function:
def f(a):
return [(1.0/x, x * 2) for x in a]
我现在要作一个考验:
def testF(self):
self.assertEqual(f(range(1,3)), [(1.0, 2), (0.5, 4)])
否则将失败,因为<代码>1.0/2<>>>/代码>并非确切的<代码>0.5/code>。 任何人能否以可读的方式提出这种说法?
<<>Edit>/strong>: 实际1.0/2>
确切为0.5
,但你有我的意思。