19{
22
24 EBTerm z(
"z"), u(
"u"),
v(
"v"), w(
"w");
25
26 EBTerm
a(1),
b(4),
c(8.9);
27
29
31
32
33 {
35 H((
x)) = -
G((
x, b)) +
c %
b;
36
37 EXPECT_EQ(std::string(H), "-(x^2+4^1+3*4*-1)+8.9%4");
38 EXPECT_EQ(
G.args(),
"x,y");
39 }
40
41
42
43 {
45 H((
x,
y, z)) =
x *
y * z;
46 EXPECT_EQ(std::string(G), "x^y");
47 EXPECT_EQ(std::string(
G((
y,
x))),
"y^x");
48 EXPECT_EQ(std::string(
H((z,
y,
x))),
"z*y*x");
49 }
50
51
52 {
53 G(
x,
y, z) =
x *
y * z;
54 H(u,
v, w,
x,
y, z) = u +
v + w +
x +
y + z;
55
56 EXPECT_EQ(std::string(
G(
a, b,
c)),
"1*4*8.9");
57 EXPECT_EQ(std::string(
H(
a, b,
c,
a, b,
c)),
"1+4+8.9+1+4+8.9");
58 EXPECT_EQ(std::string(
G(
a, b,
c) +
H(
a, b,
c,
a, b,
c)),
"1*4*8.9+1+4+8.9+1+4+8.9");
59
60 H(u,
v, w,
x,
y, z) = u +
v + w +
G(
y,
x,
x);
61 EXPECT_EQ(std::string(
H(
a, b,
c,
x,
y, z)),
"1+4+8.9+y*x*x");
62 }
63
64
65 {
66 EBTerm def =
x -
y - z;
67 EBTerm left = (
x -
y) - z;
68 EBTerm right =
x - (
y - z);
69
70 EXPECT_EQ(std::string(def), "x-y-z");
71 EXPECT_EQ(std::string(left), "x-y-z");
72 EXPECT_EQ(std::string(right), "x-(y-z)");
73 }
74
75
76 {
77 EBTerm comp1 = (
x <
y) + (
x >
y);
78 EBTerm comp2 = (
x <=
y) + (
x >=
y);
79 EBTerm comp3 = (
x ==
y) + (
x !=
y);
80
81 EXPECT_EQ(std::string(comp1), "(x<y)+(x>y)");
82 EXPECT_EQ(std::string(comp2), "(x<=y)+(x>=y)");
83 EXPECT_EQ(std::string(comp3), "(x=y)+(x!=y)");
84 }
85
86
87 {
88 EBTerm comp4 = atan2(
x,
y);
89 EXPECT_EQ(std::string(comp4), "atan2(x,y)");
90 }
91
92
93 {
95 EXPECT_EQ(std::string(if1),
96 "if"
97 "(x<2*y,x*x+y,y*y+x)");
98 }
99
100
101 {
102 EBTerm temp1;
103 EBTerm temp2;
104 EXPECT_NE(std::string(temp1), std::string(temp2));
105 }
106
107
108 {
109
110 EBTerm u =
log(
x /
a);
111 u.substitute(EBLogPlogSubstitution(b));
112 EXPECT_EQ(std::string(u), "plog(x/1,4)");
113
114
116 v.substitute(EBTermSubstitution(
x,
a));
117 EXPECT_EQ(std::string(
v),
118 "if"
119 "(1<y,1*y,1/y)");
120
121
123 EBSubstitutionRuleList s(2);
124 EBTermSubstitution s0(
x,
y), s1(
y,
a);
125 s[0] = &s0;
126 s[1] = &s1;
127 w.substitute(s);
128 EXPECT_EQ(std::string(w),
129 "if"
130 "(y<1,y*1,y/1)");
131 }
132}
Real f(Real x)
Test function for Brents method.
const std::vector< double > y
const std::vector< double > x
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
auto conditional(const C &, const L &, const R &)