source: trunk/test/unit/real.cpp @ 974

Last change on this file since 974 was 974, checked in by sam, 11 years ago

core: implement real subtraction.

File size: 3.0 KB
Line 
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
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cmath>
16
17#include "core.h"
18#include "lol/unit.h"
19
20namespace lol
21{
22
23LOLUNIT_FIXTURE(RealTest)
24{
25    LOLUNIT_TEST(test_real_from_float)
26    {
27        float a1 = real(0.0f);
28        float a2 = real(-0.0f);
29        float a3 = real(1.0f);
30        float a4 = real(-1.0f);
31        float a5 = real(1.5f);
32
33        LOLUNIT_ASSERT_EQUAL(a1, 0.0f);
34        LOLUNIT_ASSERT_EQUAL(a2, -0.0f);
35        LOLUNIT_ASSERT_EQUAL(a3, 1.0f);
36        LOLUNIT_ASSERT_EQUAL(a4, -1.0f);
37        LOLUNIT_ASSERT_EQUAL(a5, 1.5f);
38    }
39
40    LOLUNIT_TEST(test_real_neg)
41    {
42        float a1 = - real(1.0f);
43        float a2 = - real(-1.0f);
44        float a3 = - real(0.0f);
45        float a4 = - real(-0.0f);
46
47        LOLUNIT_ASSERT_EQUAL(a1, -1.0f);
48        LOLUNIT_ASSERT_EQUAL(a2, 1.0f);
49        LOLUNIT_ASSERT_EQUAL(a3, -0.0f);
50        LOLUNIT_ASSERT_EQUAL(a4, 0.0f);
51    }
52
53    LOLUNIT_TEST(test_real_comp)
54    {
55        LOLUNIT_ASSERT(real(1.0f) > real(0.5f));
56        LOLUNIT_ASSERT(real(1.0f) >= real(0.5f));
57        LOLUNIT_ASSERT(real(1.0f) >= real(1.0f));
58
59        LOLUNIT_ASSERT(real(-1.0f) < real(-0.5f));
60        LOLUNIT_ASSERT(real(-1.0f) <= real(-0.5f));
61        LOLUNIT_ASSERT(real(-1.0f) <= real(-1.0f));
62
63        LOLUNIT_ASSERT(real(-1.0f) < real(0.5f));
64        LOLUNIT_ASSERT(real(-0.5f) < real(1.0f));
65        LOLUNIT_ASSERT(real(-1.0f) <= real(0.5f));
66        LOLUNIT_ASSERT(real(-0.5f) <= real(1.0f));
67
68        LOLUNIT_ASSERT(real(1.0f) > real(-0.5f));
69        LOLUNIT_ASSERT(real(0.5f) > real(-1.0f));
70        LOLUNIT_ASSERT(real(1.0f) >= real(-0.5f));
71        LOLUNIT_ASSERT(real(0.5f) >= real(-1.0f));
72    }
73
74    LOLUNIT_TEST(test_real_add)
75    {
76        float a1 = real(1.0f) + real(0.0f);
77        float a2 = real(0.0f) + real(1.0f);
78        float a3 = real(1.0f) + real(1.0f);
79        float a4 = real(-1.0f) + real(-1.0f);
80        float a5 = real(1.0f) + real(0.125f);
81
82        LOLUNIT_ASSERT_EQUAL(a1, 1.0f);
83        LOLUNIT_ASSERT_EQUAL(a2, 1.0f);
84        LOLUNIT_ASSERT_EQUAL(a3, 2.0f);
85        LOLUNIT_ASSERT_EQUAL(a4, -2.0f);
86        LOLUNIT_ASSERT_EQUAL(a5, 1.125f);
87    }
88
89    LOLUNIT_TEST(test_real_sub)
90    {
91        float a1 = real(1.0f) + real(1e20f) - real(1e20f);
92
93        LOLUNIT_ASSERT_EQUAL(a1, 1.0f);
94    }
95
96    LOLUNIT_TEST(test_real_mul)
97    {
98        real x(1.25f);
99        real y(1.5f);
100        real z(1.99999f);
101        real w(-1.5f);
102
103        float m1 = x * x;
104        float m2 = y * y;
105        float m3 = z * z;
106        float m4 = w * w;
107
108        LOLUNIT_ASSERT_EQUAL(m1, 1.25f * 1.25f);
109        LOLUNIT_ASSERT_EQUAL(m2, 1.5f * 1.5f);
110        LOLUNIT_ASSERT_EQUAL(m3, 1.99999f * 1.99999f);
111        LOLUNIT_ASSERT_EQUAL(m4, -1.5f * -1.5f);
112    }
113};
114
115} /* namespace lol */
116
Note: See TracBrowser for help on using the repository browser.