![](/img/trans.png)
[英]How do I unit test and check the contents of a vector object of a custom struct using google mock?
[英]How do I check the contents in a vector using google-test?
std::vector<uint8_t> vector1(10);
std::vector<uint8_t> vector2(10);
std::fill(vector1.begin(), vector1.end(), 2);
std::fill(vector2.begin(), vector2.end(), 2);
EXPECT_EQ(vector1, vector2);
上面的 EXPECT_EQ() 是否檢查 vector1 和 vector2 中的內容是否相等? 如果不是,我如何使用 googletest EXPECT_* 函數檢查 vector1 和 vector2 中的內容是否相等?
googletest 的文檔解釋了如何測試 C 字符串和 c++ 字符串對象的內容,但沒有解釋如何檢查 c++ 向量的內容。
EXPECT_EQ
使用operator ==
比較對象,operator ==
用於std::vector
(引用自 cppreference):
檢查
lhs
和rhs
的內容是否相等,即它們具有相同數量的元素,並且lhs
每個元素與rhs
中相同位置的元素比較相等。
所以答案是肯定的,它將比較向量的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.