Project
Loading...
Searching...
No Matches
test_ransIterators.cxx
Go to the documentation of this file.
1// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#define BOOST_TEST_MODULE Utility test
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_DYN_LINK
19
20#include <boost/test/unit_test.hpp>
21
22#include "rANS/iterator.h"
23
24class ShiftFunctor
25{
26 public:
27 ShiftFunctor(size_t shift) : mShift{shift} {};
28
29 template <typename iterA_T, typename iterB_T>
30 inline uint32_t operator()(iterA_T iterA, iterB_T iterB) const
31 {
32 return *iterB + (static_cast<uint32_t>(*iterA) << mShift);
33 };
34
35 template <typename iterA_T, typename iterB_T>
36 inline void operator()(iterA_T iterA, iterB_T iterB, uint32_t value) const
37 {
38 *iterA = value >> mShift;
39 *iterB = value & ((1 << mShift) - 1);
40 };
41
42 private:
43 size_t mShift;
44};
45
47 const std::vector<uint16_t> a{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
48 const std::vector<uint16_t> b{a.rbegin(), a.rend()};
49 const ShiftFunctor f{16};
50 const std::vector<uint32_t> aAndB{0x0001000f, 0x0002000e, 0x0003000d, 0x0004000c, 0x0005000b,
51 0x0006000a, 0x00070009, 0x00080008, 0x00090007, 0x000a0006,
52 0x000b0005, 0x000c0004, 0x000d0003, 0x000e0002, 0x000f0001};
53};
54
56{
57
58 o2::rans::CombinedInputIterator iter(a.begin(), b.begin(), f);
59 // test equal
60 const o2::rans::CombinedInputIterator first(a.begin(), b.begin(), f);
62 // test not equal
63 const o2::rans::CombinedInputIterator second(++(a.begin()), ++(b.begin()), f);
64 BOOST_CHECK_NE(iter, second);
65 // test smaller
66 BOOST_CHECK_LT(first, second);
67 // test greater
68 BOOST_CHECK_GT(second, first);
69 // test greater-equals
70 BOOST_CHECK_GE(second, first);
71 BOOST_CHECK_GE(first, first);
72 // test smaller-equals
73 BOOST_CHECK_LE(first, second);
74 BOOST_CHECK_LE(first, first);
75
76 // test pre-increment
77 ++iter;
78 BOOST_CHECK_EQUAL(iter, second);
79 // test post-increment
80 iter = first;
81 BOOST_CHECK_EQUAL(iter++, first);
82 BOOST_CHECK_EQUAL(iter, second);
83 // test pre-decrement
84 iter = second;
85 --iter;
87 // test post-decrement
88 iter = second;
89 BOOST_CHECK_EQUAL(iter--, second);
91
92 // test +=
93 iter = first;
94 iter += 1;
95 BOOST_CHECK_EQUAL(iter, second);
96 // test +
97 iter = first;
98 BOOST_CHECK_EQUAL(first + 1, second);
99 BOOST_CHECK_EQUAL(1 + first, second);
100
101 // check -=
102 iter = second;
103 iter -= 1;
105
106 // check -
107 BOOST_CHECK_EQUAL(second - 1, first);
108
109 // check -
110 BOOST_CHECK_EQUAL(second - first, 1);
111
112 // test deref
113 const uint32_t val = first.operator*();
114
115 BOOST_CHECK_EQUAL(val, aAndB.front());
116
117 // check []
118 BOOST_CHECK_EQUAL(first[1], *second);
119}
120
122{
123 std::vector<uint16_t> aOut(2, 0x0);
124 std::vector<uint16_t> bOut(2, 0x0);
125
127 auto iter = iterFactory.makeIter(aOut.begin(), bOut.begin(), f);
128
129 // test deref:
130 *iter = aAndB[0];
131 BOOST_CHECK_EQUAL(aOut[0], a[0]);
132 BOOST_CHECK_EQUAL(bOut[0], b[0]);
133 aOut[0] = 0x0;
134 bOut[0] = 0x0;
135
136 // test pre-increment
137 *(++iter) = aAndB[1];
138 BOOST_CHECK_EQUAL(aOut[0], 0);
139 BOOST_CHECK_EQUAL(bOut[0], 0);
140 BOOST_CHECK_EQUAL(aOut[1], a[1]);
141 BOOST_CHECK_EQUAL(bOut[1], b[1]);
142 aOut.assign(2, 0x0);
143 bOut.assign(2, 0x0);
144 iter = iterFactory.makeIter(aOut.begin(), bOut.begin(), f);
145
146 // test post-increment
147 auto preInc = iter++;
148 *preInc = aAndB[0];
149 BOOST_CHECK_EQUAL(aOut[0], a[0]);
150 BOOST_CHECK_EQUAL(bOut[0], b[0]);
151 BOOST_CHECK_EQUAL(aOut[1], 0x0);
152 BOOST_CHECK_EQUAL(bOut[1], 0x0);
153 aOut.assign(2, 0x0);
154 bOut.assign(2, 0x0);
155 *iter = aAndB[1];
156 BOOST_CHECK_EQUAL(aOut[0], 0);
157 BOOST_CHECK_EQUAL(bOut[0], 0);
158 BOOST_CHECK_EQUAL(aOut[1], a[1]);
159 BOOST_CHECK_EQUAL(bOut[1], b[1]);
160};
161
162BOOST_FIXTURE_TEST_CASE(test_CombinedInputIteratorReadArray, test_CombninedIteratorFixture)
163{
164
165 const o2::rans::CombinedInputIterator begin(a.begin(), b.begin(), f);
166 const o2::rans::CombinedInputIterator end(a.end(), b.end(), f);
167 BOOST_CHECK_EQUAL_COLLECTIONS(begin, end, aAndB.begin(), aAndB.end());
168};
169
170BOOST_FIXTURE_TEST_CASE(test_CombinedOutputIteratorWriteArray, test_CombninedIteratorFixture)
171{
172 std::vector<uint16_t> aRes(a.size(), 0);
173 std::vector<uint16_t> bRes(b.size(), 0);
174
175 auto iter = o2::rans::CombinedOutputIteratorFactory<uint32_t>::makeIter(aRes.begin(), bRes.begin(), f);
176 for (auto input : aAndB) {
177 *iter++ = input;
178 }
179
180 BOOST_CHECK_EQUAL_COLLECTIONS(aRes.begin(), aRes.end(), a.begin(), a.end());
181 BOOST_CHECK_EQUAL_COLLECTIONS(bRes.begin(), bRes.end(), b.begin(), b.end());
182};
ShiftFunctor(size_t shift)
void operator()(iterA_T iterA, iterB_T iterB, uint32_t value) const
uint32_t operator()(iterA_T iterA, iterB_T iterB) const
GLuint GLuint end
Definition glcorearb.h:469
GLint first
Definition glcorearb.h:399
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLuint GLfloat * val
Definition glcorearb.h:1582
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
public interface for rANS iterators.
static auto makeIter(iterA_T iterA, iterB_T iterB, F functor) -> CombinedOutputIterator< input_T, iterA_T, iterB_T, F >
Definition iterator.h:207
const std::vector< uint32_t > aAndB
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
BOOST_FIXTURE_TEST_CASE(test_CombinedInputIteratorBase, test_CombninedIteratorFixture)