2013-03-16 5 views
0

나는 에있는 어설 션을 찾으려고 노력했습니다. 이는 Boost Test Library에있는 BOOST_CHECK_EQUAL_COLLECTIONS 어설 션과 동일합니다.Google 테스트의 BOOST_CHECK_EQUAL_COLLECTIONS

그러나; 성공없이. 그래서 내 질문은 두 가지입니다 :

  1. gtest에 해당하는 주장이 있습니까?
  2. 그렇지 않은 경우 : gtest에 컨테이너 내용을 주장하는 방법은 무엇입니까?

EDIT (약간 수정 답) :

#include <iostream> 

template<typename LeftIter, typename RightIter> 
::testing::AssertionResult CheckEqualCollections(LeftIter left_begin, 
               LeftIter left_end, 
               RightIter right_begin) 
{ 
    std::stringstream message; 
    std::size_t index(0); 
    bool equal(true); 

    for(;left_begin != left_end; left_begin++, right_begin++) { 
     if (*left_begin != *right_begin) { 
      equal = false; 
      message << "\n Mismatch in position " << index << ": " << *left_begin << " != " << *right_begin; 
     } 
     ++index; 
    } 
    if (message.str().size()) { 
     message << "\n"; 
    } 
    return equal ? ::testing::AssertionSuccess() : 
        ::testing::AssertionFailure() << message.str(); 
} 
+0

자매 프로젝트 인 Google Mock을 살펴볼 필요가 있다고 생각합니다. –

답변

0

가 나는 정확히 동등한 gtest 주장 모르겠어요.

같은 것을 using a function that returns an AssertionResult에 관한 부분은이를 사용하는 방법에 대한 자세한 내용을 제공하지만 것

template<typename LeftIter, typename RightIter> 
::testing::AssertionResult CheckEqualCollections(LeftIter left_begin, 
               LeftIter left_end, 
               RightIter right_begin) { 
    bool equal(true); 
    std::string message; 
    std::size_t index(0); 
    while (left_begin != left_end) { 
    if (*left_begin++ != *right_begin++) { 
     equal = false; 
     message += "\n\tMismatch at index " + std::to_string(index); 
    } 
    ++index; 
    } 
    if (message.size()) 
    message += "\n\t"; 
    return equal ? ::testing::AssertionSuccess() : 
       ::testing::AssertionFailure() << message; 
} 
:

알렉스으로
EXPECT_TRUE(CheckEqualCollections(collection1.begin(), 
            collection1.end(), 
            collection2.begin())); 
2

는 지적했다 gtest 그러나, 다음 함수는 비슷한 기능을 제공해야한다 당신은에서 더 많은 정보를 찾을 수 있습니다

EXPECT_THAT(actual, ContainerEq(expected)); 
// ElementsAre accepts up to ten parameters. 
EXPECT_THAT(actual, ElementsAre(a, b, c)); 
EXPECT_THAT(actual, ElementsAreArray(array)); 

: 두 개의 컨테이너를 비교하기위한 훌륭한 시설을 갖추고 구글 모의라는 자매 프로젝트를 가지고 210.