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)
5  2023, 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/util-tuple.hpp"
21 #include "lib/iter-adapter.hpp"
22 #include "lib/util.hpp"
23 
24 #include <vector>
25 
26 
27 using ::Test;
28 using util::isnil;
29 using std::tuple_size_v;
30 
31 
32 namespace util {
33 namespace test {
34 
35  using VecI = std::vector<uint>;
36  using RangeI = lib::RangeIter<VecI::iterator>;
37 
38 
39  namespace{ // Test data and operations
40 
41  VecI
42  someNumbz (uint count)
43  {
44  VecI numbers;
45  numbers.reserve(count);
46  while (count)
47  numbers.push_back(count--);
48 
49  return numbers;
50  }
51 
52  } // (End) test data and operations
53 
54 
55 
56  /*****************************************************************/
61  class UtilTuple_test : public Test
62  {
63 
64  void
65  run (Arg)
66  {
68  }
69 
70 
75  void
77  {
78  VecI container = someNumbz (5);
79  RangeI iterator(container.begin(), container.end());
80 
81  CHECK (not isnil (iterator));
82  auto tup = seqTuple<5> (iterator);
83  CHECK ( isnil (iterator)); // iterator was exhausted on unpacking...
84  CHECK (5 == tuple_size_v<decltype(tup)>);
85 
86  auto& [g,f,e,d,c] = tup;
87  CHECK (c == 1);
88  CHECK (d == 2);
89  CHECK (e == 3);
90  CHECK (f == 4);
91  CHECK (g == 5);
92 
93  g = 55; // we indeed got references...
94  CHECK (55 == std::get<0> (tup));
95  CHECK (55 == container.front());
96  }
97  };
98 
99 
100 
101 
102  LAUNCHER (UtilTuple_test, "unit common");
103 
104 
105 }} // namespace util::test
106 
Definition: run.hpp:40
Helper template(s) for creating Lumiera Forward Iterators.
Simplistic 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...