Added new test
[mono.git] / mcs / tests / test-43.cs
1 //
2 // This test is used for testing the foreach array support
3 //
4 using System;
5
6 class X {
7
8         static int test_single (int [] a)
9         {
10                 int total = 0;
11
12                 foreach (int i in a)
13                         total += i;
14
15                 return total;
16         }
17
18         static int test_continue (int [] a)
19         {
20                 int total = 0;
21                 int j = 0;
22                 
23                 foreach (int i in a){
24                         j++;
25                         if (j == 5)
26                                 continue;
27                         total += i;
28                 }
29
30                 return total;
31         }
32
33         static int test_break (int [] a)
34         {
35                 int total = 0;
36                 int j = 0;
37
38                 foreach (int i in a){
39                         j++;
40                         if (j == 5)
41                                 break;
42                         total += i;
43                 }
44
45                 return total;
46         }
47         
48         static int Main ()
49         {
50                 int [] a = new int [10];
51                 int [] b = new int [2];
52
53                 for (int i = 0; i < 10; i++)
54                         a [i] = 10 + i;
55
56                 for (int j = 0; j < 2; j++)
57                         b [j] = 50 + j;
58
59                 if (test_single (a) != 145)
60                         return 1;
61
62                 if (test_single (b) != 101)
63                         return 2;
64
65                 if (test_continue (a) != 131){
66                         Console.WriteLine ("Expecting: 131, got " + test_continue (a));
67                         return 3;
68                 }
69
70                 if (test_break (a) != 46){
71                         Console.WriteLine ("Expecting: 46, got " + test_break (a));
72                         return 4;
73                 }
74                 
75                 return 0;
76         }
77 }
78