Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-42.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 684324b8f934857bdcbb75ba1c352eba080d022d (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// This test exercises the various ways in which mutator operators can be
// used in C# and the various different scenarios that the compiler would
// have to deal with
//
// variables, linear arrays, multi-dimensional arrays, jagged arrays,
// properties, indexers and overloaded ++ and --
//

class X {

	public int v, p;
	public int idx;
	
	public int this [int n] {
		get {
			idx = n;
			return v;
		}
		set {
			idx = n;
			v = value;
		}
	}

	public int P {
		get {
			return p;
		}

		set {
			p = value;
		}
	}
	
}

class Z {
	int v;

	public Z P {
		get {
			return null;
		}

		set {
		}
	}
	
	static public Z operator ++ (Z v)
	{
		v.v++;
		return v;
	}
}

class Y {

	static int p_pre_increment (X x)
	{
		return ++x.P;
	}

	static int p_post_increment (X x)
	{
		return x.P++;
	}

	static int i_pre_increment (X x)
	{
		return ++x [100];
	}

	static int  i_post_increment (X x)
	{
		return x [14]++;
	}

	static Z overload_increment (Z z)
	{
		  return z++;
	}
	
	static Z overload_pre_increment (Z z)
	{
		  return ++z;
	}
	
	static Z ugly (Z z)
	{
		  return z.P++;
	}

	//
	// Tests the ++ and -- operators on integers
	//
	static int simple (int i)
	{
		if (++i != 11)
			return 1;
		if (--i != 10)
			return 2;
		if (i++ != 10)
			return 3;
		if (i-- != 11)
			return 4;
		return 0;
	}

	static int arrays ()
	{
		int [] a = new int [10];
		int i, j;
		
		for (i = 0; i < 10; i++)
			a [i]++;

		for (i = 0; i < 10; i++)
			if (a [i] != 1)
				return 100;

		int [,] b = new int [10,10];
		for (i = 0; i < 10; i++){
			for (j = 0; j < 10; j++){
				b [i,j] = i * 10 + j;
				if (i < 5)
					b [i,j]++;
				else
					++b [i,j];
			}
		}

		for (i = 0; i < 10; i++){
			for (j = 0; j < 10; j++){
				if (b [i,j] != i * 10 + (j + 1))
					return 101;
			}
		}
		
		return 0;
	}
	
	static int Main ()
	{
		X x = new X ();
		int c;
		
		if ((c = simple (10)) != 0)
			return c;
		
		if (i_pre_increment (x) != 1)
			return 5;
		
		if (x.idx != 100)
			return 6;
		
		if (i_post_increment (x) != 1)
			return 7;

		if (x.idx != 14)
			return 8;
		
		if (p_pre_increment (x) != 1)
			return 9;

		if (x.p != 1)
			return 10;
		
		if (p_post_increment (x) != 1)
			return 10;

		if (x.p != 2)
			return 11;

		Z z = new Z();

		overload_increment (z);

		arrays ();
		
		return 0;
	}
	
}