1 // Copyright (C) 2016-2018 T. Zachary Laine
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/yap/expression.hpp>
7
8 #include <boost/test/minimal.hpp>
9
10
11 template<typename T>
12 using term = boost::yap::terminal<boost::yap::expression, T>;
13
14 template<typename T>
15 using ref = boost::yap::expression_ref<boost::yap::expression, T>;
16
17 namespace yap = boost::yap;
18 namespace bh = boost::hana;
19
20
test_main(int,char * [])21 int test_main(int, char * [])
22 {
23 {
24 term<double> unity{1.0};
25 int i_ = 42;
26 term<int &&> i{std::move(i_)};
27 yap::expression<
28 yap::expr_kind::minus,
29 bh::tuple<ref<term<double> &>, term<int &&>>>
30 expr = unity - std::move(i);
31 yap::expression<
32 yap::expr_kind::plus,
33 bh::tuple<
34 ref<term<double> &>,
35 yap::expression<
36 yap::expr_kind::minus,
37 bh::tuple<ref<term<double> &>, term<int &&>>>>>
38 unevaluated_expr_1 = unity + std::move(expr);
39
40 yap::expression<
41 yap::expr_kind::plus,
42 bh::tuple<ref<term<double> &>, ref<term<double> &>>>
43 unevaluated_expr_2 = unity + unity;
44
45 term<double> const const_unity{1.0};
46 yap::expression<
47 yap::expr_kind::plus,
48 bh::tuple<ref<term<double> &>, ref<term<double> const &>>>
49 unevaluated_expr_3 = unity + const_unity;
50
51 {
52 double result = evaluate(unity);
53 BOOST_CHECK(result == 1);
54 }
55
56 {
57 double result = evaluate(expr);
58 BOOST_CHECK(result == -41);
59 }
60
61 {
62 double result = evaluate(unevaluated_expr_1);
63 BOOST_CHECK(result == -40);
64 }
65
66 {
67 double result = evaluate(unevaluated_expr_2);
68 BOOST_CHECK(result == 2);
69 }
70
71 {
72 double result = evaluate(unevaluated_expr_3);
73 BOOST_CHECK(result == 2);
74 }
75
76 {
77 double result = evaluate(unity, 5, 6, 7);
78 BOOST_CHECK(result == 1);
79 }
80
81 {
82 double result = evaluate(expr);
83 BOOST_CHECK(result == -41);
84 }
85
86 {
87 double result = evaluate(unevaluated_expr_1, std::string("15"));
88 BOOST_CHECK(result == -40);
89 }
90
91 {
92 double result = evaluate(unevaluated_expr_2, std::string("15"));
93 BOOST_CHECK(result == 2);
94 }
95
96 {
97 double result = evaluate(unevaluated_expr_3, std::string("15"));
98 BOOST_CHECK(result == 2);
99 }
100 }
101
102 return 0;
103 }
104