-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd_multimap.cpp
More file actions
124 lines (100 loc) · 3.69 KB
/
Copy pathstd_multimap.cpp
File metadata and controls
124 lines (100 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "common.hpp"
template <class IArchive, class OArchive>
void test_multimap() {
std::random_device rd;
std::mt19937 gen(rd());
for (int ii = 0; ii < 100; ++ii) {
std::multimap<std::string, int> o_podmultimap;
for (int j = 0; j < 100; ++j) {
auto key = random_value<std::string>(gen);
o_podmultimap.insert({key, random_value<int>(gen)});
o_podmultimap.insert({key, random_value<int>(gen)});
}
std::multimap<uint8_t, StructInternalSerialize> o_isermultimap;
for (int j = 0; j < 100; ++j) {
auto key = random_value<uint8_t>(gen);
o_isermultimap.insert({key, {random_value<int>(gen), random_value<int>(gen)}});
o_isermultimap.insert({key, {random_value<int>(gen), random_value<int>(gen)}});
}
std::multimap<int16_t, StructInternalSplit> o_isplmultimap;
for (int j = 0; j < 100; ++j) {
auto key = random_value<int16_t>(gen);
o_isplmultimap.insert({key, {random_value<int>(gen), random_value<int>(gen)}});
o_isplmultimap.insert({key, {random_value<int>(gen), random_value<int>(gen)}});
}
std::multimap<uint32_t, StructExternalSerialize> o_esermultimap;
for (int j = 0; j < 100; ++j) {
auto key = random_value<uint32_t>(gen);
o_esermultimap.insert({key, {random_value<int>(gen), random_value<int>(gen)}});
o_esermultimap.insert({key, {random_value<int>(gen), random_value<int>(gen)}});
}
std::multimap<int8_t, StructExternalSplit> o_esplmultimap;
for (int j = 0; j < 100; ++j) {
auto key = random_value<int8_t>(gen);
o_esplmultimap.insert({key, {random_value<int>(gen), random_value<int>(gen)}});
o_esplmultimap.insert({key, {random_value<int>(gen), random_value<int>(gen)}});
}
std::ostringstream os; {
OArchive oar(os);
oar(o_podmultimap);
oar(o_isermultimap);
oar(o_isplmultimap);
oar(o_esermultimap);
oar(o_esplmultimap);
}
std::multimap<std::string, int> i_podmultimap;
std::multimap<uint8_t, StructInternalSerialize> i_isermultimap;
std::multimap<int16_t, StructInternalSplit> i_isplmultimap;
std::multimap<uint32_t, StructExternalSerialize> i_esermultimap;
std::multimap<int8_t, StructExternalSplit> i_esplmultimap;
std::istringstream is(os.str()); {
IArchive iar(is);
iar(i_podmultimap);
iar(i_isermultimap);
iar(i_isplmultimap);
iar(i_esermultimap);
iar(i_esplmultimap);
}
#define MULTIMAP_CHECK(InMap, OutMap) \
for( auto & pair : OutMap ) \
{ \
auto const count = InMap.count( pair.first ); \
CHECK_EQ( count, OutMap.count( pair.first ) ); \
auto find = InMap.find( pair.first ); \
bool found = false; \
for( size_t i = 0; i < count; ++i, ++find ) \
found |= find->second == pair.second; \
CHECK_UNARY( found ); \
}
MULTIMAP_CHECK(i_podmultimap, o_podmultimap);
MULTIMAP_CHECK(i_isermultimap, o_isermultimap);
MULTIMAP_CHECK(i_isplmultimap, o_isplmultimap);
MULTIMAP_CHECK(i_esermultimap, o_esermultimap);
MULTIMAP_CHECK(i_esplmultimap, o_esplmultimap);
#undef MULTIMAP_CHECK
}
}
// -------------------------------------------------------------------------------------------------
template <class IArchive, class OArchive>
void test_multimap_preserve_order() {
std::random_device rd;
std::mt19937 gen(rd());
SaveLoadTester<IArchive, OArchive> test{};
std::multimap<int, int> map;
map.emplace(10, 1);
map.emplace(10, 2);
map.emplace(10, 3);
map.emplace(10, 4);
map.emplace(10, 5);
map.emplace(10, 6);
map.emplace(10, 7);
map.emplace(10, 8);
map.emplace(10, 9);
CHECK(test(map));
}
TEST_SUITE_BEGIN("multimap");
CREATE_TEST_CASES_FOR_ALL_ARCHIVE("multimap", test_multimap)
CREATE_TEST_CASES_FOR_ALL_ARCHIVE("multimap_preserve_order", test_multimap_preserve_order)
TEST_SUITE_END();