1 // Boost.Convert test and usage example
2 // Copyright (c) 2009-2016 Vladimir Batov.
3 // Use, modification and distribution are subject to the Boost Software License,
4 // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
6 #ifndef BOOST_CONVERT_TEST_PREPARE_HPP
7 #define BOOST_CONVERT_TEST_PREPARE_HPP
9 #include <boost/array.hpp>
13 // boostinspect:nounnamed
14 namespace { namespace local
16 // C1. 18 = 9 positive + 9 negative numbers with the number of digits from 1 to 9.
17 // Even though INT_MAX(32) = 2147483647, i.e. 10 digits (not to mention long int)
18 // we only test up to 9 digits as Spirit does not handle more than 9.
20 typedef boost::array<my_string, 18> strings; //C1
21 ///////////////////////////////////////////////////////////////////////////
22 // Generate a random number string with N digits
24 gen_int(int digits, bool negative)
28 if (negative) // Prepend a '-'
31 result += '1' + (std::rand()%9); // The first digit cannot be '0'
33 for (int i = 1; i < digits; ++i) // Generate the remaining digits
34 result += '0' + (std::rand()%10);
41 static local::strings strings;
43 static bool negative = true;
47 // Seed the random generator
48 std::srand(std::time(0));
50 for (size_t k = 0; k < strings.size(); ++k)
51 strings[k] = local::gen_int(k/2 + 1, negative = !negative).c_str();
59 #endif // BOOST_CONVERT_TEST_PREPARE_HPP