]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2015 Joel de Guzman | |
3 | Copyright (c) 2001-2011 Hartmut Kaiser | |
4 | Copyright (c) 2011 Bryce Lelbach | |
5 | ||
6 | Use, modification and distribution is subject to the Boost Software | |
7 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
8 | http://www.boost.org/LICENSE_1_0.txt) | |
9 | =============================================================================*/ | |
10 | ||
11 | #include "real.hpp" | |
12 | ||
1e59de90 TL |
13 | #include <boost/math/concepts/real_concept.hpp> |
14 | ||
7c673cae FG |
15 | int |
16 | main() | |
17 | { | |
18 | using spirit_test::test; | |
19 | using spirit_test::test_attr; | |
20 | ||
21 | /////////////////////////////////////////////////////////////////////////// | |
22 | // Custom data type | |
23 | /////////////////////////////////////////////////////////////////////////// | |
24 | { | |
25 | using boost::math::concepts::real_concept; | |
26 | using boost::spirit::x3::real_parser; | |
27 | using boost::spirit::x3::real_policies; | |
28 | using boost::spirit::x3::parse; | |
29 | ||
f67539c2 | 30 | constexpr real_parser<real_concept, real_policies<real_concept> > custom_real; |
7c673cae FG |
31 | real_concept d; |
32 | ||
f67539c2 TL |
33 | BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(custom_real); |
34 | ||
7c673cae FG |
35 | BOOST_TEST(test("-1234", custom_real)); |
36 | BOOST_TEST(test_attr("-1234", custom_real, d) && compare(d, -1234)); | |
37 | ||
38 | BOOST_TEST(test("-1.2e3", custom_real)); | |
39 | BOOST_TEST(test_attr("-1.2e3", custom_real, d) && compare(d, -1.2e3)); | |
40 | ||
41 | BOOST_TEST(test("+1.2e3", custom_real)); | |
42 | BOOST_TEST(test_attr("+1.2e3", custom_real, d) && compare(d, 1.2e3)); | |
43 | ||
44 | BOOST_TEST(test("-0.1", custom_real)); | |
45 | BOOST_TEST(test_attr("-0.1", custom_real, d) && compare(d, -0.1)); | |
46 | ||
47 | BOOST_TEST(test("-1.2e-3", custom_real)); | |
48 | BOOST_TEST(test_attr("-1.2e-3", custom_real, d) && compare(d, -1.2e-3)); | |
49 | ||
50 | BOOST_TEST(test("-1.e2", custom_real)); | |
51 | BOOST_TEST(test_attr("-1.e2", custom_real, d) && compare(d, -1.e2)); | |
52 | ||
53 | BOOST_TEST(test("-.2e3", custom_real)); | |
54 | BOOST_TEST(test_attr("-.2e3", custom_real, d) && compare(d, -.2e3)); | |
55 | ||
56 | BOOST_TEST(test("-2e3", custom_real)); | |
57 | BOOST_TEST(test_attr("-2e3", custom_real, d) && compare(d, -2e3)); | |
58 | ||
59 | BOOST_TEST(!test("-e3", custom_real)); | |
60 | BOOST_TEST(!test_attr("-e3", custom_real, d)); | |
61 | ||
62 | BOOST_TEST(!test("-1.2e", custom_real)); | |
63 | BOOST_TEST(!test_attr("-1.2e", custom_real, d)); | |
64 | } | |
65 | ||
66 | /////////////////////////////////////////////////////////////////////////// | |
67 | // custom real tests | |
68 | /////////////////////////////////////////////////////////////////////////// | |
69 | { | |
70 | using boost::spirit::x3::double_; | |
71 | custom_real n; | |
72 | ||
73 | BOOST_TEST(test_attr("-123456e6", double_, n)); | |
74 | } | |
75 | ||
76 | return boost::report_errors(); | |
77 | } |