chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
quickcheck_chunkedseq.cpp
Go to the documentation of this file.
1 
13 #include "cmdline.hpp"
14 #include "properties.hpp"
15 
16 /***********************************************************************/
17 
18 namespace pasl {
19 namespace data {
20 
21 /*---------------------------------------------------------------------*/
22 
23 static constexpr int default_capacity = 8;
24 
28 
29 template <class Property>
30 void checkit(std::string msg) {
31  assert(nb_tests > 0);
32  quickcheck::check<Property>(msg.c_str(), nb_tests);
33 }
34 
35 /*---------------------------------------------------------------------*/
36 /* Unit tests for sequence data structures */
37 
38 template <class Properties>
40  util::cmdline::argmap_dispatch c;
41  c.add("pushpop", [] { // run push pop tests
42  auto msg = "we get consistent results on randomly selected "
43  "sequences of pushes and pops";
44  checkit<typename Properties::push_pop_sequence_same>(msg);
45  });
46  c.add("split", [] { // run split tests
47  auto msg = "we get consistent results for calls to split on a "
48  "random position in the sequence";
49  checkit<typename Properties::split_same>(msg);
50  });
51  c.add("split_in_range", [] { // run split-in-range tests
52  auto msg = "we get consistent results for calls to split on "
53  "a range of valid positions";
54  checkit<typename Properties::split_in_range_same>(msg);
55  });
56  c.add("concat", [] { // run concat tests
57  auto msg = "we get consistent results on calls to concat";
58  checkit<typename Properties::concat_same>(msg);
59  });
60  c.add("random_access", [] {
61  auto msg = "we get consistent results on random accesses to the "
62  "container";
63  checkit<typename Properties::random_access_same>(msg);
64  });
65  c.add("iterator", [] {
66  auto msg = "we get consistent results on iterator-based traversal";
67  checkit<typename Properties::iterator_same>(msg);
68  });
69  c.add("random_access_iterator", [] {
70  auto msg = "we get consistent results on random iterator-based traversal";
71  checkit<typename Properties::random_access_iterator_same>(msg);
72  });
73  c.add("insert", [] {
74  auto msg = "we get consistent results over calls to insert";
75  checkit<typename Properties::insert_same>(msg);
76  });
77  c.add("erase", [] {
78  auto msg = "we get consistent results over calls to erase";
79  checkit<typename Properties::erase_same>(msg);
80  });
81  c.add("for_each_segment", [] {
82  auto msg = "we get correct results over calls to for_each_segment";
83  checkit<typename Properties::for_each_segment_correct>(msg);
84  });
85  c.add("for_each_in_interval", [] {
86  auto msg = "we get correct results over calls to for_each_segment on random intervals";
87  checkit<typename Properties::for_each_in_interval_correct>(msg);
88  });
89  c.add("pushn_popn", [] {
90  auto msg = "we get correct results over calls to pushn and to popn";
91  checkit<typename Properties::pushn_popn_sequence_same>(msg);
92  });
93  c.add("backn_frontn", [] {
94  auto msg = "we get correct results over calls to backn and frontn";
95  checkit<typename Properties::backn_frontn_sequence_same>(msg);
96  });
97  print_dashes();
98  util::cmdline::dispatch_by_argmap_with_default_all(c, "property");
99  print_dashes();
100 }
101 
102 using value_type = int;
103 using trusted_sequence_container_type = pasl::data::stl::deque_seq<value_type>;
105 template <class Untrusted_container>
106 class container_copy_from_untrusted_to_trusted {
107 public:
108  static trusted_sequence_container_type conv(const Untrusted_container& u) {
110  u.for_each([&] (value_type v) {
111  t.push_back(v);
112  });
113  return t;
114  }
115 };
116 template <class Untrusted_sequence_container>
118 template <class Untrusted_sequence_container>
120 
121 template <int Chunk_capacity>
123  util::cmdline::argmap_dispatch c;
124  c.add("chunked_bootstrapped_deque", [] {
126  chunkedseq_dispatch_by_property<sequence_container_properties<deque_type>>();
127  });
128 #ifndef SKIP_NON_DEQUE
129  c.add("chunked_bootstrapped_stack", [] {
131  chunkedseq_dispatch_by_property<sequence_container_properties<deque_type>>();
132  });
133  c.add("chunked_ftree_deque", [] {
135  chunkedseq_dispatch_by_property<sequence_container_properties<deque_type>>();
136  });
137  c.add("chunked_ftree_stack", [] {
139  chunkedseq_dispatch_by_property<sequence_container_properties<deque_type>>();
140  });
141  /*
142  c.add("triv", [] {
143  using deque_type = bootchunkedseq::triv<value_type, Chunk_capacity>;
144  chunkedseq_dispatch_by_property<container_properties<deque_type>>();
145  });
146  */
147 #endif
148  util::cmdline::dispatch_by_argmap_with_default_all(c, "datastruct");
149 }
150 
152  util::cmdline::argmap_dispatch c;
153  c.add("2", [] { seq_dispatch_by_container<2>(); });
154  c.add("8", [] { seq_dispatch_by_container<8>(); });
155  c.add("512", [] { seq_dispatch_by_container<512>(); });
156  util::cmdline::dispatch_by_argmap(c, "chunk_capacity", std::to_string(default_capacity));
157 }
158 
159 /*---------------------------------------------------------------------*/
160 /* Unit tests for bag data structures */
161 
162 template <class Properties>
164  util::cmdline::argmap_dispatch c;
165  c.add("pushpop", [] { // run push pop tests
166  auto msg = "we get consistent results on randomly selected "
167  "sequences of pushes and pops";
168  checkit<typename Properties::push_pop_sequence_same>(msg);
169  });
170  c.add("split", [] { // run split tests
171  auto msg = "we get consistent results for calls to split on a "
172  "random position in the sequence";
173  checkit<typename Properties::split_same>(msg);
174  });
175  c.add("concat", [] { // run concat tests
176  auto msg = "we get consistent results on calls to concat";
177  checkit<typename Properties::concat_same>(msg);
178  });
179  c.add("iterator", [] {
180  auto msg = "we get consistent results on iterator-based traversal";
181  checkit<typename Properties::iterator_same>(msg);
182  });
183  c.add("for_each_segment", [] {
184  auto msg = "we get correct results over calls to for_each_segment";
185  checkit<typename Properties::for_each_segment_correct>(msg);
186  });
187  c.add("pushn_popn", [] {
188  auto msg = "we get correct results over calls to pushn and to popn";
189  checkit<typename Properties::pushn_popn_sequence_same>(msg);
190  });
191  c.add("backn_frontn", [] {
192  auto msg = "we get correct results over calls to backn and frontn";
193  checkit<typename Properties::backn_frontn_sequence_same>(msg);
194  });
195  print_dashes();
196  util::cmdline::dispatch_by_argmap_with_default_all(c, "property");
197  print_dashes();
198 }
199 
200 template <class Untrusted_bag_container>
202 template <class Untrusted_bag_container>
204 
205 template <int Chunk_capacity>
207  util::cmdline::argmap_dispatch c;
208  c.add("chunked_bootstrapped", [] {
210  chunkedbag_dispatch_by_property<bag_container_properties<bag_type>>();
211  });
212 #ifndef SKIP_NON_DEQUE
213  c.add("chunked_ftree_bag", [] {
215  chunkedbag_dispatch_by_property<bag_container_properties<deque_type>>();
216  });
217 #endif
218  util::cmdline::dispatch_by_argmap_with_default_all(c, "datastruct");
219 }
220 
222  util::cmdline::argmap_dispatch c;
223  c.add("2", [] { bag_dispatch_by_container<2>(); });
224  c.add("8", [] { bag_dispatch_by_container<8>(); });
225  c.add("512", [] { bag_dispatch_by_container<512>(); });
226  util::cmdline::dispatch_by_argmap(c, "chunk_capacity", std::to_string(default_capacity));
227 }
228 
229 /*---------------------------------------------------------------------*/
230 /* Unit tests for dynamic dictionary */
231 
232 using trusted_map_type = std::map<int,int>;
234 class map_copy_from_untrusted_to_trusted {
235 public:
236  static trusted_map_type conv(const untrusted_map_type& u) {
238  for (auto it = u.begin(); it != u.end(); it++) {
239  auto p = *it;
240  t[p.first] = p.second;
241  }
242  return t;
243  }
244 };
247 
248 void map_dispatch() {
249  auto msg = "we get consistent results with std::map";
250  checkit<typename map_properties::map_same>(msg);
251 }
252 
253 /*---------------------------------------------------------------------*/
254 
255 } // end namespace
256 } // end namespace
257 
258 int main(int argc, char** argv) {
259  pasl::util::cmdline::set(argc, argv);
260  pasl::data::nb_tests = pasl::util::cmdline::parse_or_default_int("nb_tests", 1000);
261  pasl::data::print_chunkedseq_verbose = pasl::util::cmdline::parse_or_default_bool("verbose", true);
262  pasl::data::generate_by_insert = pasl::util::cmdline::parse_or_default_bool("generate_by_insert", false);
263  pasl::util::cmdline::argmap_dispatch c;
264  c.add("sequence", [] { pasl::data::seq_dispatch_by_capacity(); });
265  c.add("bag", [] { pasl::data::bag_dispatch_by_capacity(); });
266  c.add("map", [] { pasl::data::map_dispatch(); });
267  pasl::util::cmdline::dispatch_by_argmap(c, "profile", "sequence");
268  return 0;
269 }
270 
271 
272 /***********************************************************************/
void chunkedbag_dispatch_by_property()
Testing properties to be used by randomize unit testing to check invariants.
iterator begin() const
Definition: map.hpp:279
int main(int argc, char **argv)
trusted_sequence_container_type trusted_bag_container_type
pasl::data::stl::deque_seq< value_type > trusted_sequence_container_type
Definition: algebra.hpp:18
void chunkedseq_dispatch_by_property()
void seq_dispatch_by_container()
void checkit(std::string msg)
void bag_dispatch_by_container()
iterator end() const
Definition: map.hpp:283
std::map< int, int > trusted_map_type