Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python 3-断言一个布尔值。_Python 3.x_Unit Testing - Fatal编程技术网

Python 3.x Python 3-断言一个布尔值。

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

我已经重写了我当前正在进行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 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”形式,您无法直接比较。