Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 检查包含序列的两个对象是否相等_Python_Unit Testing - Fatal编程技术网

Python 检查包含序列的两个对象是否相等

Python 检查包含序列的两个对象是否相等,python,unit-testing,Python,Unit Testing,作为单元测试的一部分,我试图比较两个仅包含一个系列的现金流对象 在单元测试中,我有以下内容,其中cashflowobj_1和cashflowobj_2是包含系列的Cashflow对象: self.assert_(cashflowobj_1==cashflowobj_2) 这两个系列看起来与下面看到的完全相同,但是测试返回的系列不相等,因此我想知道我用来检查它们相等性的函数中是否存在问题现金流对象1.金额和现金流对象2.金额是各自的系列: self.assert_(cashflowobj_1==

作为单元测试的一部分,我试图比较两个仅包含一个系列的
现金流
对象

在单元测试中,我有以下内容,其中
cashflowobj_1
cashflowobj_2
是包含
系列的
Cashflow
对象:

self.assert_(cashflowobj_1==cashflowobj_2)
这两个系列看起来与下面看到的完全相同,但是测试返回的
系列不相等
,因此我想知道我用来检查它们相等性的函数中是否存在问题<代码>现金流对象1.金额
现金流对象2.金额
是各自的
系列

self.assert_(cashflowobj_1==cashflowobj_2)
cashflowobj\u 1.金额

     1983-05-15      1
     1983-11-15      1
     1984-05-15      1
     1984-11-15     101
     1983-05-15      1
     1983-11-15      1
     1984-05-15      1
     1984-11-15     101
现金流对象2.金额:

     1983-05-15      1
     1983-11-15      1
     1984-05-15      1
     1984-11-15     101
     1983-05-15      1
     1983-11-15      1
     1984-05-15      1
     1984-11-15     101
用于检查
现金流
类中的
现金流
对象是否相等的函数:

def __eq__(self, other):
    '''
    Series being equal
    '''
    if ((len(self.amounts) == len(other.amounts))) and ((all(i in self.amounts for i in other.amounts))):
        print('Series are equal')
        return(1)
    else:
        print('Series are not equal')
        return(0)

编辑:解决@matt的问题:索引都是
datetime.date()
对象。值是
float64

难道你不想检查序列是否相等吗?假设你说的是熊猫系列

使用函数

def __eq__(self, other):
    '''
    Series being equal
    '''
    if self.amounts.equals(other.amounts)
        print('Series are equal')
        return(1)
    else:
        print('Series are not equal')
        return(0)

amounts
属性中的对象类型是什么?如果它们是常规列表或元组,self.amounts部分中的
i将使用常规等式进行检查,因此如果这些对象没有正确实现
\uuuuuuueq\uuuuuu
,它们将不匹配。@matts谢谢。索引都是
datetime.date()
对象。值为
float64