stack.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <catch.hpp>
  2. #include <luwra.hpp>
  3. static
  4. int test_function_1(int a, int b) {
  5. return a - b;
  6. }
  7. static
  8. int test_function_2(int a, int b, int c) {
  9. return a + b * c;
  10. }
  11. static
  12. void test_function_3(int) {
  13. }
  14. TEST_CASE("StackInteraction") {
  15. luwra::StateWrapper state;
  16. luwra::push(state, 1);
  17. luwra::push(state, 2);
  18. luwra::push(state, 4);
  19. // Redundant function
  20. luwra::apply(state, test_function_3);
  21. // Absolute index
  22. REQUIRE(luwra::apply(state, test_function_1) == -1);
  23. REQUIRE(luwra::apply(state, 1, test_function_1) == -1);
  24. REQUIRE(luwra::apply(state, [](int a, int b) -> int { return a - b; }) == -1);
  25. REQUIRE(luwra::apply(state, 2, [](int a, int b) -> int { return a + b; }) == 6);
  26. REQUIRE(luwra::apply(state, test_function_2) == 9);
  27. REQUIRE(luwra::apply(state, 1, test_function_2) == 9);
  28. // Relative index
  29. REQUIRE(luwra::apply(state, -2, test_function_1) == -2);
  30. REQUIRE(luwra::apply(state, -3, test_function_1) == -1);
  31. REQUIRE(luwra::apply(state, -3, test_function_2) == 9);
  32. REQUIRE(luwra::apply(state, -3, [](int a, int b, int c) -> int { return a - b + c; }) == 3);
  33. }