GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — AliceO2/Algorithm/test/test_RangeTokenizer.cxx at dev · nstrangm/AliceO2 Expand file tree/ Copy pathtest_RangeTokenizer.cxxMore file actions 66 lines (57 loc) · 2.25 KB / Copy pathtest_RangeTokenizer.cxxFile metadata and controls66 lines (57 loc) · 2.25 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 // Copyright 2019-2020 CERN and copyright holders of ALICE O2. // See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. // All rights not expressly granted are reserved. // // This software is distributed under the terms of the GNU General Public // License v3 (GPL Version 3), copied verbatim in the file "COPYING". // // In applying this license CERN does not waive the privileges and immunities // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. // @file test_RangeTokenizer.cxx // @author Matthias Richter // @since 2018-12-11 // @brief Test program for RangeTokenizer #define BOOST_TEST_MODULE Algorithm RangeTokenizer test #define BOOST_TEST_MAIN #define BOOST_TEST_DYN_LINK #include <boost/test/unit_test.hpp> #include "../include/Algorithm/RangeTokenizer.h" #include <vector> #include <map> using RangeTokenizer = o2::RangeTokenizer; BOOST_AUTO_TEST_CASE(test_simple_integral) { // the simple case using integral type std::vector<int> tokens = RangeTokenizer::tokenize<int>("0-5,10,13-15"); std::vector<int> expected{0, 1, 2, 3, 4, 5, 10, 13, 14, 15}; BOOST_CHECK(tokens == expected); } BOOST_AUTO_TEST_CASE(test_simple_string) { // simple case using string type std::vector<std::string> tokens = RangeTokenizer::tokenize<std::string>("apple,strawberry,tomato"); BOOST_CHECK(tokens[0] == "apple"); BOOST_CHECK(tokens[1] == "strawberry"); BOOST_CHECK(tokens[2] == "tomato"); } BOOST_AUTO_TEST_CASE(test_mapped_custom) { // process a custom type according to a map enum struct Food { Apple, Strawberry, Tomato }; const std::map<std::string, Food> FoodMap{ {"apple", Food::Apple}, {"strawberry", Food::Strawberry}, {"tomato", Food::Tomato}, }; auto tester = [FoodMap](const char* arg) { // use a custom mapper function, this evetually throws an exception if the token is not in the map return std::move(RangeTokenizer::tokenize<Food>(arg, [FoodMap](auto const& token) { return FoodMap.at(token); })); }; auto tokens = tester("apple,tomato"); BOOST_CHECK(tokens[0] == Food::Apple); BOOST_CHECK(tokens[1] == Food::Tomato); BOOST_CHECK_THROW(tester("blueberry"), std::out_of_range); } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |