MCPcopy Create free account
hub / github.com/crownengine/crown / test_expression_language

Function test_expression_language

src/core/unit_tests.cpp:2326–2381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2324}
2325
2326static void test_expression_language()
2327{
2328 namespace el = expression_language;
2329 memory_globals::init();
2330 {
2331 unsigned byte_code[1024];
2332 f32 stack_data[32];
2333 el::Stack stack(stack_data, countof(stack_data));
2334
2335 u32 num = el::compile(""
2336 , 0
2337 , NULL
2338 , 0
2339 , NULL
2340 , NULL
2341 , byte_code
2342 , countof(byte_code)
2343 );
2344 ENSURE(num <= countof(byte_code));
2345
2346 bool ok = el::run(byte_code, NULL, stack);
2347 ENSURE(ok && stack.size == 0);
2348 }
2349 {
2350 auto eval = [](const char *expr) {
2351 unsigned byte_code[1024];
2352 f32 stack_data[32];
2353 const char *variable_names[] = { "a", "b" };
2354 f32 variable_values[] = { 2.0f, 1.5f };
2355 const char *constant_names[] = { "PI" };
2356 f32 constant_values[] = { 3.14159265359f };
2357 el::Stack stack(stack_data, countof(stack_data));
2358
2359 u32 num = el::compile(expr
2360 , countof(variable_names)
2361 , variable_names
2362 , countof(constant_names)
2363 , constant_names
2364 , constant_values
2365 , byte_code
2366 , countof(byte_code)
2367 );
2368 ENSURE(num <= countof(byte_code));
2369
2370 bool ok = el::run(byte_code, variable_values, stack);
2371 ENSURE(ok && stack.size > 0);
2372 return stack_data[stack.size - 1];
2373 };
2374
2375 ENSURE(fequal(eval("1 + 1"), 2.0f, 0.0001f));
2376 ENSURE(fequal(eval("a + b"), 3.5f, 0.0001f));
2377 ENSURE(fequal(eval("3*(sin(PI/2) + 2) - 1"), 8.0f, 0.0001f));
2378 ENSURE(fequal(eval("2*b*(sin(a)/2) + 2) - 1"), 2.36394f, 0.0001f));
2379 }
2380 memory_globals::shutdown();
2381}
2382
2383static void test_unit_id()

Callers

nothing calls this directly

Calls 4

runFunction · 0.85
initFunction · 0.70
shutdownFunction · 0.70
compileFunction · 0.50

Tested by

no test coverage detected