Add new iterators test
[mono.git] / mcs / tests / 2test-7.cs
1 using System;
2 using System.Collections;
3
4 struct S {
5         int j;
6         
7         public IEnumerable Get (int a)
8         {
9                 Console.WriteLine ("Sending: " + a);
10                 yield return a;
11                 j = 10;
12                 Console.WriteLine ("Sending: " + j);
13                 yield return j;
14         }
15
16         public static IEnumerable GetS (int a)
17         {
18                 yield return 100;
19                 yield return a;
20                 yield return 1000;
21         }
22 }
23
24 class X {
25         IEnumerable Get (int a)
26         {
27                 yield return 1;
28                 yield return 2;
29                 yield return a;
30         }
31
32         static IEnumerable GetS (int a)
33         {
34                 yield return a;
35                 yield return a;
36                 yield return 1;
37         }
38         
39         static int Main ()
40         {
41                 X y = new X ();
42
43                 int total = 0;
44                 foreach (int x in y.Get (5)){
45                         total += x;
46                 }
47                 if (total != 8)
48                         return 1;
49
50                 total = 0;
51                 foreach (int x in GetS (3)){
52                         total += x;
53                 }
54                 if (total != 7)
55                         return 2;
56
57                 S s = new S();
58                 total = 0;
59                 foreach (int x in s.Get (100)){
60                         Console.WriteLine ("Got: " + x);
61                         total += x;
62                 }
63                 if (total != 110)
64                         return 3;
65
66                 total = 0;
67                 foreach (int x in S.GetS (1)){
68                         total += x;
69                 }
70                 if (total != 1101)
71                         return 4;
72                 
73                 Console.WriteLine ("OK");
74                 return 0;
75         }
76 }