Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 */