6 #include <unordered_set> 7 #include <unordered_map> 9 #define TIMPI_UNIT_ASSERT(expr) \ 13 using namespace TIMPI;
35 { s.insert(std::vector<int>(i,i)); }
41 { m.insert(std::make_pair(i,2*i+3)); }
45 m.insert(std::make_pair(-1,-1));
46 m.insert(std::make_pair(i,3*i+1));
47 m.insert(std::make_pair(i,3*i+2));
50 void my_inserter(std::unordered_multimap<int, int> & m,
int i)
52 m.insert(std::make_pair(-1,-1));
53 m.insert(std::make_pair(i,3*i+1));
54 m.insert(std::make_pair(i,3*i+2));
58 { m.insert(std::make_pair(i,std::vector<int>(i,2*i+3))); }
61 { m.insert(std::make_pair(i,2*i+3)); }
63 void my_inserter(std::unordered_map<
int, std::vector<int>> & m,
int i)
64 { m.insert(std::make_pair(i,std::vector<int>(i,2*i+3))); }
67 void tester(
const std::set<int> & s,
int i)
68 { TIMPI_UNIT_ASSERT( s.count(i) == std::size_t(1) ); }
70 void tester(
const std::multiset<int> & s,
int i)
72 TIMPI_UNIT_ASSERT( s.count(-1) * 3 == s.size() );
73 TIMPI_UNIT_ASSERT( s.count(3*i+1) == std::size_t(1) );
74 TIMPI_UNIT_ASSERT( s.count(3*i+2) == std::size_t(1) );
77 void tester(
const std::unordered_multiset<int> & s,
int i)
79 TIMPI_UNIT_ASSERT( s.count(-1) * 3 == s.size() );
80 TIMPI_UNIT_ASSERT( s.count(3*i+1) == std::size_t(1) );
81 TIMPI_UNIT_ASSERT( s.count(3*i+2) == std::size_t(1) );
84 void tester(
const std::set<std::vector<int>> & s,
int i)
85 { TIMPI_UNIT_ASSERT( s.count(std::vector<int>(i,i)) == std::size_t(1) ); }
87 void tester(
const std::unordered_set<int> & s,
int i)
88 { TIMPI_UNIT_ASSERT( s.count(i) == std::size_t(1) ); }
90 void tester(
const std::map<int, int> & m,
int i)
92 TIMPI_UNIT_ASSERT( m.count(i) == std::size_t(1) );
93 TIMPI_UNIT_ASSERT( m.at(i) == 2*i+3 );
96 void tester(
const std::multimap<int, int> & m,
int i)
98 TIMPI_UNIT_ASSERT( m.count(-1) * 3 == m.size() );
100 std::bitset<2> found;
101 auto pr = m.equal_range(i);
102 for (
auto it = pr.first; it != pr.second; ++it)
104 auto val = it->second;
105 TIMPI_UNIT_ASSERT( val > 3*i && val < 3*i+3 );
106 TIMPI_UNIT_ASSERT( !found[val-3*i-1] );
107 found[val-3*i-1] =
true;
109 TIMPI_UNIT_ASSERT( found.count() == 2 );
112 void tester(
const std::unordered_multimap<int, int> & m,
int i)
114 TIMPI_UNIT_ASSERT( m.count(-1) * 3 == m.size() );
116 std::bitset<2> found;
117 const auto pr = m.equal_range(i);
118 for (
auto it = pr.first; it != pr.second; ++it)
120 auto val = it->second;
121 TIMPI_UNIT_ASSERT( val > 3*i && val < 3*i+3 );
122 TIMPI_UNIT_ASSERT( !found[val-3*i-1] );
123 found[val-3*i-1] =
true;
125 TIMPI_UNIT_ASSERT( found.count() == 2 );
128 void tester(
const std::map<
int, std::vector<int>> & m,
int i)
130 TIMPI_UNIT_ASSERT( m.count(i) == std::size_t(1) );
131 TIMPI_UNIT_ASSERT( m.at(i).size() == std::size_t(i) );
132 for (
auto val : m.at(i))
133 TIMPI_UNIT_ASSERT( val == 2*i+3 );
136 void tester(
const std::unordered_map<int, int> & m,
int i)
138 TIMPI_UNIT_ASSERT( m.count(i) == std::size_t(1) );
139 TIMPI_UNIT_ASSERT( m.at(i) == 2*i+3 );
142 void tester(
const std::unordered_map<
int, std::vector<int>> & m,
int i)
144 TIMPI_UNIT_ASSERT( m.count(i) == std::size_t(1) );
145 TIMPI_UNIT_ASSERT( m.at(i).size() == std::size_t(i) );
146 for (
auto val : m.at(i))
147 TIMPI_UNIT_ASSERT( val == 2*i+3 );
164 TIMPI_UNIT_ASSERT( data.size() == n_multi * std::size_t(N) );
165 for (
int p=0; p<N; ++p)
186 TIMPI_UNIT_ASSERT( data.size() == std::size_t(2*N+1) );
188 for (
int p=0; p<N; ++p)
198 std::map<unsigned int, std::set<unsigned short>> mapset;
201 mapset[0].insert(20201);
208 mapset[0].insert(60201);
224 TIMPI_UNIT_ASSERT( mapset.size() == 1 );
225 const std::set<unsigned short> goodset {20201, 60201};
226 for (
const auto & pr : mapset)
228 const auto & key = pr.first;
229 const auto & boundary_id_set = pr.second;
230 TIMPI_UNIT_ASSERT( key == 0 );
231 TIMPI_UNIT_ASSERT( boundary_id_set == goodset );
238 std::map<unsigned int, std::map<unsigned short, double>> mapmap;
241 mapmap[0].emplace(20201, 0.8);
248 mapmap[0].emplace(60201, 1.);
256 TIMPI_UNIT_ASSERT( mapmap.size() == 1 );
257 const std::map<unsigned short, double> goodmap {{20201, 0.8},
259 for (
const auto & pr : mapmap)
261 const auto & key = pr.first;
262 const auto & boundary_id_map = pr.second;
263 TIMPI_UNIT_ASSERT( key == 0 );
264 TIMPI_UNIT_ASSERT( boundary_id_map == goodmap );
269 int main(
int argc,
const char *
const * argv)
274 testBigUnion<std::set<int>>();
275 testBigUnion<std::multiset<int>>(3);
276 testBigUnion<std::unordered_multiset<int>>(3);
277 testBigUnion<std::unordered_set<int>>();
278 testBigUnion<std::map<int, int>>();
279 testBigUnion<std::multimap<int, int>>(3);
280 testBigUnion<std::unordered_multimap<int, int>>(3);
281 testBigUnion<std::unordered_map<int, int>>();
283 testUnion<std::set<int>>();
284 testUnion<std::unordered_set<int>>();
285 testUnion<std::map<int, int>>();
286 testUnion<std::unordered_map<int, int>>();
294 testUnion<std::map<int, std::vector<int>>>();
295 testUnion<std::unordered_map<int, std::vector<int>>>();
void testBigUnion(int n_multi=1)
The TIMPIInit class, when constructed, initializes any dependent libraries (e.g.
processor_id_type rank() const
Encapsulates the MPI_Comm object.
processor_id_type size() const
Communicator * TestCommWorld
void my_inserter(std::set< int > &s, int i)
int main(int argc, const char *const *argv)
void tester(const std::set< int > &s, int i)
const Communicator & comm() const
Returns the Communicator created by this object, which will be a compatibility shim if MPI is not ena...
void set_union(T &data, const unsigned int root_id) const
Take a container (set, map, unordered_set, multimap, etc) of local variables on each processor...