types_test.hxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef TYPES_TEST_HXX
  2. #define TYPES_TEST_HXX
  3. #include "libbinom/include/binom_impl/types.hxx"
  4. #include "test/tester.hxx"
  5. using namespace binom;
  6. void testTypesConversions() {
  7. RAIIPerfomanceTest test_perf("Type conversion test: ");
  8. SEPARATOR
  9. TEST_ANNOUNCE(Test types conversions)
  10. GRP(
  11. LOG("Variable type to variable type class")
  12. GRP(
  13. TEST(toTypeClass(VarType::null) == VarTypeClass::null)
  14. TEST(toTypeClass(VarType::boolean) == VarTypeClass::number)
  15. TEST(toTypeClass(VarType::ui8) == VarTypeClass::number)
  16. TEST(toTypeClass(VarType::si8) == VarTypeClass::number)
  17. TEST(toTypeClass(VarType::ui16) == VarTypeClass::number)
  18. TEST(toTypeClass(VarType::si16) == VarTypeClass::number)
  19. TEST(toTypeClass(VarType::ui32) == VarTypeClass::number)
  20. TEST(toTypeClass(VarType::si32) == VarTypeClass::number)
  21. TEST(toTypeClass(VarType::f32) == VarTypeClass::number)
  22. TEST(toTypeClass(VarType::ui64) == VarTypeClass::number)
  23. TEST(toTypeClass(VarType::si64) == VarTypeClass::number)
  24. TEST(toTypeClass(VarType::f64) == VarTypeClass::number)
  25. TEST(toTypeClass(VarType::ui8_array) == VarTypeClass::buffer_array)
  26. TEST(toTypeClass(VarType::si8_array) == VarTypeClass::buffer_array)
  27. TEST(toTypeClass(VarType::ui16_array) == VarTypeClass::buffer_array)
  28. TEST(toTypeClass(VarType::si16_array) == VarTypeClass::buffer_array)
  29. TEST(toTypeClass(VarType::ui32_array) == VarTypeClass::buffer_array)
  30. TEST(toTypeClass(VarType::si32_array) == VarTypeClass::buffer_array)
  31. TEST(toTypeClass(VarType::f32_array) == VarTypeClass::buffer_array)
  32. TEST(toTypeClass(VarType::ui64_array) == VarTypeClass::buffer_array)
  33. TEST(toTypeClass(VarType::si64_array) == VarTypeClass::buffer_array)
  34. TEST(toTypeClass(VarType::f64_array) == VarTypeClass::buffer_array)
  35. TEST(toTypeClass(VarType::array) == VarTypeClass::array)
  36. TEST(toTypeClass(VarType::map) == VarTypeClass::map)
  37. TEST(toTypeClass(VarType::separator) == VarTypeClass::invalid_type)
  38. TEST(toTypeClass(VarType::invalid_type) == VarTypeClass::invalid_type)
  39. )
  40. LOG("Variable type bit width")
  41. GRP(
  42. TEST(toBitWidth(VarType::boolean) == VarBitWidth::byte)
  43. TEST(toBitWidth(VarType::ui8) == VarBitWidth::byte)
  44. TEST(toBitWidth(VarType::si8) == VarBitWidth::byte)
  45. TEST(toBitWidth(VarType::ui8_array) == VarBitWidth::byte)
  46. TEST(toBitWidth(VarType::si8_array) == VarBitWidth::byte)
  47. TEST(toBitWidth(VarType::ui16) == VarBitWidth::word)
  48. TEST(toBitWidth(VarType::si16) == VarBitWidth::word)
  49. TEST(toBitWidth(VarType::ui16_array) == VarBitWidth::word)
  50. TEST(toBitWidth(VarType::si16_array) == VarBitWidth::word)
  51. TEST(toBitWidth(VarType::ui32) == VarBitWidth::dword)
  52. TEST(toBitWidth(VarType::si32) == VarBitWidth::dword)
  53. TEST(toBitWidth(VarType::f32) == VarBitWidth::dword)
  54. TEST(toBitWidth(VarType::ui32_array) == VarBitWidth::dword)
  55. TEST(toBitWidth(VarType::si32_array) == VarBitWidth::dword)
  56. TEST(toBitWidth(VarType::f32_array) == VarBitWidth::dword)
  57. TEST(toBitWidth(VarType::ui64) == VarBitWidth::qword)
  58. TEST(toBitWidth(VarType::si64) == VarBitWidth::qword)
  59. TEST(toBitWidth(VarType::f64) == VarBitWidth::qword)
  60. TEST(toBitWidth(VarType::ui64_array) == VarBitWidth::qword)
  61. TEST(toBitWidth(VarType::si64_array) == VarBitWidth::qword)
  62. TEST(toBitWidth(VarType::f64_array) == VarBitWidth::qword)
  63. )
  64. LOG("Value type bit width")
  65. GRP(
  66. TEST(toBitWidth(ValType::boolean) == VarBitWidth::byte)
  67. TEST(toBitWidth(ValType::ui8) == VarBitWidth::byte)
  68. TEST(toBitWidth(ValType::si8) == VarBitWidth::byte)
  69. TEST(toBitWidth(ValType::ui16) == VarBitWidth::word)
  70. TEST(toBitWidth(ValType::si16) == VarBitWidth::word)
  71. TEST(toBitWidth(ValType::ui32) == VarBitWidth::dword)
  72. TEST(toBitWidth(ValType::si32) == VarBitWidth::dword)
  73. TEST(toBitWidth(ValType::f32) == VarBitWidth::dword)
  74. TEST(toBitWidth(ValType::ui64) == VarBitWidth::qword)
  75. TEST(toBitWidth(ValType::si64) == VarBitWidth::qword)
  76. TEST(toBitWidth(ValType::f64) == VarBitWidth::qword)
  77. )
  78. LOG("Variable type to number type")
  79. GRP(
  80. TEST(toNumberType(VarType::boolean) == VarNumberType::unsigned_integer)
  81. TEST(toNumberType(VarType::ui8) == VarNumberType::unsigned_integer)
  82. TEST(toNumberType(VarType::si8) == VarNumberType::signed_integer)
  83. TEST(toNumberType(VarType::ui8_array) == VarNumberType::unsigned_integer)
  84. TEST(toNumberType(VarType::si8_array) == VarNumberType::signed_integer)
  85. TEST(toNumberType(VarType::ui16) == VarNumberType::unsigned_integer)
  86. TEST(toNumberType(VarType::si16) == VarNumberType::signed_integer)
  87. TEST(toNumberType(VarType::ui16_array) == VarNumberType::unsigned_integer)
  88. TEST(toNumberType(VarType::si16_array) == VarNumberType::signed_integer)
  89. TEST(toNumberType(VarType::ui32) == VarNumberType::unsigned_integer)
  90. TEST(toNumberType(VarType::si32) == VarNumberType::signed_integer)
  91. TEST(toNumberType(VarType::f32) == VarNumberType::float_point)
  92. TEST(toNumberType(VarType::ui32_array) == VarNumberType::unsigned_integer)
  93. TEST(toNumberType(VarType::si32_array) == VarNumberType::signed_integer)
  94. TEST(toNumberType(VarType::f32_array) == VarNumberType::float_point)
  95. TEST(toNumberType(VarType::ui64) == VarNumberType::unsigned_integer)
  96. TEST(toNumberType(VarType::si64) == VarNumberType::signed_integer)
  97. TEST(toNumberType(VarType::f64) == VarNumberType::float_point)
  98. TEST(toNumberType(VarType::ui64_array) == VarNumberType::unsigned_integer)
  99. TEST(toNumberType(VarType::si64_array) == VarNumberType::signed_integer)
  100. TEST(toNumberType(VarType::f64_array) == VarNumberType::float_point)
  101. )
  102. LOG("Value type to number type")
  103. GRP(
  104. TEST(toNumberType(ValType::boolean) == VarNumberType::unsigned_integer)
  105. TEST(toNumberType(ValType::ui8) == VarNumberType::unsigned_integer)
  106. TEST(toNumberType(ValType::si8) == VarNumberType::signed_integer)
  107. TEST(toNumberType(ValType::ui16) == VarNumberType::unsigned_integer)
  108. TEST(toNumberType(ValType::si16) == VarNumberType::signed_integer)
  109. TEST(toNumberType(ValType::ui32) == VarNumberType::unsigned_integer)
  110. TEST(toNumberType(ValType::si32) == VarNumberType::signed_integer)
  111. TEST(toNumberType(ValType::f32) == VarNumberType::float_point)
  112. TEST(toNumberType(ValType::ui64) == VarNumberType::unsigned_integer)
  113. TEST(toNumberType(ValType::si64) == VarNumberType::signed_integer)
  114. TEST(toNumberType(ValType::f64) == VarNumberType::float_point)
  115. )
  116. )
  117. }
  118. #endif // TYPES_TEST_HXX