31#include "gtest/gtest.h"
40 double value = std::get<double>(args[0]);
41 if (value < 0.0)
return std::make_tuple(0.0,
false);
42 return std::make_tuple(
sqrt(value),
true);
50 double base = std::get<double>(args[0]);
51 double exponent = std::get<double>(args[1]);
52 return std::make_tuple(
pow(base, exponent),
true);
57 class FromFileExpressionTest :
public ::testing::Test {
60 FromFileExpressionTest() {
64 virtual ~FromFileExpressionTest() {
71 virtual void SetUp() {
76 virtual void TearDown() {
83 TEST_F(FromFileExpressionTest, EvaluateFromFileExpression) {
86 double expected = 0.3126 + 0.3561 + 0.4242;
91 funcs.insert(std::pair<std::string, client::function::type>
94 std::string testexpr =
"fromFile(\"resources/fromfile_test.dat\")";
95 const std::unique_ptr<Expression>
e(
new Expression(testexpr, funcs));
98 result =
e->evaluate(vars);
101 ASSERT_NEAR(expected, std::get<0>(result), 1e-6);
102 ASSERT_TRUE(std::get<1>(result));
105 TEST_F(FromFileExpressionTest, EvaluateCombinedFromFileExpression) {
108 double expected =
sqrt(
pow(0.3126 + 0.3561 + 0.4242, 2) +
pow(0.1263 - 0.5613 + 0.2424, 2));
113 funcs.insert(std::pair<std::string, client::function::type>
116 sqrt_func = my_sqrt();
117 funcs.insert(std::pair<std::string, client::function::type>
118 (
"sqrt", sqrt_func));
121 funcs.insert(std::pair<std::string, client::function::type>
124 std::string testexpr =
"sqrt(pow(fromFile(\"resources/fromfile_test.dat\"), 2) + "
125 "pow(fromFile(\"resources/fromfile_test2.dat\"), 2))";
126 const std::unique_ptr<Expression>
e(
new Expression(testexpr, funcs));
129 result =
e->evaluate(vars);
132 ASSERT_NEAR(expected, std::get<0>(result), 1e-6);
133 ASSERT_TRUE(std::get<1>(result));
138int main(
int argc,
char **argv) {
139 ::testing::InitGoogleTest(&argc, argv);
140 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)
std::tuple< double, bool > Result_t
constexpr double e
The value of.
std::function< std::tuple< double, bool >(arguments_t)> type
std::vector< argument_t > arguments_t
Sampling method that reads design variable values from a text file.