MCPcopy Create free account
hub / github.com/ArashPartow/exprtk / run_test04

Function run_test04

exprtk_test.cpp:3266–3320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3264
3265template <typename T>
3266bool run_test04()
3267{
3268 const std::string expression_string = "clamp(-1.0,sin(2 * pi * x) + cos(y / 2 * pi),+1.0)";
3269
3270 exprtk::symbol_table<T> symbol_table;
3271 exprtk::expression<T> expression;
3272
3273 T x = T(-1000);
3274 T y = T(-1000);
3275
3276 symbol_table.add_variable("x",x);
3277 symbol_table.add_variable("y",y);
3278 symbol_table.add_constants();
3279
3280 expression.register_symbol_table(symbol_table);
3281
3282 {
3283 exprtk::parser<T> parser;
3284
3285 if (!parser.compile(expression_string,expression))
3286 {
3287 printf("run_test04() - Error: %s Expression: %s\n",
3288 parser.error().c_str(),
3289 expression_string.c_str());
3290
3291 return false;
3292 }
3293 }
3294
3295 const T pi = T(3.141592653589793238462643383279502);
3296 const T increment = T(0.0001);
3297
3298 while ((x <= T(+1000)) && (y <= T(+1000)))
3299 {
3300 T result1 = expression.value();
3301 T result2 = clamp<T>(-1.0,std::sin(2 * pi * x) + std::cos(y / 2 * pi),+1.0);
3302
3303 if (not_equal(result1,result2))
3304 {
3305 printf("run_test04() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f x:%19.15f\ty:%19.15f\n",
3306 expression_string.c_str(),
3307 static_cast<double>(result1),
3308 static_cast<double>(result2),
3309 static_cast<double>(x),
3310 static_cast<double>(y));
3311
3312 return false;
3313 }
3314
3315 x += increment;
3316 y += increment;
3317 }
3318
3319 return true;
3320}
3321
3322template <typename T>
3323bool run_test05()

Callers

nothing calls this directly

Calls 2

not_equalFunction · 0.85
valueMethod · 0.45

Tested by

no test coverage detected