Lumiera  0.pre.03
»edit your freedom«
util-tuple-test.cpp
Go to the documentation of this file.
1 /*
2  UtilTuple(Test) - helpers and shortcuts for working with tuples
3 
4  Copyright (C) Lumiera.org
5  2023, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/util-tuple.hpp"
30 #include "lib/iter-adapter.hpp"
31 #include "lib/util.hpp"
32 
33 #include <vector>
34 
35 
36 using ::Test;
37 using util::isnil;
38 using std::tuple_size_v;
39 
40 
41 namespace util {
42 namespace test {
43 
44  typedef std::vector<uint> VecI;
45  typedef lib::RangeIter<VecI::iterator> RangeI;
46 
47 
48 
49  namespace{ // Test data and operations
50 
51  VecI
52  someNumbz (uint count)
53  {
54  VecI numbers;
55  numbers.reserve(count);
56  while (count)
57  numbers.push_back(count--);
58 
59  return numbers;
60  }
61 
62  } // (End) test data and operations
63 
64 
65 
66  /*****************************************************************/
71  class UtilTuple_test : public Test
72  {
73 
74  void
75  run (Arg)
76  {
78  }
79 
80 
85  void
87  {
88  VecI container = someNumbz (5);
89  RangeI iterator(container.begin(), container.end());
90 
91  CHECK (not isnil (iterator));
92  auto tup = seqTuple<5> (iterator);
93  CHECK ( isnil (iterator)); // iterator was exhausted on unpacking...
94  CHECK (5 == tuple_size_v<decltype(tup)>);
95 
96  auto& [g,f,e,d,c] = tup;
97  CHECK (c == 1);
98  CHECK (d == 2);
99  CHECK (e == 3);
100  CHECK (f == 4);
101  CHECK (g == 5);
102 
103  g = 55; // we indeed got references...
104  CHECK (55 == std::get<0> (tup));
105  CHECK (55 == container.front());
106  }
107  };
108 
109 
110 
111 
112  LAUNCHER (UtilTuple_test, "unit common");
113 
114 
115 }} // namespace util::test
116 
Definition: run.hpp:49
Helper template(s) for creating Lumiera Forward Iterators.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...