Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

111 řádky
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://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <lol/main.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(norm(a), 5.0f);
  51. cmplx b = a * ~a;
  52. cmplx c = norm(a) * norm(a);
  53. LOLUNIT_ASSERT_EQUAL(b, c);
  54. cmplx d(5.0f, 12.0f);
  55. LOLUNIT_ASSERT_EQUAL(norm(d), 13.0f);
  56. LOLUNIT_ASSERT_EQUAL(norm(a * d), norm(a) * norm(d));
  57. }
  58. LOLUNIT_TEST(Base)
  59. {
  60. cmplx one(1.0f, 0.0f);
  61. cmplx i(0.0f, 1.0f);
  62. LOLUNIT_ASSERT_EQUAL(norm(one), 1.0f);
  63. LOLUNIT_ASSERT_EQUAL(norm(i), 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(norm(b), 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 */