forked from FluorineDog/2017aut-quest2
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathset_test.cc
81 lines (71 loc) · 2.48 KB
/
set_test.cc
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
/**
* By recolic, Nov 10.
*/
#include <chrono>
#include <iostream>
#include <random>
#include <functional>
#include "test_utils.hpp"
using rlib::println;
std::default_random_engine rand_eng(810);
std::uniform_real_distribution<double> distribution(0, 100);
double m_rand() {return distribution(rand_eng);}
template <class operation_t, typename... args_t>
void timed_func(const std::string &info, std::function<operation_t> f, args_t... args)
{
println(info, "launched.");
auto begin = std::chrono::high_resolution_clock::now();
f(args ...);
auto end = std::chrono::high_resolution_clock::now();
println(info, "used", std::chrono::duration<double>(end - begin).count(), "s");
}
template <class operation_t, typename... args_t>
void repeat(size_t count, std::function<operation_t> f, args_t... args)
{
for(size_t cter = 0; cter < count; ++cter)
f(args ...);
}
int main()
{
using data_t = double;
Lab::set<data_t> seta;
std::set<data_t> setb;
using op_arg1_t = Lab::set<data_t> &;
using op_arg2_t = std::set<data_t> &;
#define op_args_t op_arg1_t, op_arg2_t
using operation_t = void(op_args_t);
auto co_insert = [](auto &bufa, auto &bufb){
data_t val = m_rand();
bufa.insert(val);
bufb.insert(val);
};
data_t current_value = 0;
auto co_particle_insert = [¤t_value](auto &bufa, auto &bufb){
current_value += 1;
bufa.insert(current_value);
bufb.insert(current_value);
};
auto co_erase = [](auto &bufa, auto &bufb){
bufa.erase(++bufa.begin());
bufb.erase(++bufb.begin());
};
auto co_clear = [](auto &bufa, auto &bufb){
bufa.clear();
bufb.clear();
};
using namespace std::placeholders;
#define TEST(count, operation, desc) SET_ASSERT_EQUIVALENCE(seta, setb, std::function<operation_t>( \
std::bind(timed_func<operation_t, op_args_t>, desc, \
std::function<operation_t>(std::bind(repeat<operation_t, op_args_t>, count, operation, _1, _2)), \
_1, _2)))
TEST(1000, co_insert, "push1");
TEST(1000000, co_insert, "push2");
TEST(1234, co_erase, "erase1");
TEST(1000, co_insert, "push3");
TEST(543, co_erase, "erase2");
TEST(2, co_clear, "clear1");
TEST(3456, co_particle_insert, "PartiInsert1");
TEST(1000000, co_particle_insert, "PartiInsert2");
println("All tests done.");
return 0;
}