chunkedseq
container library for large in-memory data sets
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
generators.hpp
Go to the documentation of this file.
1 
13 #include "prelims.hpp" // must be loaded before quickcheck.hh
14 #include "quickcheck.hh"
15 
16 #ifndef _PASL_DATA_TEST_GENERATORS_H_
17 #define _PASL_DATA_TEST_GENERATORS_H_
18 
19 namespace pasl {
20 namespace data {
21 
22 /* NOTE:
23  * if you want your generator function to be seen by the quickcheck
24  * framework, you must put a forward reference of the function first
25  * into prelims.hpp so that the forward reference appears before
26  * quickcheck.hh is included.
27  */
28 
29 template <class Item>
31  return quickcheck::generateInRange(Item(1), Item(1<<8));
32 }
33 
34 static inline bool flip_coin() {
35  bool b;
37  return b;
38 }
39 
40 template <class T, class U, class C, class S>
42  using value_type = typename T::value_type;
43  for (size_t i = 0; i < nb_items; i++) {
44  value_type v = generate_value<value_type>();
45  if (flip_coin()) {
46  dst.trusted.push_back(v);
47  dst.untrusted.push_back(v);
48  } else {
49  dst.trusted.push_front(v);
50  dst.untrusted.push_front(v);
51  }
52  }
53  assert(dst.ok());
54 }
55 
56 template <class T, class U, class C>
57 void random_push_pop_sequence(size_t nb_items, container_pair<T, U, C, bag_container_same<T>>& dst) {
58  using value_type = typename T::value_type;
59  for (size_t i = 0; i < nb_items; i++) {
60  value_type v = generate_value<value_type>();
61  dst.trusted.push_back(v);
62  dst.untrusted.push_back(v);
63  }
64  assert(dst.ok());
65 }
66 
67 template <class T, class U, class C, class S>
69  using value_type = typename T::value_type;
70  for (size_t i = 0; i < nb; i++) {
71  int sz = (int)dst.trusted.size();
72  int pos = (sz == 0) ? 0 : quickcheck::generateInRange(0, sz-1);
73  value_type v;
74  quickcheck::generate(1<<15, v);
75  dst.trusted.insert(dst.trusted.begin() + pos, v);
76  dst.untrusted.insert(dst.untrusted.begin() + pos, v);
77  }
78 }
79 
80 extern bool generate_by_insert;
81 
82 template <class Item, class U, class C, class S>
83 void generate(size_t& nb, container_pair<pasl::data::stl::deque_seq<Item>, U, C, S>& dst) {
84  if (generate_by_insert)
85  random_insert_sequence(nb, dst);
86  else
87  random_push_pop_sequence(nb, dst);
88 }
89 
90 template <class Key, class T, class Compare, class Alloc, class U, class C, class S>
91 void generate(size_t& nb, container_pair<std::map<Key,T,Compare,Alloc>, U, C, S>& dst) {
92  for (size_t i = 0; i < nb; i++) {
93  Key key = quickcheck::generateInRange(0, Key(1<<18));
94  T val = generate_value<T>();
95  dst.trusted[key] = val;
96  dst.untrusted[key] = val;
97  }
98 }
99 
100 } // end namespace
101 } // end namespace
102 
103 #endif
trusted_container_type trusted
Definition: prelims.hpp:86
void random_insert_sequence(size_t nb, container_pair< T, U, C, S > &dst)
Definition: generators.hpp:68
Data generation for randomize unit testing.
Definition: algebra.hpp:18
void generate(size_t &nb, container_pair< std::map< Key, T, Compare, Alloc >, U, C, S > &dst)
Definition: generators.hpp:91
Item generate_value()
Definition: generators.hpp:30
untrusted_container_type untrusted
Definition: prelims.hpp:87
void random_push_pop_sequence(size_t nb_items, container_pair< T, U, C, S > &dst)
Definition: generators.hpp:41
bytes_8 Item
Definition: do_fifo.cpp:107
void generate(size_t &nb, container_pair< pasl::data::stl::deque_seq< Item >, U, C, S > &dst)
Definition: generators.hpp:83