2010-05-19 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / test-233.cs
blob94dda70a7120d54dfcae3d411108a039ca0d4be1
1 using System;
2 using System.Reflection;
4 class Tests {
6 static int Main () {
7 return TestDriver.RunTests (typeof (Tests));
10 static int test_0_beq () {
11 double a = 2.0;
12 if (a != 2.0)
13 return 1;
14 return 0;
17 static int test_0_bne_un () {
18 double a = 2.0;
19 if (a == 1.0)
20 return 1;
21 return 0;
24 static int test_0_conv_r8 () {
25 double a = 2;
26 if (a != 2.0)
27 return 1;
28 return 0;
31 static int test_0_conv_i () {
32 double a = 2.0;
33 int i = (int)a;
34 if (i != 2)
35 return 1;
36 uint ui = (uint)a;
37 if (ui != 2)
38 return 2;
39 short s = (short)a;
40 if (s != 2)
41 return 3;
42 ushort us = (ushort)a;
43 if (us != 2)
44 return 4;
45 byte b = (byte)a;
46 if (b != 2)
47 return 5;
48 return 0;
51 static int test_5_conv_r4 () {
52 int i = 5;
53 float f = (float)i;
54 return (int)f;
57 static int test_5_double_conv_r4 () {
58 double d = 5.0;
59 float f = (float)d;
60 return (int)f;
63 static int test_5_float_conv_r8 () {
64 float f = 5.0F;
65 double d = (double)f;
66 return (int)d;
69 static int test_5_conv_r8 () {
70 int i = 5;
71 double f = (double)i;
72 return (int)f;
75 static int test_5_add () {
76 double a = 2.0;
77 double b = 3.0;
78 return (int)(a + b);
81 static int test_5_sub () {
82 double a = 8.0;
83 double b = 3.0;
84 return (int)(a - b);
87 static int test_24_mul () {
88 double a = 8.0;
89 double b = 3.0;
90 return (int)(a * b);
93 static int test_4_div () {
94 double a = 8.0;
95 double b = 2.0;
96 return (int)(a / b);
99 static int test_2_rem () {
100 double a = 8.0;
101 double b = 3.0;
102 return (int)(a % b);
105 static int test_2_neg () {
106 double a = -2.0;
107 return (int)(-a);
110 static int test_46_float_add_spill () {
111 // we overflow the FP stack
112 double a = 1;
113 double b = 2;
114 double c = 3;
115 double d = 4;
116 double e = 5;
117 double f = 6;
118 double g = 7;
119 double h = 8;
120 double i = 9;
122 return (int)(1.0 + (a + (b + (c + (d + (e + (f + (g + (h + i)))))))));
125 static int test_362880_float_mul_spill () {
126 // we overflow the FP stack
127 double a = 1;
128 double b = 2;
129 double c = 3;
130 double d = 4;
131 double e = 5;
132 double f = 6;
133 double g = 7;
134 double h = 8;
135 double i = 9;
137 return (int)(1.0 * (a * (b * (c * (d * (e * (f * (g * (h * i)))))))));
140 static int test_4_long_cast () {
141 long a = 1000;
142 double d = (double)a;
143 long b = (long)d;
144 if (b != 1000)
145 return 0;
146 return 4;
149 /* FIXME: This only works on little-endian machines */
151 static unsafe int test_2_negative_zero () {
152 int result = 0;
153 double d = -0.0;
154 float f = -0.0f;
156 byte *ptr = (byte*)&d;
157 if (ptr [7] == 0)
158 return result;
159 result ++;
161 ptr = (byte*)&f;
162 if (ptr [3] == 0)
163 return result;
164 result ++;
166 return result;
170 static int test_16_float_cmp () {
171 double a = 2.0;
172 double b = 1.0;
173 int result = 0;
174 bool val;
176 val = a == a;
177 if (!val)
178 return result;
179 result++;
181 val = (a != a);
182 if (val)
183 return result;
184 result++;
186 val = a < a;
187 if (val)
188 return result;
189 result++;
191 val = a > a;
192 if (val)
193 return result;
194 result++;
196 val = a <= a;
197 if (!val)
198 return result;
199 result++;
201 val = a >= a;
202 if (!val)
203 return result;
204 result++;
206 val = b == a;
207 if (val)
208 return result;
209 result++;
211 val = b < a;
212 if (!val)
213 return result;
214 result++;
216 val = b > a;
217 if (val)
218 return result;
219 result++;
221 val = b <= a;
222 if (!val)
223 return result;
224 result++;
226 val = b >= a;
227 if (val)
228 return result;
229 result++;
231 val = a == b;
232 if (val)
233 return result;
234 result++;
236 val = a < b;
237 if (val)
238 return result;
239 result++;
241 val = a > b;
242 if (!val)
243 return result;
244 result++;
246 val = a <= b;
247 if (val)
248 return result;
249 result++;
251 val = a >= b;
252 if (!val)
253 return result;
254 result++;
256 return result;
259 static int test_15_float_cmp_un () {
260 double a = Double.NaN;
261 double b = 1.0;
262 int result = 0;
263 bool val;
265 val = a == a;
266 if (val)
267 return result;
268 result++;
270 val = a < a;
271 if (val)
272 return result;
273 result++;
275 val = a > a;
276 if (val)
277 return result;
278 result++;
280 val = a <= a;
281 if (val)
282 return result;
283 result++;
285 val = a >= a;
286 if (val)
287 return result;
288 result++;
290 val = b == a;
291 if (val)
292 return result;
293 result++;
295 val = b < a;
296 if (val)
297 return result;
298 result++;
300 val = b > a;
301 if (val)
302 return result;
303 result++;
305 val = b <= a;
306 if (val)
307 return result;
308 result++;
310 val = b >= a;
311 if (val)
312 return result;
313 result++;
315 val = a == b;
316 if (val)
317 return result;
318 result++;
320 val = a < b;
321 if (val)
322 return result;
323 result++;
325 val = a > b;
326 if (val)
327 return result;
328 result++;
330 val = a <= b;
331 if (val)
332 return result;
333 result++;
335 val = a >= b;
336 if (val)
337 return result;
338 result++;
340 return result;
343 static int test_15_float_branch () {
344 double a = 2.0;
345 double b = 1.0;
346 int result = 0;
348 if (!(a == a))
349 return result;
350 result++;
352 if (a < a)
353 return result;
354 result++;
356 if (a > a)
357 return result;
358 result++;
360 if (!(a <= a))
361 return result;
362 result++;
364 if (!(a >= a))
365 return result;
366 result++;
368 if (b == a)
369 return result;
370 result++;
372 if (!(b < a))
373 return result;
374 result++;
376 if (b > a)
377 return result;
378 result++;
380 if (!(b <= a))
381 return result;
382 result++;
384 if (b >= a)
385 return result;
386 result++;
388 if (a == b)
389 return result;
390 result++;
392 if (a < b)
393 return result;
394 result++;
396 if (!(a > b))
397 return result;
398 result++;
400 if (a <= b)
401 return result;
402 result++;
404 if (!(a >= b))
405 return result;
406 result++;
408 return result;
411 static int test_15_float_branch_un () {
412 double a = Double.NaN;
413 double b = 1.0;
414 int result = 0;
416 if (a == a)
417 return result;
418 result++;
420 if (a < a)
421 return result;
422 result++;
424 if (a > a)
425 return result;
426 result++;
428 if (a <= a)
429 return result;
430 result++;
432 if (a >= a)
433 return result;
434 result++;
436 if (b == a)
437 return result;
438 result++;
440 if (b < a)
441 return result;
442 result++;
444 if (b > a)
445 return result;
446 result++;
448 if (b <= a)
449 return result;
450 result++;
452 if (b >= a)
453 return result;
454 result++;
456 if (a == b)
457 return result;
458 result++;
460 if (a < b)
461 return result;
462 result++;
464 if (a > b)
465 return result;
466 result++;
468 if (a <= b)
469 return result;
470 result++;
472 if (a >= b)
473 return result;
474 result++;
476 return result;
481 public class TestDriver {
483 static public int RunTests (Type type, string[] args) {
484 int failed = 0, ran = 0;
485 int result, expected, elen;
486 int i, j;
487 string name;
488 MethodInfo[] methods;
489 bool do_timings = false;
490 int tms = 0;
491 DateTime start, end = DateTime.Now;
493 if (args != null && args.Length > 0) {
494 for (j = 0; j < args.Length; j++) {
495 if (args [j] == "--time") {
496 do_timings = true;
497 string[] new_args = new string [args.Length - 1];
498 for (i = 0; i < j; ++i)
499 new_args [i] = args [i];
500 j++;
501 for (; j < args.Length; ++i, ++j)
502 new_args [i] = args [j];
503 args = new_args;
504 break;
508 methods = type.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static);
509 for (i = 0; i < methods.Length; ++i) {
510 name = methods [i].Name;
511 if (!name.StartsWith ("test_"))
512 continue;
513 if (args != null && args.Length > 0) {
514 bool found = false;
515 for (j = 0; j < args.Length; j++) {
516 if (name.EndsWith (args [j])) {
517 found = true;
518 break;
521 if (!found)
522 continue;
524 for (j = 5; j < name.Length; ++j)
525 if (!Char.IsDigit (name [j]))
526 break;
527 expected = Int32.Parse (name.Substring (5, j - 5));
528 start = DateTime.Now;
529 result = (int)methods [i].Invoke (null, null);
530 if (do_timings) {
531 end = DateTime.Now;
532 long tdiff = end.Ticks - start.Ticks;
533 int mdiff = (int)tdiff/10000;
534 tms += mdiff;
535 Console.WriteLine ("{0} took {1} ms", name, mdiff);
537 ran++;
538 if (result != expected) {
539 failed++;
540 Console.WriteLine ("{0} failed: got {1}, expected {2}", name, result, expected);
544 if (do_timings) {
545 Console.WriteLine ("Total ms: {0}", tms);
547 Console.WriteLine ("Regression tests: {0} ran, {1} failed in {2}", ran, failed, type);
548 //Console.WriteLine ("Regression tests: {0} ran, {1} failed in [{2}]{3}", ran, failed, type.Assembly.GetName().Name, type);
549 return failed;
551 static public int RunTests (Type type) {
552 return RunTests (type, null);