Project
Loading...
Searching...
No Matches
test_ransSparseVector.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#undef NDEBUG
21#include <cassert>
22
23#include <boost/test/unit_test.hpp>
24#include <boost/mpl/vector.hpp>
25#include <gsl/span>
26
28
29using namespace o2::rans;
30using namespace o2::rans::internal;
31
32using source_type = int32_t;
34
36{
37
39
40 BOOST_CHECK_EQUAL(vec.empty(), true);
41 BOOST_CHECK_EQUAL(vec.size(), 0);
42 BOOST_CHECK(vec.begin() == vec.end());
43 BOOST_CHECK(vec.cbegin() == vec.cend());
44};
45
47{
49
50 std::vector<source_type> samples{-5, -2, 1, 3, 5, 8, -5, 5, 1, 1, 1, 14, 8, 8, 8, 8, 8, 8, 8, 8, utils::pow2(18) + 1};
51
52 std::unordered_map<source_type, uint32_t> results{{-5, 2}, {-2, 1}, {-1, 0}, {0, 0}, {1, 4}, {2, 0}, {3, 1}, {4, 0}, {5, 2}, {8, 9}, {14, 1}, {utils::pow2(18) + 1, 1}};
53
54 std::for_each(samples.begin(), samples.end(), [&vec](const source_type& s) { ++vec[s]; });
55
56 BOOST_CHECK_EQUAL(vec.empty(), false);
57 BOOST_CHECK_EQUAL(vec.getOffset(), std::numeric_limits<source_type>::min());
58 BOOST_CHECK_EQUAL(vec.getOffset(), std::numeric_limits<source_type>::min());
59 BOOST_CHECK_EQUAL(vec.size(), 3 * vec.getBucketSize());
60
61 for (auto [key, value] : results) {
63 }
64
65 const auto& vecRef = vec;
66
67 for (auto [key, value] : results) {
68 BOOST_CHECK_EQUAL(vecRef[key], value);
69 }
70
71 // iterate
72 BOOST_CHECK(vec.begin() != vec.end());
73 BOOST_CHECK(vec.cbegin() != vec.cend());
74
75 BOOST_TEST_MESSAGE("testing forward iterators");
76 for (auto iter = vec.begin(); iter != vec.end(); ++iter) {
77 auto value = iter->second;
78 if (value > 0) {
79 BOOST_TEST_MESSAGE(fmt::format("checking symbol [{}]:{}", iter->first, value));
80 BOOST_CHECK_EQUAL(results[iter->first], value);
81 }
82 }
83
84 BOOST_TEST_MESSAGE("testing const forward iterators");
85 for (auto iter = vec.cbegin(); iter != vec.cend(); ++iter) {
86 auto value = iter->second;
87 if (value > 0) {
88 BOOST_TEST_MESSAGE(fmt::format("checking symbol [{}]:{}", iter->first, value));
89 BOOST_CHECK_EQUAL(results[iter->first], value);
90 }
91 }
92}
Vector Wrapper with contiguous but shifted, integer indexing. Base of all frequency container classes...
uint32_t source_type
StringRef key
GLsizei const GLfloat * value
Definition glcorearb.h:819
std::vector< o2::ctf::BufferType > vec
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
BOOST_AUTO_TEST_CASE(test_empty)