Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.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
C++ 在CPPFUnit中断言迭代器相等_C++_Cppunit - Fatal编程技术网

C++ 在CPPFUnit中断言迭代器相等

C++ 在CPPFUnit中断言迭代器相等,c++,cppunit,C++,Cppunit,我已经开始使用CPPU单元库。一切都很好,但现在,我不得不使用CPPUNIT\u ASSERT\u EQUAL断言迭代器。这就是我的代码: void TestingClass::test_adjacent_find() { // Set up int a [5] = {1,2,3,3,5}; int b [5] = {1,2,3,4,5}; int c [1] = {1}; std::list<int> lst; lst.push_b

我已经开始使用CPPU单元库。一切都很好,但现在,我不得不使用
CPPUNIT\u ASSERT\u EQUAL
断言迭代器。这就是我的代码:

void TestingClass::test_adjacent_find()
{
    // Set up
    int a [5] = {1,2,3,3,5};
    int b [5] = {1,2,3,4,5};
    int c [1] = {1};

    std::list<int> lst;
    lst.push_back(1);
    lst.push_back(1);
    lst.push_back(5);

    // Check
    CPPUNIT_ASSERT_EQUAL(a+2, my_adjacent_find(a , a+5, pred_eq<int>));
    CPPUNIT_ASSERT_EQUAL(b+5, my_adjacent_find(b, b+5, pred_eq<int>));
    CPPUNIT_ASSERT_EQUAL(c+1, my_adjacent_find(c, c+1, pred_eq<int>));
    CPPUNIT_ASSERT_EQUAL(lst.begin(), lst.end()); // problem is here
}
void TestingClass::test\u nexting\u find()
{
//设立
int a[5]={1,2,3,3,5};
int b[5]={1,2,3,4,5};
int c[1]={1};
std::列表lst;
一、推回(1);
一、推回(1);
一、推回(5);
//检查
CPPUNIT_ASSERT_EQUAL(a+2,my_nexting_find(a,a+5,pred_eq));
CPPUNIT_ASSERT_EQUAL(b+5,my_nexting_find(b,b+5,pred_eq));
CPPUNIT_ASSERT_EQUAL(c+1,my_nexting_find(c,c+1,pred_eq));
CPPUNIT_ASSERT_EQUAL(lst.begin(),lst.end());//问题就在这里
}
当我运行这个测试时,我得到下面的错误

/opt/local/include/cppunit/TestAssert.h:49:13: 
Invalid operands to binary expression 
('OStringStream' (aka 'basic_ostringstream<char>') 
and 'const std::_List_iterator<int>')
/opt/local/include/cppunit/TestAssert.h:49:13:
二进制表达式的操作数无效
(“OStringStream”(又名“basic_OStringStream”)
和'const std::_List_iterator')

如果我用迭代器注释该行,那么它编译时不会出现任何问题。那么我做错了什么?我应该如何断言两个迭代器相等?顺便说一下,我使用的是xcode 4.4。

请参见
TestAssert.h
中的
CPPUNIT\u ASSERT\u EQUAL
宏文档:

#定义CPPUNIT_断言_等于(预期、实际)

预期
实际
参数要求:

  • 它们是完全相同的类型

  • 可使用运算符将它们序列化为std::STRSTRESEAM请参见
    TestAssert.h
    中的
    CPPUNIT\u ASSERT\u EQUAL
    宏文档:

    #定义CPPUNIT_断言_等于(预期、实际)

    预期
    实际
    参数要求:

    • 它们是完全相同的类型
    • 它们可以使用运算符序列化为std::stream
      CPPUNIT_ASSERT(lst.begin() == lst.end());