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