test_abs.odin 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package test_internal
  2. import "core:testing"
  3. @(private="file")
  4. not_const :: proc(v: $T) -> T { return v }
  5. @(test)
  6. abs_f16_const :: proc(t: ^testing.T) {
  7. // Constant f16
  8. testing.expect_value(t, abs(f16(0.)), 0.)
  9. testing.expect_value(t, abs(f16(-0.)), 0.)
  10. testing.expect_value(t, abs(f16(-1.)), 1.)
  11. testing.expect_value(t, abs(min(f16)), max(f16))
  12. testing.expect_value(t, abs(max(f16)), max(f16))
  13. testing.expect_value(t, abs(f16(-.12)), .12)
  14. // Constant f16le
  15. testing.expect_value(t, abs(f16le(0.)), 0.)
  16. testing.expect_value(t, abs(f16le(-0.)), 0.)
  17. testing.expect_value(t, abs(f16le(-1.)), 1.)
  18. testing.expect_value(t, abs(min(f16le)), max(f16le))
  19. testing.expect_value(t, abs(max(f16le)), max(f16le))
  20. testing.expect_value(t, abs(f16le(-.12)), .12)
  21. // Constant f16be
  22. testing.expect_value(t, abs(f16be(0.)), 0.)
  23. testing.expect_value(t, abs(f16be(-0.)), 0.)
  24. testing.expect_value(t, abs(f16be(-1.)), 1.)
  25. testing.expect_value(t, abs(min(f16be)), max(f16be))
  26. testing.expect_value(t, abs(max(f16be)), max(f16be))
  27. testing.expect_value(t, abs(f16be(-.12)), .12)
  28. }
  29. @(test)
  30. abs_f16_variable :: proc(t: ^testing.T) {
  31. // Variable f16
  32. testing.expect_value(t, abs(not_const(f16(0.))), 0.)
  33. testing.expect_value(t, abs(not_const(f16(-0.))), 0.)
  34. testing.expect_value(t, abs(not_const(f16(-1.))), 1.)
  35. testing.expect_value(t, abs(not_const(min(f16))), max(f16))
  36. testing.expect_value(t, abs(not_const(max(f16))), max(f16))
  37. testing.expect_value(t, abs(not_const(f16(-.12))), .12)
  38. // Variable f16le
  39. testing.expect_value(t, abs(not_const(f16le(0.))), 0.)
  40. testing.expect_value(t, abs(not_const(f16le(-0.))), 0.)
  41. testing.expect_value(t, abs(not_const(f16le(-1.))), 1.)
  42. testing.expect_value(t, abs(not_const(min(f16le))), max(f16le))
  43. testing.expect_value(t, abs(not_const(max(f16le))), max(f16le))
  44. testing.expect_value(t, abs(not_const(f16le(-.12))), .12)
  45. // Variable f16be
  46. testing.expect_value(t, abs(not_const(f16be(0.))), 0.)
  47. testing.expect_value(t, abs(not_const(f16be(-0.))), 0.)
  48. testing.expect_value(t, abs(not_const(f16be(-1.))), 1.)
  49. testing.expect_value(t, abs(not_const(min(f16be))), max(f16be))
  50. testing.expect_value(t, abs(not_const(max(f16be))), max(f16be))
  51. testing.expect_value(t, abs(not_const(f16be(-.12))), .12)
  52. }
  53. @(test)
  54. abs_f32_const :: proc(t: ^testing.T) {
  55. // Constant f32
  56. testing.expect_value(t, abs(f32(0.)), 0.)
  57. testing.expect_value(t, abs(f32(-0.)), 0.)
  58. testing.expect_value(t, abs(f32(-1.)), 1.)
  59. testing.expect_value(t, abs(min(f32)), max(f32))
  60. testing.expect_value(t, abs(max(f32)), max(f32))
  61. testing.expect_value(t, abs(f32(-.12345)), .12345)
  62. // Constant f32le
  63. testing.expect_value(t, abs(f32le(0.)), 0.)
  64. testing.expect_value(t, abs(f32le(-0.)), 0.)
  65. testing.expect_value(t, abs(f32le(-1.)), 1.)
  66. testing.expect_value(t, abs(min(f32le)), max(f32le))
  67. testing.expect_value(t, abs(max(f32le)), max(f32le))
  68. testing.expect_value(t, abs(f32le(-.12345)), .12345)
  69. // Constant f32be
  70. testing.expect_value(t, abs(f32be(0.)), 0.)
  71. testing.expect_value(t, abs(f32be(-0.)), 0.)
  72. testing.expect_value(t, abs(f32be(-1.)), 1.)
  73. testing.expect_value(t, abs(min(f32be)), max(f32be))
  74. testing.expect_value(t, abs(max(f32be)), max(f32be))
  75. testing.expect_value(t, abs(f32be(-.12345)), .12345)
  76. }
  77. @(test)
  78. abs_f32_variable :: proc(t: ^testing.T) {
  79. // Variable f32
  80. testing.expect_value(t, abs(not_const(f32(0.))), 0.)
  81. testing.expect_value(t, abs(not_const(f32(-0.))), 0.)
  82. testing.expect_value(t, abs(not_const(f32(-1.))), 1.)
  83. testing.expect_value(t, abs(not_const(min(f32))), max(f32))
  84. testing.expect_value(t, abs(not_const(max(f32))), max(f32))
  85. testing.expect_value(t, abs(not_const(f32(-.12345))), .12345)
  86. // Variable f32le
  87. testing.expect_value(t, abs(not_const(f32le(0.))), 0.)
  88. testing.expect_value(t, abs(not_const(f32le(-0.))), 0.)
  89. testing.expect_value(t, abs(not_const(f32le(-1.))), 1.)
  90. testing.expect_value(t, abs(not_const(min(f32le))), max(f32le))
  91. testing.expect_value(t, abs(not_const(max(f32le))), max(f32le))
  92. testing.expect_value(t, abs(not_const(f32le(-.12345))), .12345)
  93. // Variable f32be
  94. testing.expect_value(t, abs(not_const(f32be(0.))), 0.)
  95. testing.expect_value(t, abs(not_const(f32be(-0.))), 0.)
  96. testing.expect_value(t, abs(not_const(f32be(-1.))), 1.)
  97. testing.expect_value(t, abs(not_const(min(f32be))), max(f32be))
  98. testing.expect_value(t, abs(not_const(max(f32be))), max(f32be))
  99. testing.expect_value(t, abs(not_const(f32be(-.12345))), .12345)
  100. }
  101. @(test)
  102. abs_f64_const :: proc(t: ^testing.T) {
  103. // Constant f64
  104. testing.expect_value(t, abs(f64(0.)), 0.)
  105. testing.expect_value(t, abs(f64(-0.)), 0.)
  106. testing.expect_value(t, abs(f64(-1.)), 1.)
  107. testing.expect_value(t, abs(min(f64)), max(f64))
  108. testing.expect_value(t, abs(max(f64)), max(f64))
  109. testing.expect_value(t, abs(f64(-.12345)), .12345)
  110. // Constant f64le
  111. testing.expect_value(t, abs(f64le(0.)), 0.)
  112. testing.expect_value(t, abs(f64le(-0.)), 0.)
  113. testing.expect_value(t, abs(f64le(-1.)), 1.)
  114. testing.expect_value(t, abs(min(f64le)), max(f64le))
  115. testing.expect_value(t, abs(max(f64le)), max(f64le))
  116. testing.expect_value(t, abs(f64le(-.12345)), .12345)
  117. // Constant f64be
  118. testing.expect_value(t, abs(f64be(0.)), 0.)
  119. testing.expect_value(t, abs(f64be(-0.)), 0.)
  120. testing.expect_value(t, abs(f64be(-1.)), 1.)
  121. testing.expect_value(t, abs(min(f64be)), max(f64be))
  122. testing.expect_value(t, abs(max(f64be)), max(f64be))
  123. testing.expect_value(t, abs(f64be(-.12345)), .12345)
  124. }
  125. @(test)
  126. abs_f64_variable :: proc(t: ^testing.T) {
  127. // Variable f64
  128. testing.expect_value(t, abs(not_const(f64(0.))), 0.)
  129. testing.expect_value(t, abs(not_const(f64(-0.))), 0.)
  130. testing.expect_value(t, abs(not_const(f64(-1.))), 1.)
  131. testing.expect_value(t, abs(not_const(min(f64))), max(f64))
  132. testing.expect_value(t, abs(not_const(max(f64))), max(f64))
  133. testing.expect_value(t, abs(not_const(f64(-.12345))), .12345)
  134. // Variable f64le
  135. testing.expect_value(t, abs(not_const(f64le(0.))), 0.)
  136. testing.expect_value(t, abs(not_const(f64le(-0.))), 0.)
  137. testing.expect_value(t, abs(not_const(f64le(-1.))), 1.)
  138. testing.expect_value(t, abs(not_const(min(f64le))), max(f64le))
  139. testing.expect_value(t, abs(not_const(max(f64le))), max(f64le))
  140. testing.expect_value(t, abs(not_const(f64le(-.12345))), .12345)
  141. // Variable f64be
  142. testing.expect_value(t, abs(not_const(f64be(0.))), 0.)
  143. testing.expect_value(t, abs(not_const(f64be(-0.))), 0.)
  144. testing.expect_value(t, abs(not_const(f64be(-1.))), 1.)
  145. testing.expect_value(t, abs(not_const(min(f64be))), max(f64be))
  146. testing.expect_value(t, abs(not_const(max(f64be))), max(f64be))
  147. testing.expect_value(t, abs(not_const(f64be(-.12345))), .12345)
  148. }