[netcore] Disable a flaky test on interpreter (#18904)
[mono-project.git] / mono / tests / array.cs
blob7b3a68247a8f16df2176a2622b2b58b6a91615af
1 using System;
2 using System.Collections.Generic;
3 using System.Runtime.InteropServices;
5 public class Test {
7 public static int test_0_jagged ()
9 int[][] j2 = new int [3][];
11 // does not work
12 // j2 [0] = new int[] {1, 2, 3};
13 // j2 [1] = new int[] {1, 2, 3, 4, 5, 6};
14 // j2 [2] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
16 j2 [0] = new int[3];
17 j2 [1] = new int[6];
18 j2 [2] = new int[9];
20 for (int i = 0; i < j2.Length; i++)
21 for (int j = 0; j < (i+1)*3; j++)
22 j2 [i][j] = j;
24 for (int i = 0; i < j2.Length; i++)
25 for (int j = 0; j < (i+1)*3; j++)
26 if (j2 [i][j] != j)
27 return 1;
28 return 0;
31 public static int test_0_stest ()
33 string[] sa = new string[32];
35 sa [0] = "This";
36 sa [2] = "is";
37 sa [10] = "a";
38 sa [20] = "stupid";
39 sa [21] = "Test";
41 for (int i = 0; i < sa.Length; i++){
42 if (sa [i] != null)
43 Console.WriteLine (sa [i]);
46 return 0;
49 public static int test_0_atest2 ()
51 int[,] ia = new int[32,32];
53 for (int i = 0; i <ia.GetLength (0); i++)
54 ia [i,i] = i*i;
56 for (int i = 0; i <ia.GetLength (0); i++)
57 if (ia [i,i] != i*i)
58 return 1;
60 for (int i = 0; i <ia.GetLength (0); i++)
61 ia.SetValue (i*i*i, i, i);
63 for (int i = 0; i <ia.GetLength (0); i++)
64 if ((int)ia.GetValue (i, i) != i*i*i)
65 return 1;
67 return 0;
70 public static int test_0_atest ()
72 int[] ia = new int[32];
74 for (int i = 0; i <ia.Length; i++)
75 ia [i] = i*i;
77 for (int i = 0; i <ia.Length; i++)
78 if (ia [i] != i*i)
79 return 1;
81 if (ia.Rank != 1)
82 return 2;
84 if (ia.GetValue (2) == null)
85 return 3;
87 for (int i = 0; i <ia.Length; i++)
88 ia.SetValue (i*i*i, i);
90 for (int i = 0; i <ia.Length; i++)
91 if ((int)ia.GetValue (i) != i*i*i){
92 Console.WriteLine ("Crap: " + i + " " + (int) ia.GetValue (i) );
94 return 4;
97 return 0;
100 enum Foo { a, b };
101 public static int test_0_enum_array_casting () {
102 var x = new Foo[10];
103 try {
104 var y = (IReadOnlyList<int>)(object)x;
105 } catch (Exception e) {
106 return 1;
108 try {
109 var y = (IList<int>)(object)x;
110 } catch (Exception e) {
111 return 2;
114 try {
115 var y = (ICollection<int>)(object)x;
116 } catch (Exception e) {
117 return 3;
120 try {
121 var y = (IEnumerable<int>)(object)x;
122 } catch (Exception e) {
123 return 4;
126 try {
127 var y = (IReadOnlyCollection<int>)(object)x;
128 } catch (Exception e) {
129 return 5;
131 return 0;
134 public static int Main (string[] args) {
135 return TestDriver.RunTests (typeof (Test), args);