• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright John Maddock 2006.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <fstream>
7 #include <boost/math/tools/test_data.hpp>
8 #include "mp_t.hpp"
9 
10 using namespace boost::math::tools;
11 using namespace std;
12 
13 struct cube_data_generator
14 {
operator ()cube_data_generator15    mp_t operator()(mp_t z)
16    {
17       mp_t result = z*z*z;
18       // if result is out of range of a float,
19       // don't include in test data as it messes up our results:
20       if(result > (std::numeric_limits<float>::max)())
21          throw std::domain_error("");
22       if(result < (std::numeric_limits<float>::min)())
23          throw std::domain_error("");
24       return result;
25    }
26 };
27 
main(int argc,char * argv[])28 int main(int argc, char* argv[])
29 {
30    parameter_info<mp_t> arg1;
31    test_data<mp_t> data;
32 
33    std::cout << "Welcome.\n"
34       "This program will generate spot tests for the cbrt function:\n\n";
35 
36    bool cont;
37    std::string line;
38 
39    do{
40       if(0 == get_user_parameter_info(arg1, "z"))
41          return 1;
42       data.insert(cube_data_generator(), arg1);
43 
44       std::cout << "Any more data [y/n]?";
45       std::getline(std::cin, line);
46       boost::algorithm::trim(line);
47       cont = (line == "y");
48    }while(cont);
49 
50    std::cout << "Enter name of test data file [default=cbrt_data.ipp]";
51    std::getline(std::cin, line);
52    boost::algorithm::trim(line);
53    if(line == "")
54       line = "cbrt_data.ipp";
55    std::ofstream ofs(line.c_str());
56    ofs << std::scientific << std::setprecision(40);
57    write_code(ofs, data, "cbrt_data");
58 
59    return 0;
60 }
61 
62 
63 
64 
65