Lumiera  0.pre.03
»edit your freedom«
util-collection-test.cpp
Go to the documentation of this file.
1 /*
2  UtilCollection(Test) - helpers and shortcuts for working with collections
3 
4  Copyright (C)
5  2012, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/itertools.hpp"
21 #include "lib/util-coll.hpp"
22 #include "lib/iter-adapter.hpp"
23 #include "lib/meta/trait.hpp"
24 
25 
26 #include <boost/lexical_cast.hpp>
27 #include <vector>
28 
29 
30 using ::Test;
31 
32 using util::first;
33 using util::last;
34 
38 
39 using boost::lexical_cast;
40 
41 
42 
43 namespace util {
44 namespace test {
45 
46  typedef std::vector<uint> VecI;
47  typedef lib::RangeIter<VecI::iterator> RangeI;
48 
49 
50 
51  namespace{ // Test data and operations
52 
53  VecI
54  someNumberz (uint count)
55  {
56  VecI numbers;
57  numbers.reserve(count);
58  while (count)
59  numbers.push_back(count--);
60 
61  return numbers;
62  }
63 
64  } // (End) test data and operations
65 
66 
67 
68  /*****************************************************************/
75  class UtilCollection_test : public Test
76  {
77  virtual void
78  run (Arg arg)
79  {
80  verify_typeDetectors();
81 
82  uint NUM_ELMS = firstVal (arg, 20);
83  VecI container = someNumberz (NUM_ELMS);
84  RangeI iterator(container.begin(), container.end());
85 
86  verify_accessFirstLast (container, NUM_ELMS);
87  verify_accessFirstLast (iterator, NUM_ELMS);
88 
89  verify_Min_Max (container, NUM_ELMS);
90  verify_Min_Max (iterator, NUM_ELMS);
91  }
92 
93 
94  template<class COL>
95  void
96  verify_accessFirstLast (COL const& col, uint lim)
97  {
98  uint theFirst = lim;
99  uint theLast = 1;
100 
101  CHECK (first(col) == theFirst);
102  CHECK (last(col) == theLast);
103  }
104 
105 
106  template<class COL>
107  void
108  verify_Min_Max (COL const& col, uint lim)
109  {
110  uint expectedMax = lim;
111  uint expectedMin = 1;
112 
113  CHECK (max (col) == expectedMax);
114  CHECK (min (col) == expectedMin);
115 
116  COL empty;
117 
118  using Val = typename COL::value_type;
119 
120  CHECK (max (empty) == std::numeric_limits<Val>::min());
121  CHECK (min (empty) == std::numeric_limits<Val>::max());
122  }
123 
124 
125  void
126  verify_typeDetectors()
127  {
130 
133 
136  }
137  };
138 
139 
140 
141 
142  LAUNCHER (UtilCollection_test, "unit common");
143 
144 
145 }} // namespace util::test
146 
Trait template to detect a type usable with the STL for-each loop.
Definition: trait.hpp:555
Trait template to detect a type also supporting STL-style backwards iteration.
Definition: trait.hpp:619
auto first(IT ii)
extract the first element yielded by an Lumiera Forward Iterator.
Definition: util-coll.hpp:132
auto first(COLL const &coll)
access the first element of a STL-like container.
Definition: util-coll.hpp:102
Definition: run.hpp:40
Helper template(s) for creating Lumiera Forward Iterators.
auto last(COLL const &coll)
access the last element of a STL-like container.
Definition: util-coll.hpp:117
Simplistic test class runner.
Trait template to detect a type usable immediately as "Lumiera Forward Iterator" in a specialised for...
Definition: trait.hpp:510
Helpers for type detection, type rewriting and metaprogramming.
Helpers for working with iterators based on the pipeline model.
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
Some small helpers and convenience shortcuts to ease working with collections and sequences (given by...