1*14ef8742SLei YU #include "exprtkTools.hpp"
2*14ef8742SLei YU
3*14ef8742SLei YU #include <gmock/gmock.h>
4*14ef8742SLei YU #include <gtest/gtest.h>
5*14ef8742SLei YU
TEST(TestExprtkTools,max)6*14ef8742SLei YU TEST(TestExprtkTools, max)
7*14ef8742SLei YU {
8*14ef8742SLei YU std::vector<double> v(3, 0.1);
9*14ef8742SLei YU FuncMaxIgnoreNaN<double> funcMaxIgnoreNaN;
10*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcMaxIgnoreNaN(v), 0.1);
11*14ef8742SLei YU
12*14ef8742SLei YU v[0] = std::numeric_limits<double>::quiet_NaN();
13*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcMaxIgnoreNaN(v), 0.1);
14*14ef8742SLei YU
15*14ef8742SLei YU v[1] = std::numeric_limits<double>::quiet_NaN();
16*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcMaxIgnoreNaN(v), 0.1);
17*14ef8742SLei YU
18*14ef8742SLei YU v[2] = std::numeric_limits<double>::quiet_NaN();
19*14ef8742SLei YU EXPECT_TRUE(std::isnan(funcMaxIgnoreNaN(v)));
20*14ef8742SLei YU }
21*14ef8742SLei YU
TEST(TestExprtkTools,sum)22*14ef8742SLei YU TEST(TestExprtkTools, sum)
23*14ef8742SLei YU {
24*14ef8742SLei YU std::vector<double> v(3, 0.1);
25*14ef8742SLei YU FuncSumIgnoreNaN<double> funcSumIgnoreNaN;
26*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcSumIgnoreNaN(v), 0.3);
27*14ef8742SLei YU
28*14ef8742SLei YU v[0] = std::numeric_limits<double>::quiet_NaN();
29*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcSumIgnoreNaN(v), 0.2);
30*14ef8742SLei YU
31*14ef8742SLei YU v[1] = std::numeric_limits<double>::quiet_NaN();
32*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcSumIgnoreNaN(v), 0.1);
33*14ef8742SLei YU
34*14ef8742SLei YU v[2] = std::numeric_limits<double>::quiet_NaN();
35*14ef8742SLei YU EXPECT_TRUE(std::isnan(funcSumIgnoreNaN(v)));
36*14ef8742SLei YU }
37*14ef8742SLei YU
TEST(TestExprtkTools,ifNan)38*14ef8742SLei YU TEST(TestExprtkTools, ifNan)
39*14ef8742SLei YU {
40*14ef8742SLei YU double a = 1.0;
41*14ef8742SLei YU double b = 2.0;
42*14ef8742SLei YU
43*14ef8742SLei YU FuncIfNan<double> funcIfNan;
44*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcIfNan(a, b), 1.0);
45*14ef8742SLei YU
46*14ef8742SLei YU a = std::numeric_limits<double>::quiet_NaN();
47*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcIfNan(a, b), 2.0);
48*14ef8742SLei YU
49*14ef8742SLei YU b = std::numeric_limits<double>::quiet_NaN();
50*14ef8742SLei YU EXPECT_TRUE(std::isnan(funcIfNan(a, b)));
51*14ef8742SLei YU
52*14ef8742SLei YU a = 1.0;
53*14ef8742SLei YU EXPECT_DOUBLE_EQ(funcIfNan(a, b), 1.0);
54*14ef8742SLei YU }
55