Add UT cases for exprtk functions related to nan

Add unit test cases for below exprtk functions:
* maxIgnoreNaN
* sumIgnoreNaN
* ifNan

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I4a9ea4b1f88ad1fd76295f88778a5bfc6b4defd1
diff --git a/meson.build b/meson.build
index ca276f6..8265ab5 100644
--- a/meson.build
+++ b/meson.build
@@ -66,3 +66,8 @@
   configuration: conf_data,
   install: true,
   install_dir: systemd.get_variable('systemdsystemunitdir'))
+
+build_tests = get_option('tests')
+if not build_tests.disabled()
+  subdir('test')
+endif
diff --git a/meson.options b/meson.options
new file mode 100644
index 0000000..0fc2767
--- /dev/null
+++ b/meson.options
@@ -0,0 +1 @@
+option('tests', type: 'feature', description: 'Build tests')
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..5454812
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,18 @@
+gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
+gmock = dependency('gmock', disabler: true, required: build_tests)
+test_inc = include_directories('.')
+src_inc = include_directories('..')
+
+common_dep = [
+  gtest,
+  gmock,
+]
+
+test_exprtk_tools = executable(
+  'test_exprtk_tools',
+  'test_exprtk_tools.cpp',
+  include_directories: [test_inc, src_inc],
+  dependencies: [common_dep, exprtk]
+)
+
+test('test_exprtk_tools', test_exprtk_tools)
diff --git a/test/test_exprtk_tools.cpp b/test/test_exprtk_tools.cpp
new file mode 100644
index 0000000..eb4f72b
--- /dev/null
+++ b/test/test_exprtk_tools.cpp
@@ -0,0 +1,54 @@
+#include "exprtkTools.hpp"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+TEST(TestExprtkTools, max)
+{
+    std::vector<double> v(3, 0.1);
+    FuncMaxIgnoreNaN<double> funcMaxIgnoreNaN;
+    EXPECT_DOUBLE_EQ(funcMaxIgnoreNaN(v), 0.1);
+
+    v[0] = std::numeric_limits<double>::quiet_NaN();
+    EXPECT_DOUBLE_EQ(funcMaxIgnoreNaN(v), 0.1);
+
+    v[1] = std::numeric_limits<double>::quiet_NaN();
+    EXPECT_DOUBLE_EQ(funcMaxIgnoreNaN(v), 0.1);
+
+    v[2] = std::numeric_limits<double>::quiet_NaN();
+    EXPECT_TRUE(std::isnan(funcMaxIgnoreNaN(v)));
+}
+
+TEST(TestExprtkTools, sum)
+{
+    std::vector<double> v(3, 0.1);
+    FuncSumIgnoreNaN<double> funcSumIgnoreNaN;
+    EXPECT_DOUBLE_EQ(funcSumIgnoreNaN(v), 0.3);
+
+    v[0] = std::numeric_limits<double>::quiet_NaN();
+    EXPECT_DOUBLE_EQ(funcSumIgnoreNaN(v), 0.2);
+
+    v[1] = std::numeric_limits<double>::quiet_NaN();
+    EXPECT_DOUBLE_EQ(funcSumIgnoreNaN(v), 0.1);
+
+    v[2] = std::numeric_limits<double>::quiet_NaN();
+    EXPECT_TRUE(std::isnan(funcSumIgnoreNaN(v)));
+}
+
+TEST(TestExprtkTools, ifNan)
+{
+    double a = 1.0;
+    double b = 2.0;
+
+    FuncIfNan<double> funcIfNan;
+    EXPECT_DOUBLE_EQ(funcIfNan(a, b), 1.0);
+
+    a = std::numeric_limits<double>::quiet_NaN();
+    EXPECT_DOUBLE_EQ(funcIfNan(a, b), 2.0);
+
+    b = std::numeric_limits<double>::quiet_NaN();
+    EXPECT_TRUE(std::isnan(funcIfNan(a, b)));
+
+    a = 1.0;
+    EXPECT_DOUBLE_EQ(funcIfNan(a, b), 1.0);
+}