New test.
[mono.git] / mcs / tests / test-44.cs
1 //
2 // This test shows that the current way in which we handle blocks
3 // and statements is broken.  The b [q,w] code is only executed 10
4 // times instead of a 100
5 //
6 using System;
7
8 class X {
9
10         static int dob (int [,]b)
11         {
12                 int total = 0;
13                 
14                 foreach (int i in b)
15                         total += i;
16
17                 return total;
18         }
19
20         //
21         // This tests typecasting from an object to an array of ints
22         // and then doing foreach
23         //
24         static int count (object o)
25         {
26                 int total = 0;
27
28                 foreach (int i in (int []) o)
29                         total += i;
30
31                 return total;
32         }
33         
34         static int Main ()
35         {
36                 int [,] b = new int [10,10];
37
38                 for (int q = 0; q < 10; q++)
39                         for (int w = 0; w < 10; w++)
40                                 b [q,w] = q * 10 + w;
41
42                 if (dob (b) != 4950)
43                         return 1;
44
45                 int [] a = new int [10];
46                 for (int i = 0; i < 10; i++)
47                         a [i] = 2;
48
49                 if (count (a) != 20)
50                         return 2;
51                 
52                 return 0;
53         }
54 }
55