Skip to content

Commit 2fb9e21

Browse files
author
thk123
committed
Add utility for checking two vectors are equal without caring about order
1 parent 6f98511 commit 2fb9e21

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************\
2+
3+
Module: Unit test utilities
4+
5+
Author: Diffblue Limited.
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_TESTING_UTILS_REQUIRE_VECTORS_EQUAL_UNORDERED_H
10+
#define CPROVER_TESTING_UTILS_REQUIRE_VECTORS_EQUAL_UNORDERED_H
11+
12+
#include <testing-utils/catch.hpp>
13+
#include <vector>
14+
15+
/// Checks whether two vectors are equal, ignoring ordering
16+
/// \tparam T: The type of the vector contents
17+
/// \param actual: The vector to check
18+
/// \param expected: The vector to check against
19+
template <class T>
20+
void require_vectors_equal_unordered(
21+
const std::vector<T> &actual,
22+
const std::vector<T> &expected)
23+
{
24+
REQUIRE(actual.size() == expected.size());
25+
REQUIRE_THAT(actual, Catch::Matchers::Vector::ContainsMatcher<T>{expected});
26+
}
27+
28+
#endif // CPROVER_TESTING_UTILS_REQUIRE_VECTORS_EQUAL_UNORDERED_H

0 commit comments

Comments
 (0)