Merge pull request #1861 from saper/home-override
[mono-project.git] / mcs / tests / test-43.cs
blob0af13f130c8af3dda77d894fd62fd496ac99f750
1 //
2 // This test is used for testing the foreach array support
3 //
4 using System;
6 class X {
8 static int test_single (int [] a)
10 int total = 0;
12 foreach (int i in a)
13 total += i;
15 return total;
18 static int test_continue (int [] a)
20 int total = 0;
21 int j = 0;
23 foreach (int i in a){
24 j++;
25 if (j == 5)
26 continue;
27 total += i;
30 return total;
34 // test that we can iterate on doubles, with a float contorl
35 // variable (this excercises the conversion operator and the
36 // proper loading on the array
38 static bool test_double (double [] d)
40 float t = 1.0F;
41 t += 2.0F + 3.0F;
42 float x = 0;
44 foreach (float f in d){
45 x += f;
47 return x == t;
50 static int test_break (int [] a)
52 int total = 0;
53 int j = 0;
55 foreach (int i in a){
56 j++;
57 if (j == 5)
58 break;
59 total += i;
62 return total;
65 static bool test_multi (int [,] d)
67 int total = 0;
69 foreach (int a in d){
70 total += a;
72 return (total == 46);
75 public static int Main ()
77 int [] a = new int [10];
78 int [] b = new int [2];
80 for (int i = 0; i < 10; i++)
81 a [i] = 10 + i;
83 for (int j = 0; j < 2; j++)
84 b [j] = 50 + j;
86 if (test_single (a) != 145)
87 return 1;
89 if (test_single (b) != 101)
90 return 2;
92 if (test_continue (a) != 131){
93 Console.WriteLine ("Expecting: 131, got " + test_continue (a));
94 return 3;
97 if (test_break (a) != 46){
98 Console.WriteLine ("Expecting: 46, got " + test_break (a));
99 return 4;
102 double [] d = new double [] { 1.0, 2.0, 3.0 };
103 if (!test_double (d))
104 return 5;
106 int [,] jj = new int [2,2];
107 jj [0,0] = 10;
108 jj [0,1] = 2;
109 jj [1,0] = 30;
110 jj [1,1] = 4;
111 if (!test_multi (jj))
112 return 6;
114 return 0;