Line data Source code
1 : // Author(s): Wieger Wesselink 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : // 9 : 10 : #define BOOST_AUTO_TEST_MAIN 11 : #include <boost/test/included/unit_test.hpp> 12 : 13 : #include "mcrl2/utilities/parse_numbers.h" 14 : 15 : using namespace mcrl2; 16 : 17 5 : void test_parse_natural_number_sequence(const std::string& text, const std::vector<std::size_t>& expected_result) 18 : { 19 5 : std::vector<std::size_t> result = utilities::parse_natural_number_sequence(text); 20 5 : BOOST_CHECK(result == expected_result); 21 5 : } 22 : 23 2 : BOOST_AUTO_TEST_CASE(parse_natural_numbers_test) 24 : { 25 1 : test_parse_natural_number_sequence(" 1 2 3 ", { 1, 2, 3 }); 26 1 : test_parse_natural_number_sequence(" ", { }); 27 1 : test_parse_natural_number_sequence("1", { 1 }); 28 1 : test_parse_natural_number_sequence(" 1", { 1 }); 29 1 : test_parse_natural_number_sequence("1 ", { 1 }); 30 : 31 4 : BOOST_CHECK_THROW(utilities::parse_natural_number_sequence("a"), mcrl2::runtime_error); 32 4 : BOOST_CHECK_THROW(utilities::parse_natural_number_sequence("12 a"), mcrl2::runtime_error); 33 4 : BOOST_CHECK_THROW(utilities::parse_natural_number_sequence("12 3a "), mcrl2::runtime_error); 34 1 : } 35 : 36 4 : void test_parse_number(const std::string& text, std::size_t expected_result) 37 : { 38 4 : std::size_t result = utilities::parse_natural_number(text); 39 4 : BOOST_CHECK_EQUAL(result, expected_result); 40 4 : } 41 : 42 2 : BOOST_AUTO_TEST_CASE(parse_number_test) 43 : { 44 1 : test_parse_number("10", 10); 45 1 : test_parse_number(" 10", 10); 46 1 : test_parse_number(" 10 ", 10); 47 1 : test_parse_number(" 023 ", 23); 48 : 49 4 : BOOST_CHECK_THROW(utilities::parse_natural_number(""), mcrl2::runtime_error); 50 4 : BOOST_CHECK_THROW(utilities::parse_natural_number(" "), mcrl2::runtime_error); 51 4 : BOOST_CHECK_THROW(utilities::parse_natural_number("a"), mcrl2::runtime_error); 52 4 : BOOST_CHECK_THROW(utilities::parse_natural_number("12 a"), mcrl2::runtime_error); 53 4 : BOOST_CHECK_THROW(utilities::parse_natural_number("12 3a "), mcrl2::runtime_error); 54 1 : }