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

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

core: fix real unary minus and handle negative numbers in additions.

File size: 2.3 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_add)
54    {
55        float a1 = real(1.0f) + real(0.0f);
56        float a2 = real(0.0f) + real(1.0f);
57        float a3 = real(1.0f) + real(1.0f);
58        float a4 = real(-1.0f) + real(-1.0f);
59        float a5 = real(1.0f) + real(0.125f);
60
61        LOLUNIT_ASSERT_EQUAL(a1, 1.0f);
62        LOLUNIT_ASSERT_EQUAL(a2, 1.0f);
63        LOLUNIT_ASSERT_EQUAL(a3, 2.0f);
64        LOLUNIT_ASSERT_EQUAL(a4, -2.0f);
65        LOLUNIT_ASSERT_EQUAL(a5, 1.125f);
66    }
67
68    LOLUNIT_TEST(test_real_sub)
69    {
70#if 0
71printf("\n");
72real k(1.25f);
73k.print();
74real l(1.0f);
75l.print();
76real m = k - l;
77m.print();
78#endif
79        LOLUNIT_ASSERT(true);
80    }
81
82    LOLUNIT_TEST(test_real_mul)
83    {
84        real x(1.25f);
85        real y(1.5f);
86        real z(1.99999f);
87        real w(-1.5f);
88
89        float m1 = x * x;
90        float m2 = y * y;
91        float m3 = z * z;
92        float m4 = w * w;
93
94        LOLUNIT_ASSERT_EQUAL(m1, 1.25f * 1.25f);
95        LOLUNIT_ASSERT_EQUAL(m2, 1.5f * 1.5f);
96        LOLUNIT_ASSERT_EQUAL(m3, 1.99999f * 1.99999f);
97        LOLUNIT_ASSERT_EQUAL(m4, -1.5f * -1.5f);
98    }
99};
100
101} /* namespace lol */
102
Note: See TracBrowser for help on using the repository browser.