選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

vector.cpp 3.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2012 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(VectorTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(VectorEquality)
  22. {
  23. vec2 a2(1.0f, 2.0f);
  24. vec2 b2(0.0f, 2.0f);
  25. vec2 c2(1.0f, 0.0f);
  26. LOLUNIT_ASSERT_EQUAL(a2, a2);
  27. LOLUNIT_ASSERT_NOT_DIFFERENT(a2, a2);
  28. LOLUNIT_ASSERT_DIFFERENT(a2, b2);
  29. LOLUNIT_ASSERT_NOT_EQUAL(a2, b2);
  30. LOLUNIT_ASSERT_DIFFERENT(a2, c2);
  31. LOLUNIT_ASSERT_NOT_EQUAL(a2, c2);
  32. vec3 a3(1.0f, 2.0f, 3.0f);
  33. vec3 b3(0.0f, 2.0f, 3.0f);
  34. vec3 c3(1.0f, 0.0f, 3.0f);
  35. vec3 d3(1.0f, 2.0f, 0.0f);
  36. LOLUNIT_ASSERT_EQUAL(a3, a3);
  37. LOLUNIT_ASSERT_NOT_DIFFERENT(a3, a3);
  38. LOLUNIT_ASSERT_DIFFERENT(a3, b3);
  39. LOLUNIT_ASSERT_NOT_EQUAL(a3, b3);
  40. LOLUNIT_ASSERT_DIFFERENT(a3, c3);
  41. LOLUNIT_ASSERT_NOT_EQUAL(a3, c3);
  42. LOLUNIT_ASSERT_DIFFERENT(a3, d3);
  43. LOLUNIT_ASSERT_NOT_EQUAL(a3, d3);
  44. vec4 a4(1.0f, 2.0f, 3.0f, 4.0f);
  45. vec4 b4(0.0f, 2.0f, 3.0f, 4.0f);
  46. vec4 c4(1.0f, 0.0f, 3.0f, 4.0f);
  47. vec4 d4(1.0f, 2.0f, 0.0f, 4.0f);
  48. vec4 e4(1.0f, 2.0f, 3.0f, 0.0f);
  49. LOLUNIT_ASSERT_EQUAL(a4, a4);
  50. LOLUNIT_ASSERT_NOT_DIFFERENT(a4, a4);
  51. LOLUNIT_ASSERT_DIFFERENT(a4, b4);
  52. LOLUNIT_ASSERT_NOT_EQUAL(a4, b4);
  53. LOLUNIT_ASSERT_DIFFERENT(a4, c4);
  54. LOLUNIT_ASSERT_NOT_EQUAL(a4, c4);
  55. LOLUNIT_ASSERT_DIFFERENT(a4, d4);
  56. LOLUNIT_ASSERT_NOT_EQUAL(a4, d4);
  57. LOLUNIT_ASSERT_DIFFERENT(a4, e4);
  58. LOLUNIT_ASSERT_NOT_EQUAL(a4, e4);
  59. }
  60. LOLUNIT_TEST(VectorInequality)
  61. {
  62. vec2 a2(1.0f, 3.0f);
  63. vec2 b2(0.0f, 0.0f);
  64. vec2 c2(1.0f, 1.0f);
  65. vec2 d2(2.0f, 2.0f);
  66. vec2 e2(3.0f, 3.0f);
  67. vec2 f2(4.0f, 4.0f);
  68. LOLUNIT_ASSERT_LEQUAL(a2, a2);
  69. LOLUNIT_ASSERT_NOT_LESS(a2, a2);
  70. LOLUNIT_ASSERT_NOT_LEQUAL(a2, b2);
  71. LOLUNIT_ASSERT_NOT_LESS(a2, b2);
  72. LOLUNIT_ASSERT_NOT_LEQUAL(a2, c2);
  73. LOLUNIT_ASSERT_NOT_LESS(a2, c2);
  74. LOLUNIT_ASSERT_NOT_LEQUAL(a2, d2);
  75. LOLUNIT_ASSERT_NOT_LESS(a2, d2);
  76. LOLUNIT_ASSERT_LEQUAL(a2, e2);
  77. LOLUNIT_ASSERT_NOT_LESS(a2, e2);
  78. LOLUNIT_ASSERT_LEQUAL(a2, f2);
  79. LOLUNIT_ASSERT_LESS(a2, f2);
  80. }
  81. LOLUNIT_TEST(VectorUnaryMinus)
  82. {
  83. vec2 a(1.0f, 3.0f);
  84. vec2 b(-1.0f, -3.0f);
  85. LOLUNIT_ASSERT_EQUAL(a, -b);
  86. LOLUNIT_ASSERT_EQUAL(-a, b);
  87. }
  88. LOLUNIT_TEST(CastVector)
  89. {
  90. vec2 a1(1.0f, 3.0f);
  91. vec3 b(a1, 0.0f);
  92. vec2 a2(b.xy);
  93. LOLUNIT_ASSERT_EQUAL(b.x, a1.x);
  94. LOLUNIT_ASSERT_EQUAL(b.y, a1.y);
  95. LOLUNIT_ASSERT_EQUAL(b.z, 0.0f);
  96. LOLUNIT_ASSERT_EQUAL(a2, a1);
  97. vec4 c(a1, 0.0f, 0.0f);
  98. vec2 a3(c.xy);
  99. LOLUNIT_ASSERT_EQUAL(c.x, a1.x);
  100. LOLUNIT_ASSERT_EQUAL(c.y, a1.y);
  101. LOLUNIT_ASSERT_EQUAL(c.z, 0.0f);
  102. LOLUNIT_ASSERT_EQUAL(c.w, 0.0f);
  103. LOLUNIT_ASSERT_EQUAL(a3, a1);
  104. }
  105. };
  106. } /* namespace lol */