Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: tests/lib/typeddata/float32x4_test.dart

Issue 14426006: Rename dart:typeddata to dart:typed_data. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Library tag to be able to run in html test framework.
6 library float32x4_test;
7
8 import "package:expect/expect.dart";
9 import 'dart:typeddata';
10
11 testAdd() {
12 var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
13 var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
14 var o = m + n;
15 Expect.equals(0.0, o.x);
16 Expect.equals(0.0, o.y);
17 Expect.equals(0.0, o.z);
18 Expect.equals(0.0, o.w);
19 }
20
21 testNegate() {
22 var m = new Float32x4(1.0, 2.0, -3.0, -4.0);
23 m = -m;
24 Expect.equals(-1.0, m.x);
25 Expect.equals(-2.0, m.y);
26 Expect.equals(3.0, m.z);
27 Expect.equals(4.0, m.w);
28 }
29
30 testSub() {
31 var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
32 var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
33 var o = m - n;
34 Expect.equals(-2.0, o.x);
35 Expect.equals(-4.0, o.y);
36 Expect.equals(-6.0, o.z);
37 Expect.equals(-8.0, o.w);
38 }
39
40 testMul() {
41 var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
42 var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
43 var o = m * n;
44 Expect.equals(-1.0, o.x);
45 Expect.equals(-4.0, o.y);
46 Expect.equals(-9.0, o.z);
47 Expect.equals(-16.0, o.w);
48 }
49
50 testDiv() {
51 var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
52 var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
53 var o = m / n;
54 Expect.equals(-1.0, o.x);
55 Expect.equals(-1.0, o.y);
56 Expect.equals(-1.0, o.z);
57 Expect.equals(-1.0, o.w);
58 }
59
60 testComparison() {
61 var m = new Float32x4(1.0, 2.0, 0.1, 0.001);
62 var n = new Float32x4(2.0, 2.0, 0.001, 0.1);
63 var cmp;
64 cmp = m.lessThan(n);
65 Expect.equals(0xFFFFFFFF, cmp.x);
66 Expect.equals(0x0, cmp.y);
67 Expect.equals(0x0, cmp.z);
68 Expect.equals(0xFFFFFFFF, cmp.w);
69
70 cmp = m.lessThanOrEqual(n);
71 Expect.equals(0xFFFFFFFF, cmp.x);
72 Expect.equals(0xFFFFFFFF, cmp.y);
73 Expect.equals(0x0, cmp.z);
74 Expect.equals(0xFFFFFFFF, cmp.w);
75
76 cmp = m.equal(n);
77 Expect.equals(0x0, cmp.x);
78 Expect.equals(0xFFFFFFFF, cmp.y);
79 Expect.equals(0x0, cmp.z);
80 Expect.equals(0x0, cmp.w);
81
82 cmp = m.notEqual(n);
83 Expect.equals(0xFFFFFFFF, cmp.x);
84 Expect.equals(0x0, cmp.y);
85 Expect.equals(0xFFFFFFFF, cmp.z);
86 Expect.equals(0xFFFFFFFF, cmp.w);
87
88 cmp = m.greaterThanOrEqual(n);
89 Expect.equals(0x0, cmp.x);
90 Expect.equals(0xFFFFFFFF, cmp.y);
91 Expect.equals(0xFFFFFFFF, cmp.z);
92 Expect.equals(0x0, cmp.w);
93
94 cmp = m.greaterThan(n);
95 Expect.equals(0x0, cmp.x);
96 Expect.equals(0x0, cmp.y);
97 Expect.equals(0xFFFFFFFF, cmp.z);
98 Expect.equals(0x0, cmp.w);
99 }
100
101 testAbs() {
102 var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
103 m = m.abs();
104 Expect.equals(1.0, m.x);
105 Expect.equals(2.0, m.y);
106 Expect.equals(3.0, m.z);
107 Expect.equals(4.0, m.w);
108 }
109
110 testScale() {
111 var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
112 m = m.scale(20.0);
113 Expect.equals(20.0, m.x);
114 Expect.equals(-40.0, m.y);
115 Expect.equals(60.0, m.z);
116 Expect.equals(-80.0, m.w);
117 }
118
119 testClamp() {
120 var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
121 var lo = new Float32x4(0.0, 0.0, 0.0, 0.0);
122 var hi = new Float32x4(2.0, 2.0, 2.0, 2.0);
123 m = m.clamp(lo, hi);
124 Expect.equals(1.0, m.x);
125 Expect.equals(0.0, m.y);
126 Expect.equals(2.0, m.z);
127 Expect.equals(0.0, m.w);
128 }
129
130 testShuffle() {
131 var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
132 var xxxx = m.xxxx;
133 Expect.equals(1.0, xxxx.x);
134 Expect.equals(1.0, xxxx.y);
135 Expect.equals(1.0, xxxx.z);
136 Expect.equals(1.0, xxxx.w);
137 var yyyy = m.yyyy;
138 Expect.equals(2.0, yyyy.x);
139 Expect.equals(2.0, yyyy.y);
140 Expect.equals(2.0, yyyy.z);
141 Expect.equals(2.0, yyyy.w);
142 var zzzz = m.zzzz;
143 Expect.equals(3.0, zzzz.x);
144 Expect.equals(3.0, zzzz.y);
145 Expect.equals(3.0, zzzz.z);
146 Expect.equals(3.0, zzzz.w);
147 var wwww = m.wwww;
148 Expect.equals(4.0, wwww.x);
149 Expect.equals(4.0, wwww.y);
150 Expect.equals(4.0, wwww.z);
151 Expect.equals(4.0, wwww.w);
152 }
153
154 testMin() {
155 var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
156 var n = new Float32x4(1.0, 0.0, 2.5, 5.0);
157 m = m.min(n);
158 Expect.equals(1.0, m.x);
159 Expect.equals(0.0, m.y);
160 Expect.equals(2.5, m.z);
161 Expect.equals(4.0, m.w);
162 }
163
164 testMax() {
165 var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
166 var n = new Float32x4(1.0, 0.0, 2.5, 5.0);
167 m = m.max(n);
168 Expect.equals(1.0, m.x);
169 Expect.equals(2.0, m.y);
170 Expect.equals(3.0, m.z);
171 Expect.equals(5.0, m.w);
172 }
173
174 testSqrt() {
175 var m = new Float32x4(1.0, 4.0, 9.0, 16.0);
176 m = m.sqrt();
177 Expect.equals(1.0, m.x);
178 Expect.equals(2.0, m.y);
179 Expect.equals(3.0, m.z);
180 Expect.equals(4.0, m.w);
181 }
182
183 testReciprocal() {
184 var m = new Float32x4(1.0, 4.0, 9.0, 16.0);
185 m = m.reciprocal();
186 Expect.approxEquals(1.0, m.x);
187 Expect.approxEquals(0.25, m.y);
188 Expect.approxEquals(0.1111111, m.z);
189 Expect.approxEquals(0.0625, m.w);
190 }
191
192 testReciprocalSqrt() {
193 var m = new Float32x4(1.0, 0.25, 0.111111, 0.0625);
194 m = m.reciprocalSqrt();
195 Expect.approxEquals(1.0, m.x);
196 Expect.approxEquals(2.0, m.y);
197 Expect.approxEquals(3.0, m.z);
198 Expect.approxEquals(4.0, m.w);
199 }
200
201 testSelect() {
202 var m = new Uint32x4.bool(true, true, false, false);
203 var t = new Float32x4(1.0, 2.0, 3.0, 4.0);
204 var f = new Float32x4(5.0, 6.0, 7.0, 8.0);
205 var s = m.select(t, f);
206 Expect.equals(1.0, s.x);
207 Expect.equals(2.0, s.y);
208 Expect.equals(7.0, s.z);
209 Expect.equals(8.0, s.w);
210 }
211
212 testConversions() {
213 var m = new Uint32x4(0x3F800000, 0x40000000, 0x40400000, 0x40800000);
214 var n = m.toFloat32x4();
215 Expect.equals(1.0, n.x);
216 Expect.equals(2.0, n.y);
217 Expect.equals(3.0, n.z);
218 Expect.equals(4.0, n.w);
219 n = new Float32x4(5.0, 6.0, 7.0, 8.0);
220 m = n.toUint32x4();
221 Expect.equals(0x40A00000, m.x);
222 Expect.equals(0x40C00000, m.y);
223 Expect.equals(0x40E00000, m.z);
224 Expect.equals(0x41000000, m.w);
225 // Flip sign using bit-wise operators.
226 n = new Float32x4(9.0, 10.0, 11.0, 12.0);
227 m = new Uint32x4(0x80000000, 0x80000000, 0x80000000, 0x80000000);
228 var nMask = n.toUint32x4();
229 nMask = nMask ^ m; // flip sign.
230 n = nMask.toFloat32x4();
231 Expect.equals(-9.0, n.x);
232 Expect.equals(-10.0, n.y);
233 Expect.equals(-11.0, n.z);
234 Expect.equals(-12.0, n.w);
235 nMask = n.toUint32x4();
236 nMask = nMask ^ m; // flip sign.
237 n = nMask.toFloat32x4();
238 Expect.equals(9.0, n.x);
239 Expect.equals(10.0, n.y);
240 Expect.equals(11.0, n.z);
241 Expect.equals(12.0, n.w);
242 }
243
244
245 testBitOperators() {
246 var m = new Uint32x4(0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA);
247 var n = new Uint32x4(0x55555555, 0x55555555, 0x55555555, 0x55555555);
248 Expect.equals(0xAAAAAAAA, m.x);
249 Expect.equals(0xAAAAAAAA, m.y);
250 Expect.equals(0xAAAAAAAA, m.z);
251 Expect.equals(0xAAAAAAAA, m.w);
252 Expect.equals(0x55555555, n.x);
253 Expect.equals(0x55555555, n.y);
254 Expect.equals(0x55555555, n.z);
255 Expect.equals(0x55555555, n.w);
256 Expect.equals(true, n.flagX);
257 Expect.equals(true, n.flagY);
258 Expect.equals(true, n.flagZ);
259 Expect.equals(true, n.flagW);
260 var o = m|n; // or
261 Expect.equals(0xFFFFFFFF, o.x);
262 Expect.equals(0xFFFFFFFF, o.y);
263 Expect.equals(0xFFFFFFFF, o.z);
264 Expect.equals(0xFFFFFFFF, o.w);
265 Expect.equals(true, o.flagX);
266 Expect.equals(true, o.flagY);
267 Expect.equals(true, o.flagZ);
268 Expect.equals(true, o.flagW);
269 o = m&n; // and
270 Expect.equals(0x0, o.x);
271 Expect.equals(0x0, o.y);
272 Expect.equals(0x0, o.z);
273 Expect.equals(0x0, o.w);
274 n = n.withX(0xAAAAAAAA);
275 n = n.withY(0xAAAAAAAA);
276 n = n.withZ(0xAAAAAAAA);
277 n = n.withW(0xAAAAAAAA);
278 Expect.equals(0xAAAAAAAA, n.x);
279 Expect.equals(0xAAAAAAAA, n.y);
280 Expect.equals(0xAAAAAAAA, n.z);
281 Expect.equals(0xAAAAAAAA, n.w);
282 o = m^n; // xor
283 Expect.equals(0x0, o.x);
284 Expect.equals(0x0, o.y);
285 Expect.equals(0x0, o.z);
286 Expect.equals(0x0, o.w);
287 Expect.equals(false, o.flagX);
288 Expect.equals(false, o.flagY);
289 Expect.equals(false, o.flagZ);
290 Expect.equals(false, o.flagW);
291 }
292
293 testSetters() {
294 var f = new Float32x4.zero();
295 Expect.equals(0.0, f.x);
296 Expect.equals(0.0, f.y);
297 Expect.equals(0.0, f.z);
298 Expect.equals(0.0, f.w);
299 f = f.withX(4.0);
300 Expect.equals(4.0, f.x);
301 f = f.withY(3.0);
302 Expect.equals(3.0, f.y);
303 f = f.withZ(2.0);
304 Expect.equals(2.0, f.z);
305 f = f.withW(1.0);
306 Expect.equals(1.0, f.w);
307 f = new Float32x4.zero();
308 f = f.withX(4.0).withZ(2.0).withW(1.0).withY(3.0);
309 Expect.equals(4.0, f.x);
310 Expect.equals(3.0, f.y);
311 Expect.equals(2.0, f.z);
312 Expect.equals(1.0, f.w);
313 var m = new Uint32x4.bool(false, false, false, false);
314 Expect.equals(false, m.flagX);
315 Expect.equals(false, m.flagY);
316 Expect.equals(false, m.flagZ);
317 Expect.equals(false, m.flagW);
318 m = m.withFlagX(true);
319 Expect.equals(true, m.flagX);
320 Expect.equals(false, m.flagY);
321 Expect.equals(false, m.flagZ);
322 Expect.equals(false, m.flagW);
323 m = m.withFlagY(true);
324 Expect.equals(true, m.flagX);
325 Expect.equals(true, m.flagY);
326 Expect.equals(false, m.flagZ);
327 Expect.equals(false, m.flagW);
328 m = m.withFlagZ(true);
329 Expect.equals(true, m.flagX);
330 Expect.equals(true, m.flagY);
331 Expect.equals(true, m.flagZ);
332 Expect.equals(false, m.flagW);
333 m = m.withFlagW(true);
334 Expect.equals(true, m.flagX);
335 Expect.equals(true, m.flagY);
336 Expect.equals(true, m.flagZ);
337 Expect.equals(true, m.flagW);
338 }
339
340 testGetters() {
341 var f = new Float32x4(1.0, 2.0, 3.0, 4.0);
342 Expect.equals(1.0, f.x);
343 Expect.equals(2.0, f.y);
344 Expect.equals(3.0, f.z);
345 Expect.equals(4.0, f.w);
346 var m = new Uint32x4.bool(false, true, true, false);
347 Expect.equals(false, m.flagX);
348 Expect.equals(true, m.flagY);
349 Expect.equals(true, m.flagZ);
350 Expect.equals(false, m.flagW);
351 }
352
353 main() {
354 for (int i = 0; i < 3000; i++) {
355 testAdd();
356 testGetters();
357 testSetters();
358 testBitOperators();
359 testConversions();
360 testSelect();
361 testShuffle();
362 testSub();
363 testNegate();
364 testMul();
365 testDiv();
366 testComparison();
367 testScale();
368 testClamp();
369 testAbs();
370 testMin();
371 testMax();
372 testSqrt();
373 testReciprocal();
374 testReciprocalSqrt();
375 }
376 }
OLDNEW
« no previous file with comments | « tests/lib/typeddata/float32x4_list_test.dart ('k') | tests/lib/typeddata/float32x4_unbox_regress_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698