variable_test.hxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef VARIABLE_TEST_HXX
  2. #define VARIABLE_TEST_HXX
  3. #include "tester.hxx"
  4. #include "print_variable.hxx"
  5. using namespace binom;
  6. void testVariable() {
  7. RAIIPerfomanceTest test_perf("Variable test: ");
  8. SEPARATOR
  9. using namespace literals;
  10. TEST_ANNOUNCE(Variable-reference test); GRP_PUSH;
  11. {
  12. PRINT_RUN(Variable a = 256_ui64);
  13. LOG("NOTE: Number b = a.move()");
  14. LOG("move() -> rvalue-ref");
  15. LOG("operator T&() -> lvalue-ref");
  16. LOG("Number(const Number&) *MAKES COPY*")
  17. PRINT_RUN(Number b = a.toNumber().move());
  18. PRINT_RUN(Variable c = a.move());
  19. TEST(ui64(a.toNumber()) == 256);
  20. TEST(ui64(b) == 256);
  21. PRINT_RUN(b = 512;)
  22. TEST(ui64(a.toNumber()) == 512);
  23. TEST(ui64(b) == 512);
  24. } GRP_POP;
  25. TEST_ANNOUNCE(Variable-reference in array test); GRP_PUSH;
  26. {
  27. LOG("(bug in [r]): Variable array = arr{ true, false, i8(-8), 8_ui8, i16(-16), 16_ui16, i32(-32), 32_ui32, .32_f32, i64(-64), 64_ui64, .64_f64};")
  28. Variable array = arr{ true, false, i8(-8), 8_ui8, i16(-16), 16_ui16, i32(-32), 32_ui32, .32_f32, i64(-64), 64_ui64, .64_f64};
  29. LOG("(bug in [r]): array.toArray() += arr{false, true, array.move()};")
  30. array.toArray() += arr{false, true, array.move()};
  31. #ifdef FULL_TEST
  32. PRINT_RUN(utils::printVariable(array));
  33. #endif
  34. LOG("FIXME:")
  35. LOG("If you don't delete the variable-reference to the parent element,")
  36. LOG("then the memory from under the resource will not be freed!")
  37. PRINT_RUN(array.toArray().popBack());
  38. } GRP_POP;
  39. TEST_ANNOUNCE(List test); GRP_PUSH;
  40. {
  41. LOG("(bug in [r]): Variable list_var = list{true, false, i8(-8), 8_ui8, i16(-16), 16_ui16, i32(-32), 32_ui32, .32_f32, i64(-64), 64_ui64, .64_f64};")
  42. Variable list_var = list{true, false, i8(-8), 8_ui8, i16(-16), 16_ui16, i32(-32), 32_ui32, .32_f32, i64(-64), 64_ui64, .64_f64};
  43. PRINT_RUN(List _list = list_var.toList().move());
  44. PRINT_RUN(utils::printVariable(_list));
  45. LOG("Iteration in order")
  46. for(const auto& element : _list) {
  47. utils::printVariable(element);
  48. }
  49. LOG("Reverse iteration")
  50. for(const auto& element : reverse_iterator::ReverseRange(_list)) {
  51. utils::printVariable(element);
  52. }
  53. } GRP_POP
  54. }
  55. #endif // VARIABLE_TEST_HXX