Project
Loading...
Searching...
No Matches
test_dc_primitives.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 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
16
17#define BOOST_TEST_MODULE Utility test
18#define BOOST_TEST_MAIN
19#define BOOST_TEST_DYN_LINK
20#include <boost/test/unit_test.hpp>
21#include "../include/DataCompression/dc_primitives.h"
22#include <boost/mpl/size.hpp>
23#include <boost/type.hpp>
24#include <boost/mpl/range_c.hpp>
25#include <boost/mpl/vector.hpp>
26#include <boost/mpl/for_each.hpp>
27#include <boost/mpl/vector_c.hpp>
28#include <iostream>
29#include <iomanip>
30#include <vector>
31
32namespace o2
33{
34namespace data_compression
35{
36
47 template <typename T>
48 void operator()(boost::type<T>)
49 {
50 std::cout << "Max number in " << std::setw(2) << T::value << "-bit range: " << getmax<uint64_t, T::value>::value
51 << std::endl;
52 }
53};
54
56 template <typename T>
57 void operator()(boost::type<T>)
58 {
59 std::cout << "number of bits required for value " << std::setw(4) << T::value << ": " << std::setw(3)
61 }
62};
63
64template <typename ValueList>
66 ValueList mList;
68 AlphabetTester(const ValueList& list) : mList(list) {}
69 template <typename Alphabet>
70 void operator()(Alphabet& alphabet)
71 {
72 for (const auto v : mList) {
73 std::cout << "Alphabet '" << alphabet.getName() << "': value " << std::setw(2) << v << " is "
74 << (alphabet.isValid(v) ? "valid" : "not valid") << std::endl;
75 }
76 }
77};
78
79BOOST_AUTO_TEST_CASE(test_dc_primitives)
80{
81 // test the getmax meta program
82 std::cout << std::endl
83 << "Testing getmax meta program ..." << std::endl;
84 using bitranges = boost::mpl::vector_c<uint16_t, 0, 1, 2, 3, 4, 31, 32, 64>;
85 boost::mpl::for_each<bitranges, boost::type<boost::mpl::_>>(getmaxTester());
86
87 // test the getnofelements meta program
88 std::cout << std::endl
89 << "Testing getnofelements meta program ..." << std::endl;
90 constexpr uint16_t lowerelement = 0;
91 constexpr uint16_t upperelement = 10;
92 std::cout << "Number of elements in range [" << lowerelement << "," << upperelement
94
95 // test the upperbinarybound compile time evaluation
96 std::cout << std::endl
97 << "Testing upperbinarybound meta program ..." << std::endl;
98 boost::mpl::for_each<boost::mpl::vector_c<int, 6, 1000, 86, 200>, boost::type<boost::mpl::_>>(
100
101 std::cout << std::endl
102 << "Testing alphabet template ..." << std::endl;
103 // declare two types of alphabets: a contiguous range alphabet with symbols
104 // between -1 and 10 and a bit-range alphabet for a 10-bit word
105 using TestAlphabetName = boost::mpl::string<'T', 'e', 's', 't'>::type;
106 using TenBitAlphabetName = boost::mpl::string<'1', '0', '-', 'b', 'i', 't'>::type;
107 using TestAlphabet = ContiguousAlphabet<int16_t, -1, 10, TestAlphabetName>;
109
110 // now check a set of values if they are valid in each of the alphabets
111 // the check is done at runtime on types of alphabets rather than on
112 // actual objects
113 std::vector<int16_t> values = {0, 5, 15, -2, -1};
114 using ParameterSet = boost::mpl::vector<TestAlphabet, TenBitAlphabet>;
115 boost::mpl::for_each<ParameterSet>(AlphabetTester<std::vector<int16_t>>(values));
116}
117
118} // namespace data_compression
119} // namespace o2
const GLdouble * v
Definition glcorearb.h:832
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLenum GLsizei GLsizei GLint * values
Definition glcorearb.h:1576
BOOST_AUTO_TEST_CASE(test_dc_primitives)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Definition list.h:40
Get maximum of an n-bit number.
Get number of elements in a sequence of integral types This redirects to the size meta program of the...
Get the upper binary bound of a number The gives the number of bits required to present a number.