File: array.cs

package info (click to toggle)
mono-reference-assemblies 3.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 604,240 kB
  • ctags: 625,505
  • sloc: cs: 3,967,741; xml: 2,793,081; ansic: 418,042; java: 60,435; sh: 14,833; makefile: 11,576; sql: 7,956; perl: 1,467; cpp: 1,446; yacc: 1,203; python: 598; asm: 422; sed: 16; php: 1
file content (127 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Runtime.InteropServices;

public class Test {

	static void puts (string s)
	{
		Console.WriteLine (s);
	}

	public static int jagged ()
	{
		int[][] j2 = new int [3][];

		// does not work 
		// j2 [0] = new int[] {1, 2, 3};
		// j2 [1] = new int[] {1, 2, 3, 4, 5, 6};
		// j2 [2] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};

		j2 [0] = new int[3];
		j2 [1] = new int[6];
		j2 [2] = new int[9];

		for (int i = 0; i < j2.Length; i++)
			for (int j = 0; j < (i+1)*3; j++)
				j2 [i][j] = j;

		for (int i = 0; i < j2.Length; i++)
			for (int j = 0; j < (i+1)*3; j++)
				if (j2 [i][j] != j)
					return 1;
		return 0;
	}

	public static int stest ()
	{
		string[] sa = new string[32];

		sa [0] = "This";
		sa [2] = "is";
		sa [10] = "a";
		sa [20] = "stupid";
		sa [21] = "Test";

		for (int i = 0; i < sa.Length; i++){
			if (sa [i] != null)
				puts (sa [i]);
		}
		
		return 0;
	}
	
	public static int atest2 ()
	{
		int[,] ia = new int[32,32];

		for (int i = 0; i <ia.GetLength (0); i++)
			ia [i,i] = i*i;

		for (int i = 0; i <ia.GetLength (0); i++)
			if (ia [i,i] != i*i)
				return 1;

		for (int i = 0; i <ia.GetLength (0); i++)
			ia.SetValue (i*i*i, i, i);

		for (int i = 0; i <ia.GetLength (0); i++)
			if ((int)ia.GetValue (i, i) != i*i*i)
				return 1;

		return 0;
	}
	
	public static int atest ()
	{
		int[] ia = new int[32];

		for (int i = 0; i <ia.Length; i++)
			ia [i] = i*i;
		
		for (int i = 0; i <ia.Length; i++)
			if (ia [i] != i*i)
				return 1;
		
		if (ia.Rank != 1)
			return 2;

		if (ia.GetValue (2) == null)
			return 3;

		for (int i = 0; i <ia.Length; i++)
			ia.SetValue (i*i*i, i);

		for (int i = 0; i <ia.Length; i++)
			if ((int)ia.GetValue (i) != i*i*i){
				puts ("Crap: " + i + " " + (int) ia.GetValue (i) );

				return 4;
			}
		
		return 0;
	}
	

	public static int Main () {
		puts ("a");
		if (atest () != 0)
			return atest ();
	 	puts ("b");	
		if (atest2 () != 0)
			return 1;
		puts ("c");
		if (atest2 () != 0)
			return 1;
		puts ("d");	
		if (stest () != 0)
			return 1;
	 	puts ("e");	
		if (jagged () != 0)
			return 1;
		
		
		return 0;
	}
}