29 #include <gtest/gtest.h> 33 TEST(FormulaCalcTest, testFormulaCalculation)
37 for (i = 0; i < 5; i++)
49 ASSERT_EQ(
formula(
"1+1", &rpf, variable), 1);
58 ASSERT_EQ(
formula(
"abc+1", &rpf, variable), 0);
60 ASSERT_EQ(
formula(
"1+2+3+4/8+2*3", &rpf, variable), 1);
69 ASSERT_EQ(
formula(
"cos(3.1416)+1", &rpf, variable), 1);
71 EXPECT_LT(fabs(ret), 1e-3);
74 EXPECT_LT(fabs(ret), 1e-3);
78 ASSERT_EQ(
formula(
"(TEST+1)*2-1", &rpf, variable), 1);
80 for (test = 0; test < 4; test++)
83 EXPECT_EQ(ret, (test + 1) * 2.0 - 1.0);
88 for (test = 0; test < 4; test++)
91 EXPECT_EQ(ret, (test + 1) * 2.0 - 1.0);
96 ASSERT_EQ(
formula(
"(TEST=5)*0.1+10.0", &rpf, variable), 1);
98 EXPECT_NEAR(ret, 10.5, 1e-6);
99 EXPECT_NEAR(test, 5.0, 1e-6);
102 ASSERT_EQ(
formula(
"TEST=(10.0+5*0.1)", &rpf, variable), 1);
104 EXPECT_NEAR(ret, 10.5, 1e-6);
105 EXPECT_NEAR(test, 10.5, 1e-6);
110 int main(
int argc,
char **argv)
112 testing::InitGoogleTest(&argc, argv);
114 return RUN_ALL_TESTS();