Python 3.x Python 3-断言一个布尔值。
我已经重写了我当前正在进行doctesting的类中的Python 3.x Python 3-断言一个布尔值。,python-3.x,unit-testing,Python 3.x,Unit Testing,我已经重写了我当前正在进行doctesting的类中的\uuuuuuuuuuueq\uuuuuuuuu。所有的方法(未显示)都可以正常工作,但是当我添加\uuuueq\uuuuu时,我收到一条错误消息 我的方法: def __eq__(self, other): """ Tests if two dual objects are equal or not. Returns ------- True or false, depending on the com
\uuuuuuuuuuueq\uuuuuuuuu
。所有的方法(未显示)都可以正常工作,但是当我添加\uuuueq\uuuuu
时,我收到一条错误消息
我的方法:
def __eq__(self, other):
""" Tests if two dual objects are equal or not.
Returns
-------
True or false, depending on the comparison
Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False
在我的doctesting文件中,以下方法用于测试此方法是否有效:
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y
我得到的错误消息如下:
=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence \p
"""
有什么事情我做得非常错误或忽略了吗?错误清楚地表明,z和y的值是“1.00+eps 1.00”形式,您无法直接比较。 您可以执行以下操作:
assert z.r == y.r
assert z.d == z.d
错误清楚地表明z和y的值是“1.00+eps 1.00”形式,您无法直接比较。