29 #include "gtest/gtest.h"
31 #include "boost/smart_ptr.hpp"
32 #include "boost/tuple/tuple.hpp"
33 #include "boost/variant/get.hpp"
34 #include "boost/variant/variant.hpp"
43 double value = boost::get<double>(args[0]);
44 if (value < 0.0)
return boost::make_tuple(0.0,
false);
45 return boost::make_tuple(
sqrt(value),
true);
53 double base = boost::get<double>(args[0]);
54 double exponent = boost::get<double>(args[1]);
55 return boost::make_tuple(
pow(base, exponent),
true);
60 class FromFileExpressionTest :
public ::testing::Test {
63 FromFileExpressionTest() {
67 virtual ~FromFileExpressionTest() {
74 virtual void SetUp() {
79 virtual void TearDown() {
86 TEST_F(FromFileExpressionTest, EvaluateFromFileExpression) {
89 double expected = 0.3126 + 0.3561 + 0.4242;
94 funcs.insert(std::pair<std::string, client::function::type>
97 std::string testexpr =
"fromFile(\"resources/fromfile_test.dat\")";
98 boost::scoped_ptr<Expression>
e(
new Expression(testexpr, funcs));
101 result =
e->evaluate(vars);
104 ASSERT_NEAR(expected, boost::get<0>(result), 1
e-6);
105 ASSERT_TRUE(boost::get<1>(result));
108 TEST_F(FromFileExpressionTest, EvaluateCombinedFromFileExpression) {
111 double expected =
sqrt(
pow(0.3126 + 0.3561 + 0.4242, 2) +
pow(0.1263 - 0.5613 + 0.2424, 2));
116 funcs.insert(std::pair<std::string, client::function::type>
119 sqrt_func = my_sqrt();
120 funcs.insert(std::pair<std::string, client::function::type>
121 (
"sqrt", sqrt_func));
124 funcs.insert(std::pair<std::string, client::function::type>
127 std::string testexpr =
"sqrt(pow(fromFile(\"resources/fromfile_test.dat\"), 2) + "
128 "pow(fromFile(\"resources/fromfile_test2.dat\"), 2))";
129 boost::scoped_ptr<Expression>
e(
new Expression(testexpr, funcs));
132 result =
e->evaluate(vars);
135 ASSERT_NEAR(expected, boost::get<0>(result), 1
e-6);
136 ASSERT_TRUE(boost::get<1>(result));
141 int main(
int argc,
char **argv) {
142 ::testing::InitGoogleTest(&argc, argv);
143 return RUN_ALL_TESTS();
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sqrt(const Tps< T > &x)
Square root.
std::map< std::string, client::function::type > functionDictionary_t
std::map< std::string, double > variableDictionary_t
int main(int argc, char **argv)
boost::tuple< double, bool > Result_t
constexpr double e
The value of.
boost::function< boost::tuple< double, bool >arguments_t)> type
std::vector< argument_t > arguments_t
double FromFile(std::string file, const std::vector< double > &referencePoint)