aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/math.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/test/math.cpp')
-rw-r--r--linden/indra/test/math.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/linden/indra/test/math.cpp b/linden/indra/test/math.cpp
index be8a398..3f5a15c 100644
--- a/linden/indra/test/math.cpp
+++ b/linden/indra/test/math.cpp
@@ -6,6 +6,7 @@
6 * 6 *
7 * Copyright (c) 2005-2007, Linden Research, Inc. 7 * Copyright (c) 2005-2007, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code
9 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0 11 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement 12 * ("GPL"), unless you have obtained a separate licensing agreement
@@ -32,6 +33,7 @@
32 33
33#include "llmath.h" 34#include "llmath.h"
34#include "lluuid.h" 35#include "lluuid.h"
36#include "llcrc.h"
35 37
36namespace tut 38namespace tut
37{ 39{
@@ -74,6 +76,95 @@ namespace tut
74 val = llabs(val); 76 val = llabs(val);
75 ensure("double absolute value 2", (8937843.9394878 == val)); 77 ensure("double absolute value 2", (8937843.9394878 == val));
76 } 78 }
79
80 template<> template<>
81 void math_object::test<4>()
82 {
83 F32 val = 430903.9f;
84 S32 val1 = lltrunc(val);
85 ensure("float truncate value 1", (430903 == val1));
86 val = -2303.9f;
87 val1 = lltrunc(val);
88 ensure("float truncate value 2", (-2303 == val1));
89 }
90
91 template<> template<>
92 void math_object::test<5>()
93 {
94 F64 val = 387439393.987329839 ;
95 S32 val1 = lltrunc(val);
96 ensure("float truncate value 1", (387439393 == val1));
97 val = -387439393.987329839;
98 val1 = lltrunc(val);
99 ensure("float truncate value 2", (-387439393 == val1));
100 }
101
102 template<> template<>
103 void math_object::test<6>()
104 {
105 F32 val = 430903.2f;
106 S32 val1 = llfloor(val);
107 ensure("float llfloor value 1", (430903 == val1));
108 val = -430903.9f;
109 val1 = llfloor(val);
110 ensure("float llfloor value 2", (-430904 == val1));
111 }
112
113 template<> template<>
114 void math_object::test<7>()
115 {
116 F32 val = 430903.2f;
117 S32 val1 = llceil(val);
118 ensure("float llceil value 1", (430904 == val1));
119 val = -430903.9f;
120 val1 = llceil(val);
121 ensure("float llceil value 2", (-430903 == val1));
122 }
123
124 template<> template<>
125 void math_object::test<8>()
126 {
127 F32 val = 430903.2f;
128 S32 val1 = llround(val);
129 ensure("float llround value 1", (430903 == val1));
130 val = -430903.9f;
131 val1 = llround(val);
132 ensure("float llround value 2", (-430904 == val1));
133 }
134
135 template<> template<>
136 void math_object::test<9>()
137 {
138 F32 val = 430905.2654f, nearest = 100.f;
139 val = llround(val, nearest);
140 ensure("float llround value 1", (430900 == val));
141 val = -430905.2654f, nearest = 10.f;
142 val = llround(val, nearest);
143 ensure("float llround value 1", (-430910 == val));
144 }
145
146 template<> template<>
147 void math_object::test<10>()
148 {
149 F64 val = 430905.2654, nearest = 100.0;
150 val = llround(val, nearest);
151 ensure("double llround value 1", (430900 == val));
152 val = -430905.2654, nearest = 10.0;
153 val = llround(val, nearest);
154 ensure("double llround value 1", (-430910.00000 == val));
155 }
156
157 template<> template<>
158 void math_object::test<11>()
159 {
160 const F32 F_PI = 3.1415926535897932384626433832795f;
161 F32 angle = 3506.f;
162 angle = llsimple_angle(angle);
163 ensure("llsimple_angle value 1", (angle <=F_PI && angle >= -F_PI));
164 angle = -431.f;
165 angle = llsimple_angle(angle);
166 ensure("llsimple_angle value 1", (angle <=F_PI && angle >= -F_PI));
167 }
77} 168}
78 169
79namespace tut 170namespace tut
@@ -131,3 +222,55 @@ namespace tut
131 } 222 }
132 223
133} 224}
225
226namespace tut
227{
228 struct crc_data
229 {
230 };
231 typedef test_group<crc_data> crc_test;
232 typedef crc_test::object crc_object;
233 tut::crc_test tc("crc");
234
235 template<> template<>
236 void crc_object::test<1>()
237 {
238 /* Test buffer update and individual char update */
239 const char TEST_BUFFER[] = "hello &#$)$&Nd0";
240 LLCRC c1, c2;
241 c1.update((U8*)TEST_BUFFER, sizeof(TEST_BUFFER) - 1);
242 char* rh = (char*)TEST_BUFFER;
243 while(*rh != '\0')
244 {
245 c2.update(*rh);
246 ++rh;
247 }
248 ensure_equals("crc update 1", c1.getCRC(), c2.getCRC());
249 }
250
251 template<> template<>
252 void crc_object::test<2>()
253 {
254 /* Test mixing of buffer and individual char update */
255 const char TEST_BUFFER1[] = "Split Buffer one $^%$%#@$";
256 const char TEST_BUFFER2[] = "Split Buffer two )(8723#5dsds";
257 LLCRC c1, c2;
258 c1.update((U8*)TEST_BUFFER1, sizeof(TEST_BUFFER1) - 1);
259 char* rh = (char*)TEST_BUFFER2;
260 while(*rh != '\0')
261 {
262 c1.update(*rh);
263 ++rh;
264 }
265
266 rh = (char*)TEST_BUFFER1;
267 while(*rh != '\0')
268 {
269 c2.update(*rh);
270 ++rh;
271 }
272 c2.update((U8*)TEST_BUFFER2, sizeof(TEST_BUFFER2) - 1);
273
274 ensure_equals("crc update 2", c1.getCRC(), c2.getCRC());
275 }
276}