Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
30using ::Test;
31
32using util::first;
33using util::last;
34
38
39using boost::lexical_cast;
40
41
42
43namespace util {
44namespace test {
45
46 typedef std::vector<uint> VecI;
48
49
50
51 namespace{ // Test data and operations
52
53 VecI
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 {
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 = 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
137 };
138
139
140
141
143
144
145}} // namespace util::test
146
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
Trait template to detect a type usable immediately as "Lumiera Forward Iterator" in a specialised for...
Definition trait.hpp:511
Trait template to detect a type usable with the STL for-each loop.
Definition trait.hpp:556
Trait template to detect a type also supporting STL-style backwards iteration.
Definition trait.hpp:620
void verify_Min_Max(COL const &col, uint lim)
void verify_accessFirstLast(COL const &col, uint lim)
unsigned int uint
Definition integral.hpp:29
Helper template(s) for creating Lumiera Forward Iterators.
Helpers for working with iterators based on the pipeline model.
Test runner and basic definitions for tests.
lib::RangeIter< VecI::iterator > RangeI
std::vector< uint > VecI
auto first(COLL const &coll)
access the first element of a STL-like container.
auto max(IT &&elms)
auto last(COLL const &coll)
access the last element of a STL-like container.
auto min(IT &&elms)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Helpers for type detection, type rewriting and metaprogramming.
Some small helpers and convenience shortcuts to ease working with collections and sequences (given by...