MCPcopy Create free account
hub / github.com/comaps/comaps / TestSortUnique

Function TestSortUnique

libs/base/base_tests/stl_helpers_tests.cpp:26–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25template <template <typename...> class Cont>
26void TestSortUnique()
27{
28 {
29 Cont<int> actual = {1, 2, 1, 4, 3, 5, 2, 7, 1};
30 SortUnique(actual);
31 Cont<int> const expected = {1, 2, 3, 4, 5, 7};
32 TEST_EQUAL(actual, expected, ());
33 }
34 {
35 using Value = int;
36 using Pair = std::pair<Value, int>;
37 Cont<Pair> d = {{1, 22}, {2, 33}, {1, 23}, {4, 54}, {3, 34}, {5, 23}, {2, 23}, {7, 32}, {1, 12}};
38
39 SortUnique(d, LessBy(&Pair::first), EqualsBy(&Pair::first));
40
41 Cont<Value> const expected = {1, 2, 3, 4, 5, 7};
42 TEST_EQUAL(d.size(), expected.size(), ());
43 for (size_t i = 0; i < d.size(); ++i)
44 TEST_EQUAL(d[i].first, expected[i], (i));
45 }
46 {
47 using Value = double;
48 using Pair = std::pair<Value, int>;
49 Cont<Pair> d = {{0.5, 11}, {1000.99, 234}, {0.5, 23}, {1234.56789, 54}, {1000.99, 34}};
50
51 SortUnique(d, LessBy(&Pair::first), EqualsBy(&Pair::first));
52
53 Cont<Value> const expected = {0.5, 1000.99, 1234.56789};
54 TEST_EQUAL(d.size(), expected.size(), ());
55 for (size_t i = 0; i < d.size(); ++i)
56 TEST_EQUAL(d[i].first, expected[i], (i));
57 }
58}
59
60template <template <typename...> class Cont>
61void TestEqualsBy()

Callers

nothing calls this directly

Calls 4

SortUniqueFunction · 0.85
LessByFunction · 0.85
EqualsByFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected