You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

80 lines
1.8 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 <cmath>
  14. #include "core.h"
  15. #include "lol/unit.h"
  16. namespace lol
  17. {
  18. LOLUNIT_FIXTURE(RealTest)
  19. {
  20. public:
  21. LOLUNIT_TEST(test_real_from_float)
  22. {
  23. float a1 = real(0.0f);
  24. float a2 = real(-0.0f);
  25. float a3 = real(1.0f);
  26. float a4 = real(-1.0f);
  27. float a5 = real(1.5f);
  28. LOLUNIT_ASSERT_EQUAL(a1, 0.0f);
  29. LOLUNIT_ASSERT_EQUAL(a2, -0.0f);
  30. LOLUNIT_ASSERT_EQUAL(a3, 1.0f);
  31. LOLUNIT_ASSERT_EQUAL(a4, -1.0f);
  32. LOLUNIT_ASSERT_EQUAL(a5, 1.5f);
  33. }
  34. LOLUNIT_TEST(test_real_neg)
  35. {
  36. float a1 = - real(1.0f);
  37. float a2 = - real(-1.0f);
  38. float a3 = - real(0.0f);
  39. float a4 = - real(-0.0f);
  40. LOLUNIT_ASSERT_EQUAL(a1, -1.0f);
  41. LOLUNIT_ASSERT_EQUAL(a2, 1.0f);
  42. LOLUNIT_ASSERT_EQUAL(a3, -0.0f);
  43. LOLUNIT_ASSERT_EQUAL(a4, 0.0f);
  44. }
  45. LOLUNIT_TEST(test_real_add)
  46. {
  47. LOLUNIT_ASSERT(true);
  48. }
  49. LOLUNIT_TEST(test_real_mul)
  50. {
  51. real x(1.25f);
  52. real y(1.5f);
  53. real z(1.99999f);
  54. real w(-1.5f);
  55. float m1 = x * x;
  56. float m2 = y * y;
  57. float m3 = z * z;
  58. float m4 = w * w;
  59. LOLUNIT_ASSERT_EQUAL(m1, 1.25f * 1.25f);
  60. LOLUNIT_ASSERT_EQUAL(m2, 1.5f * 1.5f);
  61. LOLUNIT_ASSERT_EQUAL(m3, 1.99999f * 1.99999f);
  62. LOLUNIT_ASSERT_EQUAL(m4, -1.5f * -1.5f);
  63. }
  64. };
  65. } /* namespace lol */