summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/qi/real5.cpp
blob: af17004d4ac7955aa531aad976aa05fc50a757f2 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*=============================================================================
    Copyright (c) 2001-2011 Joel de Guzman
    Copyright (c) 2001-2011 Hartmut Kaiser
    Copyright (c) 2011      Bryce Lelbach

    Use, modification and distribution is subject to the Boost Software
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#include "real.hpp"

#include <boost/phoenix/core/reference.hpp>

int
main()
{
    using spirit_test::test;
    using spirit_test::test_attr;
    
    ///////////////////////////////////////////////////////////////////////////
    //  parameterized signed real number tests
    ///////////////////////////////////////////////////////////////////////////
    {
        using boost::spirit::qi::double_;
        double d;

        BOOST_TEST(test("+1234", double_(1234)));
        BOOST_TEST(!test("+1234", double_(-1234)));
        BOOST_TEST(test_attr("+1234", double_(1234), d));
        BOOST_TEST(compare(d, 1234));
        BOOST_TEST(!test_attr("+1234", double_(-1234), d));
        
        BOOST_TEST(test("-1234", double_(-1234)));
        BOOST_TEST(!test("-1234", double_(1234)));
        BOOST_TEST(test_attr("-1234", double_(-1234), d));
        BOOST_TEST(compare(d, -1234));
        BOOST_TEST(!test_attr("-1234", double_(1234), d));

        BOOST_TEST(test("+1.2e3", double_(1.2e3)));
        BOOST_TEST(!test("+1.2e3", double_(-1.2e3)));
        BOOST_TEST(test_attr("+1.2e3", double_(1.2e3), d));
        BOOST_TEST(compare(d, 1.2e3));
        BOOST_TEST(!test_attr("+1.2e3", double_(-1.2e3), d));
        
        BOOST_TEST(test("-1.2e3", double_(-1.2e3)));
        BOOST_TEST(!test("-1.2e3", double_(1.2e3)));
        BOOST_TEST(test_attr("-1.2e3", double_(-1.2e3), d));
        BOOST_TEST(compare(d, -1.2e3));
        BOOST_TEST(!test_attr("-1.2e3", double_(1.2e3), d));
    }

    ///////////////////////////////////////////////////////////////////////////
    //  parameterized unsigned real number tests
    ///////////////////////////////////////////////////////////////////////////
    {
        using boost::spirit::qi::real_parser;
        using boost::spirit::qi::ureal_policies;
        double d;

        real_parser<double, ureal_policies<double> > udouble;

        BOOST_TEST(test("1234", udouble(1234)));
        BOOST_TEST(!test("1234", udouble(4321)));
        BOOST_TEST(test_attr("1234", udouble(1234), d));
        BOOST_TEST(compare(d, 1234));
        BOOST_TEST(!test_attr("1234", udouble(4321), d));

        BOOST_TEST(test("1.2e3", udouble(1.2e3)));
        BOOST_TEST(!test("1.2e3", udouble(3.2e1)));
        BOOST_TEST(test_attr("1.2e3", udouble(1.2e3), d));
        BOOST_TEST(compare(d, 1.2e3));
        BOOST_TEST(!test_attr("1.2e3", udouble(3.2e1), d));
    }
    
    ///////////////////////////////////////////////////////////////////////////
    //  parameterized custom data type
    ///////////////////////////////////////////////////////////////////////////
    {
        using boost::math::concepts::real_concept;
        using boost::spirit::qi::real_parser;
        using boost::spirit::qi::real_policies;

        real_parser<real_concept, real_policies<real_concept> > custom_real;
        real_concept d;

        BOOST_TEST(test("-1234", custom_real(-1234)));
        BOOST_TEST(!test("-1234", custom_real(4321)));
        BOOST_TEST(test_attr("-1234", custom_real(-1234), d));
        BOOST_TEST(compare(d, -1234));
        BOOST_TEST(!test_attr("-1234", custom_real(-4321), d));

        BOOST_TEST(test("1.2e3", custom_real(1.2e3)));
        BOOST_TEST(!test("1.2e3", custom_real(-1.2e3)));
        BOOST_TEST(test_attr("1.2e3", custom_real(1.2e3), d));
        BOOST_TEST(compare(d, 1.2e3));
        BOOST_TEST(!test_attr("1.2e3", custom_real(-3.2e1), d));
    }
    
    ///////////////////////////////////////////////////////////////////////////
    //  parameterized lazy tests
    ///////////////////////////////////////////////////////////////////////////
    {
        using boost::phoenix::ref;
        using boost::spirit::qi::double_;
        double n = 1.2e3, m = 3.2e1;

        BOOST_TEST(test("1.2e3", double_(ref(n))));
        BOOST_TEST(!test("1.2e3", double_(ref(m))));
    }
   
    ///////////////////////////////////////////////////////////////////////////
    //  literal real number tests
    ///////////////////////////////////////////////////////////////////////////
    {
        using boost::spirit::qi::lit;

        BOOST_TEST(test("+1.2e3", lit(1.2e3)));
        BOOST_TEST(!test("+1.2e3", lit(-1.2e3)));
        BOOST_TEST(test("-1.2e3", lit(-1.2e3)));
        BOOST_TEST(!test("-1.2e3", lit(1.2e3)));
        BOOST_TEST(test("1.2e3", lit(1.2e3)));
        BOOST_TEST(!test("1.2e3", lit(3.2e1)));
    }
    
    ///////////////////////////////////////////////////////////////////////////
    //  literal lazy tests
    ///////////////////////////////////////////////////////////////////////////
    {
        using boost::spirit::qi::lit;
        using boost::phoenix::ref;
        double n = 1.2e3, m = 3.2e1;

        BOOST_TEST(test("1.2e3", lit(ref(n))));
        BOOST_TEST(!test("1.2e3", lit(ref(m))));
    }

    return boost::report_errors();
}