Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

111 lignes
2.2 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(ComplexTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(Equality)
  22. {
  23. cmplx a2(1.0f, 2.0f);
  24. cmplx b2(0.0f, 2.0f);
  25. cmplx 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. }
  33. LOLUNIT_TEST(UnaryMinus)
  34. {
  35. cmplx a(1.0f, 3.0f);
  36. cmplx b(-1.0f, -3.0f);
  37. LOLUNIT_ASSERT_EQUAL(a, -b);
  38. LOLUNIT_ASSERT_EQUAL(-a, b);
  39. }
  40. LOLUNIT_TEST(Conjugate)
  41. {
  42. cmplx a(1.0f, 3.0f);
  43. cmplx b(1.0f, -3.0f);
  44. LOLUNIT_ASSERT_EQUAL(a, ~b);
  45. LOLUNIT_ASSERT_EQUAL(~a, b);
  46. }
  47. LOLUNIT_TEST(Norm)
  48. {
  49. cmplx a(3.0f, -4.0f);
  50. LOLUNIT_ASSERT_EQUAL(a.norm(), 5.0f);
  51. cmplx b = a * ~a;
  52. cmplx c = a.norm() * a.norm();
  53. LOLUNIT_ASSERT_EQUAL(b, c);
  54. cmplx d(5.0f, 12.0f);
  55. LOLUNIT_ASSERT_EQUAL(d.norm(), 13.0f);
  56. LOLUNIT_ASSERT_EQUAL((a * d).norm(), a.norm() * d.norm());
  57. }
  58. LOLUNIT_TEST(Base)
  59. {
  60. cmplx one(1.0f, 0.0f);
  61. cmplx i(0.0f, 1.0f);
  62. LOLUNIT_ASSERT_EQUAL(one.norm(), 1.0f);
  63. LOLUNIT_ASSERT_EQUAL(i.norm(), 1.0f);
  64. LOLUNIT_ASSERT_EQUAL(i * i, -one);
  65. }
  66. LOLUNIT_TEST(Normalize)
  67. {
  68. cmplx a(3.0f, -4.0f);
  69. cmplx b = normalize(a);
  70. LOLUNIT_ASSERT_DOUBLES_EQUAL(b.norm(), 1.0, 1e-8);
  71. }
  72. LOLUNIT_TEST(Reciprocal)
  73. {
  74. cmplx a(3.0f, -4.0f);
  75. cmplx b = re(a);
  76. LOLUNIT_ASSERT_EQUAL(a * b, b * a);
  77. cmplx c = 1.0f;
  78. LOLUNIT_ASSERT_EQUAL(a * b, c);
  79. }
  80. };
  81. } /* namespace lol */