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

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

core: handle zero, negative zero and infinite in the real constructor,
and add a test suite check for unary minus.

File size: 1.8 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{
25public:
26    LOLUNIT_TEST(test_real_from_float)
27    {
28        float a1 = real(0.0f);
29        float a2 = real(-0.0f);
30        float a3 = real(1.0f);
31        float a4 = real(-1.0f);
32        float a5 = real(1.5f);
33
34        LOLUNIT_ASSERT_EQUAL(a1, 0.0f);
35        LOLUNIT_ASSERT_EQUAL(a2, -0.0f);
36        LOLUNIT_ASSERT_EQUAL(a3, 1.0f);
37        LOLUNIT_ASSERT_EQUAL(a4, -1.0f);
38        LOLUNIT_ASSERT_EQUAL(a5, 1.5f);
39    }
40
41    LOLUNIT_TEST(test_real_neg)
42    {
43        float a1 = - real(1.0f);
44        float a2 = - real(-1.0f);
45        float a3 = - real(0.0f);
46        float a4 = - real(-0.0f);
47
48        LOLUNIT_ASSERT_EQUAL(a1, -1.0f);
49        LOLUNIT_ASSERT_EQUAL(a2, 1.0f);
50        LOLUNIT_ASSERT_EQUAL(a3, -0.0f);
51        LOLUNIT_ASSERT_EQUAL(a4, 0.0f);
52    }
53
54    LOLUNIT_TEST(test_real_add)
55    {
56        LOLUNIT_ASSERT(true);
57    }
58
59    LOLUNIT_TEST(test_real_mul)
60    {
61        real x(1.25f);
62        real y(1.5f);
63        real z(1.99999f);
64        real w(-1.5f);
65
66        float m1 = x * x;
67        float m2 = y * y;
68        float m3 = z * z;
69        float m4 = w * w;
70
71        LOLUNIT_ASSERT_EQUAL(m1, 1.25f * 1.25f);
72        LOLUNIT_ASSERT_EQUAL(m2, 1.5f * 1.5f);
73        LOLUNIT_ASSERT_EQUAL(m3, 1.99999f * 1.99999f);
74        LOLUNIT_ASSERT_EQUAL(m4, -1.5f * -1.5f);
75    }
76};
77
78} /* namespace lol */
79
Note: See TracBrowser for help on using the repository browser.