111 rivejä
3.3 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. #include "lol/unit.h"
  15. namespace lol
  16. {
  17. LOLUNIT_FIXTURE(BuildTest)
  18. {
  19. LOLUNIT_TEST(TypeSize)
  20. {
  21. LOLUNIT_ASSERT_EQUAL(sizeof(half), 2);
  22. //LOLUNIT_ASSERT_EQUAL(sizeof(f16vec2), 4);
  23. //LOLUNIT_ASSERT_EQUAL(sizeof(f16vec3), 6);
  24. //LOLUNIT_ASSERT_EQUAL(sizeof(f16vec4), 8);
  25. //LOLUNIT_ASSERT_EQUAL(sizeof(f16mat4), 32);
  26. LOLUNIT_ASSERT_EQUAL(sizeof(float), 4);
  27. LOLUNIT_ASSERT_EQUAL(sizeof(vec2), 8);
  28. LOLUNIT_ASSERT_EQUAL(sizeof(vec3), 12);
  29. LOLUNIT_ASSERT_EQUAL(sizeof(vec4), 16);
  30. LOLUNIT_ASSERT_EQUAL(sizeof(i8vec2), 2);
  31. LOLUNIT_ASSERT_EQUAL(sizeof(u8vec2), 2);
  32. LOLUNIT_ASSERT_EQUAL(sizeof(i16vec2), 4);
  33. LOLUNIT_ASSERT_EQUAL(sizeof(u16vec2), 4);
  34. LOLUNIT_ASSERT_EQUAL(sizeof(ivec2), 8);
  35. LOLUNIT_ASSERT_EQUAL(sizeof(uvec2), 8);
  36. LOLUNIT_ASSERT_EQUAL(sizeof(i64vec2), 16);
  37. LOLUNIT_ASSERT_EQUAL(sizeof(u64vec2), 16);
  38. LOLUNIT_ASSERT_EQUAL(sizeof(i8vec3), 3);
  39. LOLUNIT_ASSERT_EQUAL(sizeof(u8vec3), 3);
  40. LOLUNIT_ASSERT_EQUAL(sizeof(i16vec3), 6);
  41. LOLUNIT_ASSERT_EQUAL(sizeof(u16vec3), 6);
  42. LOLUNIT_ASSERT_EQUAL(sizeof(ivec3), 12);
  43. LOLUNIT_ASSERT_EQUAL(sizeof(uvec3), 12);
  44. LOLUNIT_ASSERT_EQUAL(sizeof(i64vec3), 24);
  45. LOLUNIT_ASSERT_EQUAL(sizeof(u64vec3), 24);
  46. LOLUNIT_ASSERT_EQUAL(sizeof(i8vec4), 4);
  47. LOLUNIT_ASSERT_EQUAL(sizeof(u8vec4), 4);
  48. LOLUNIT_ASSERT_EQUAL(sizeof(i16vec4), 8);
  49. LOLUNIT_ASSERT_EQUAL(sizeof(u16vec4), 8);
  50. LOLUNIT_ASSERT_EQUAL(sizeof(ivec4), 16);
  51. LOLUNIT_ASSERT_EQUAL(sizeof(uvec4), 16);
  52. LOLUNIT_ASSERT_EQUAL(sizeof(i64vec4), 32);
  53. LOLUNIT_ASSERT_EQUAL(sizeof(u64vec4), 32);
  54. LOLUNIT_ASSERT_EQUAL(sizeof(i8mat4), 16);
  55. LOLUNIT_ASSERT_EQUAL(sizeof(u8mat4), 16);
  56. LOLUNIT_ASSERT_EQUAL(sizeof(i16mat4), 32);
  57. LOLUNIT_ASSERT_EQUAL(sizeof(u16mat4), 32);
  58. LOLUNIT_ASSERT_EQUAL(sizeof(imat4), 64);
  59. LOLUNIT_ASSERT_EQUAL(sizeof(umat4), 64);
  60. LOLUNIT_ASSERT_EQUAL(sizeof(i64mat4), 128);
  61. LOLUNIT_ASSERT_EQUAL(sizeof(u64mat4), 128);
  62. }
  63. #if !defined LOL_DEBUG
  64. LOLUNIT_TEST(FastMath)
  65. {
  66. double x, y;
  67. y = x = 1.0 + RandF(0.1f, 0.2f);
  68. y += 4503599627370496.0;
  69. /* The compiler should optimise this away */
  70. y -= 4503599627370496.0;
  71. LOLUNIT_ASSERT_EQUAL(x, y);
  72. }
  73. #endif
  74. LOLUNIT_TEST(FastMathOverride)
  75. {
  76. double x, y;
  77. y = x = 1.0 + RandF(0.1f, 0.2f);
  78. y += 4503599627370496.0;
  79. FP_USE(y);
  80. /* The compiler should not optimise this away */
  81. y -= 4503599627370496.0;
  82. LOLUNIT_ASSERT_EQUAL(1.0, y);
  83. }
  84. LOLUNIT_TEST(IsNaN)
  85. {
  86. union { float f; uint32_t x; } u;
  87. u.x = 0x7fc00000u;
  88. LOLUNIT_ASSERT(isnan(u.f));
  89. }
  90. };
  91. } /* namespace lol */