source: trunk/test/unit/build.cpp @ 1041

Last change on this file since 1041 was 1041, checked in by sam, 8 years ago

core: new combinations of integer vectors (unsigned, 8-bit, etc.), dot and
cross product, normalize, etc.

  • Property svn:keywords set to Id
File size: 3.2 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 "core.h"
16#include "lol/unit.h"
17
18namespace lol
19{
20
21LOLUNIT_FIXTURE(BuildTest)
22{
23    LOLUNIT_TEST(TypeSize)
24    {
25        LOLUNIT_ASSERT_EQUAL(sizeof(half), 2);
26        //LOLUNIT_ASSERT_EQUAL(sizeof(f16vec2), 4);
27        //LOLUNIT_ASSERT_EQUAL(sizeof(f16vec3), 6);
28        //LOLUNIT_ASSERT_EQUAL(sizeof(f16vec4), 8);
29        //LOLUNIT_ASSERT_EQUAL(sizeof(f16mat4), 32);
30
31        LOLUNIT_ASSERT_EQUAL(sizeof(float), 4);
32        LOLUNIT_ASSERT_EQUAL(sizeof(vec2), 8);
33        LOLUNIT_ASSERT_EQUAL(sizeof(vec3), 12);
34        LOLUNIT_ASSERT_EQUAL(sizeof(vec4), 16);
35
36        LOLUNIT_ASSERT_EQUAL(sizeof(i8vec2), 2);
37        LOLUNIT_ASSERT_EQUAL(sizeof(u8vec2), 2);
38        LOLUNIT_ASSERT_EQUAL(sizeof(i16vec2), 4);
39        LOLUNIT_ASSERT_EQUAL(sizeof(u16vec2), 4);
40        LOLUNIT_ASSERT_EQUAL(sizeof(ivec2), 8);
41        LOLUNIT_ASSERT_EQUAL(sizeof(uvec2), 8);
42        LOLUNIT_ASSERT_EQUAL(sizeof(i64vec2), 16);
43        LOLUNIT_ASSERT_EQUAL(sizeof(u64vec2), 16);
44
45        LOLUNIT_ASSERT_EQUAL(sizeof(i8vec3), 3);
46        LOLUNIT_ASSERT_EQUAL(sizeof(u8vec3), 3);
47        LOLUNIT_ASSERT_EQUAL(sizeof(i16vec3), 6);
48        LOLUNIT_ASSERT_EQUAL(sizeof(u16vec3), 6);
49        LOLUNIT_ASSERT_EQUAL(sizeof(ivec3), 12);
50        LOLUNIT_ASSERT_EQUAL(sizeof(uvec3), 12);
51        LOLUNIT_ASSERT_EQUAL(sizeof(i64vec3), 24);
52        LOLUNIT_ASSERT_EQUAL(sizeof(u64vec3), 24);
53
54        LOLUNIT_ASSERT_EQUAL(sizeof(i8vec4), 4);
55        LOLUNIT_ASSERT_EQUAL(sizeof(u8vec4), 4);
56        LOLUNIT_ASSERT_EQUAL(sizeof(i16vec4), 8);
57        LOLUNIT_ASSERT_EQUAL(sizeof(u16vec4), 8);
58        LOLUNIT_ASSERT_EQUAL(sizeof(ivec4), 16);
59        LOLUNIT_ASSERT_EQUAL(sizeof(uvec4), 16);
60        LOLUNIT_ASSERT_EQUAL(sizeof(i64vec4), 32);
61        LOLUNIT_ASSERT_EQUAL(sizeof(u64vec4), 32);
62
63        LOLUNIT_ASSERT_EQUAL(sizeof(i8mat4), 16);
64        LOLUNIT_ASSERT_EQUAL(sizeof(u8mat4), 16);
65        LOLUNIT_ASSERT_EQUAL(sizeof(i16mat4), 32);
66        LOLUNIT_ASSERT_EQUAL(sizeof(u16mat4), 32);
67        LOLUNIT_ASSERT_EQUAL(sizeof(imat4), 64);
68        LOLUNIT_ASSERT_EQUAL(sizeof(umat4), 64);
69        LOLUNIT_ASSERT_EQUAL(sizeof(i64mat4), 128);
70        LOLUNIT_ASSERT_EQUAL(sizeof(u64mat4), 128);
71    }
72
73#if !defined LOL_DEBUG
74    LOLUNIT_TEST(FastMath)
75    {
76        double x, y;
77
78        y = x = 1.0 + RandF(0.1f, 0.2f);
79        y += 4503599627370496.0;
80        /* The compiler should optimise this away */
81        y -= 4503599627370496.0;
82
83        LOLUNIT_ASSERT_EQUAL(x, y);
84    }
85#endif
86
87    LOLUNIT_TEST(FastMathOverride)
88    {
89        double x, y;
90
91        y = x = 1.0 + RandF(0.1f, 0.2f);
92        y += 4503599627370496.0;
93        FP_USE(y);
94        /* The compiler should not optimise this away */
95        y -= 4503599627370496.0;
96
97        LOLUNIT_ASSERT_EQUAL(1.0, y);
98    }
99
100    LOLUNIT_TEST(IsNaN)
101    {
102        union { float f; uint32_t x; } u;
103
104        u.x = 0x7fc00000u;
105        LOLUNIT_ASSERT(isnan(u.f));
106    }
107};
108
109} /* namespace lol */
110
Note: See TracBrowser for help on using the repository browser.