generic_value_test.hxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef GENERIC_VALUE_TEST_HXX
  2. #define GENERIC_VALUE_TEST_HXX
  3. #include "libbinom/include/variables/generic_value.hxx"
  4. #include "test/tester.hxx"
  5. using namespace binom;
  6. void testGenericValue() {
  7. RAIIPerfomanceTest test_perf("Generic value test: ");
  8. SEPARATOR
  9. TEST_ANNOUNCE(GenericValue test)
  10. GRP_PUSH
  11. {
  12. LOG("Types & min max value ranges")
  13. GRP_PUSH
  14. PRINT_RUN(GenericValue _ui8_max = 255_ui8; GenericValue _ui8_min = 0_ui8;)
  15. PRINT_RUN(GenericValue _i8_max = 127_i8; GenericValue _i8_min = i8(-128_i8);)
  16. PRINT_RUN(GenericValue _ui16_max = 65535_ui16; GenericValue _ui16_min = 0_ui16;)
  17. PRINT_RUN(GenericValue _i16_max = 32767_i16; GenericValue _i16_min = i16(-32768_i16);)
  18. PRINT_RUN(GenericValue _ui32_max = 4294967295_ui32; GenericValue _ui32_min = 0_ui32;)
  19. PRINT_RUN(GenericValue _i32_max = 2147483647_i32; GenericValue _i32_min = 2147483648_ni32;)
  20. PRINT_RUN(GenericValue _ui64_max = 18446744073709551615_ui64; GenericValue _ui64_min = 0_ui64;)
  21. PRINT_RUN(GenericValue _i64_max = 9223372036854775807_i64; GenericValue _i64_min = 9223372036854775808_ni64;)
  22. GRP_PUSH
  23. LOG("_ui8_min: " << int(_ui8_min) << " _ui8_max: " << int(_ui8_max))
  24. LOG("_i8_min: " << int(_i8_min) << " _i8_max: " << int(_i8_max))
  25. TEST(_ui8_min.getValType() == _ui8_max.getValType() && _ui8_max.getValType() == ValType::ui8)
  26. TEST(_i8_min.getValType() == _i8_max.getValType() && _i8_max.getValType() == ValType::si8)
  27. GRP_POP
  28. GRP_PUSH
  29. LOG("_ui16_min: " << ui16(_ui16_min) << " _ui16_max: " << ui16(_ui16_max))
  30. LOG("_i16_min: " << i16(_i16_min) << " _i16_max: " << i16(_i16_max))
  31. TEST(_ui16_min.getValType() == _ui16_max.getValType() && _ui16_max.getValType() == ValType::ui16)
  32. TEST(_i16_min.getValType() == _i16_max.getValType() && _i16_max.getValType() == ValType::si16)
  33. GRP_POP
  34. GRP_PUSH
  35. LOG("_ui32_min: " << ui32(_ui32_min) << " _ui32_min: " << ui32(_ui32_max))
  36. LOG("_i32_min: " << i32(_i32_min) << " _i32_min: " << i32(_i32_min))
  37. TEST(_ui32_min.getValType() == _ui32_max.getValType() && _ui32_max.getValType() == ValType::ui32)
  38. TEST(_i32_min.getValType() == _i32_max.getValType() && _i32_max.getValType() == ValType::si32)
  39. GRP_POP
  40. GRP_PUSH
  41. LOG("_ui64_min: " << ui64(_ui64_min) << " _ui64_max: " << ui64(_ui64_max))
  42. LOG("_i64_min: " << i64(_i64_min) << " _i64_max: " << i64(_i64_max))
  43. TEST(_ui64_min.getValType() == _ui64_max.getValType() && _ui64_max.getValType() == ValType::ui64)
  44. TEST(_i64_min.getValType() == _i64_max.getValType() && _i64_max.getValType() == ValType::si64)
  45. GRP_POP
  46. GRP_POP
  47. }
  48. GRP_POP
  49. GRP_PUSH
  50. {
  51. TEST_ANNOUNCE(GenericValue Operators)
  52. PRINT_RUN(GenericValue a = 20_ui64;);
  53. PRINT_RUN(GenericValue b = 40_ui64;);
  54. LOG("a = " << ui64(a))
  55. LOG("b = " << ui64(b))
  56. PRINT_RUN(a += b;)
  57. LOG("a = " << ui64(a))
  58. PRINT_RUN(a -= b;)
  59. LOG("a = " << ui64(a))
  60. PRINT_RUN(a *= b;)
  61. LOG("a = " << ui64(a))
  62. PRINT_RUN(a /= b;)
  63. LOG("a = " << ui64(a))
  64. PRINT_RUN(b %= a;)
  65. LOG("b = " << ui64(b))
  66. PRINT_RUN(b = 12;)
  67. PRINT_RUN(GenericValue c = a + b;)
  68. LOG("c = " << ui64(c))
  69. PRINT_RUN(a.castTo(ValType::f32) = 0.5);
  70. LOG("a = " << f32(a));
  71. LOG("b = " << ui64(b))
  72. PRINT_RUN(a += b;)
  73. LOG("a = " << f32(a))
  74. PRINT_RUN(a -= b;)
  75. LOG("a = " << f32(a))
  76. PRINT_RUN(a *= b;)
  77. LOG("a = " << f32(a))
  78. PRINT_RUN(a /= b;)
  79. LOG("a = " << f32(a))
  80. PRINT_RUN(b %= a;)
  81. LOG("b = " << ui64(b))
  82. PRINT_RUN(b = 12;)
  83. PRINT_RUN(c.castTo(ValType::f64) = a + b;)
  84. LOG("c = " << f64(c))
  85. }
  86. GRP_POP
  87. }
  88. #endif