29 #include "gtest/gtest.h"
31 #include "boost/tuple/tuple.hpp"
32 #include "boost/variant/get.hpp"
33 #include "boost/variant/variant.hpp"
42 double value = boost::get<double>(args[0]);
43 if (value < 0.0)
return boost::make_tuple(0.0,
false);
44 return boost::make_tuple(
sqrt(value),
true);
52 double base = boost::get<double>(args[0]);
53 double exponent = boost::get<double>(args[1]);
54 return boost::make_tuple(
pow(base, exponent),
true);
59 class FromFileExpressionTest :
public ::testing::Test {
62 FromFileExpressionTest() {
66 virtual ~FromFileExpressionTest() {
73 virtual void SetUp() {
78 virtual void TearDown() {
85 TEST_F(FromFileExpressionTest, EvaluateFromFileExpression) {
88 double expected = 0.3126 + 0.3561 + 0.4242;
93 funcs.insert(std::pair<std::string, client::function::type>
96 std::string testexpr =
"fromFile(\"resources/fromfile_test.dat\")";
97 const std::unique_ptr<Expression>
e(
new Expression(testexpr, funcs));
100 result =
e->evaluate(vars);
103 ASSERT_NEAR(expected, boost::get<0>(result), 1
e-6);
104 ASSERT_TRUE(boost::get<1>(result));
107 TEST_F(FromFileExpressionTest, EvaluateCombinedFromFileExpression) {
110 double expected =
sqrt(
pow(0.3126 + 0.3561 + 0.4242, 2) +
pow(0.1263 - 0.5613 + 0.2424, 2));
115 funcs.insert(std::pair<std::string, client::function::type>
118 sqrt_func = my_sqrt();
119 funcs.insert(std::pair<std::string, client::function::type>
120 (
"sqrt", sqrt_func));
123 funcs.insert(std::pair<std::string, client::function::type>
126 std::string testexpr =
"sqrt(pow(fromFile(\"resources/fromfile_test.dat\"), 2) + "
127 "pow(fromFile(\"resources/fromfile_test2.dat\"), 2))";
128 const std::unique_ptr<Expression>
e(
new Expression(testexpr, funcs));
131 result =
e->evaluate(vars);
134 ASSERT_NEAR(expected, boost::get<0>(result), 1
e-6);
135 ASSERT_TRUE(boost::get<1>(result));
140 int main(
int argc,
char **argv) {
141 ::testing::InitGoogleTest(&argc, argv);
142 return RUN_ALL_TESTS();
Tps< T > sqrt(const Tps< T > &x)
Square root.
int main(int argc, char *argv[])
boost::function< boost::tuple< double, bool >arguments_t)> type
std::vector< argument_t > arguments_t
std::map< std::string, double > variableDictionary_t
double FromFile(std::string file, const std::vector< double > &referencePoint)
std::map< std::string, client::function::type > functionDictionary_t
constexpr double e
The value of .
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
boost::tuple< double, bool > Result_t