Initial set of Ward sgen annotations (#5705)
[mono.git] / mcs / tests / test-43.cs
old mode 100755 (executable)
new mode 100644 (file)
index f86fa3b..0af13f1
@@ -1,6 +1,7 @@
 //
 // This test is used for testing the foreach array support
 //
+using System;
 
 class X {
 
@@ -14,7 +15,64 @@ class X {
                return total;
        }
 
-       static int Main ()
+       static int test_continue (int [] a)
+       {
+               int total = 0;
+               int j = 0;
+               
+               foreach (int i in a){
+                       j++;
+                       if (j == 5)
+                               continue;
+                       total += i;
+               }
+
+               return total;
+       }
+
+       //
+       // test that we can iterate on doubles, with a float contorl
+       // variable (this excercises the conversion operator and the
+       // proper loading on the array
+       //
+       static bool test_double (double [] d)
+       {
+               float t = 1.0F;
+               t += 2.0F + 3.0F;
+               float x = 0;
+               
+               foreach (float f in d){
+                       x += f;
+               }
+               return x == t;
+       }
+       
+       static int test_break (int [] a)
+       {
+               int total = 0;
+               int j = 0;
+
+               foreach (int i in a){
+                       j++;
+                       if (j == 5)
+                               break;
+                       total += i;
+               }
+
+               return total;
+       }
+
+       static bool test_multi (int [,] d)
+       {
+               int total = 0;
+               
+               foreach (int a in d){
+                       total += a;
+               }
+               return (total == 46);
+       }
+       
+       public static int Main ()
        {
                int [] a = new int [10];
                int [] b = new int [2];
@@ -31,6 +89,28 @@ class X {
                if (test_single (b) != 101)
                        return 2;
 
+               if (test_continue (a) != 131){
+                       Console.WriteLine ("Expecting: 131, got " + test_continue (a));
+                       return 3;
+               }
+               
+               if (test_break (a) != 46){
+                       Console.WriteLine ("Expecting: 46, got " + test_break (a));
+                       return 4;
+               }
+               
+               double [] d = new double [] { 1.0, 2.0, 3.0 };
+               if (!test_double (d))
+                       return 5;
+
+               int [,] jj = new int [2,2];
+               jj [0,0] = 10;
+               jj [0,1] = 2;
+               jj [1,0] = 30;
+               jj [1,1] = 4;
+               if (!test_multi (jj))
+                       return 6;
+                       
                return 0;
        }
 }