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

test-7.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8d27a6dec75a797514cddef3046d6492ac945db6 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;

namespace Mine {

	public class MyBoolean {
		public static implicit operator bool (MyBoolean x)
		{
			return true;
		}
	}

	public class MyTrueFalse {
		public static bool operator true (MyTrueFalse i)
		{
			return true;
		}
		
		public static bool operator false (MyTrueFalse i)
		{
			return false;
		}
	}
	
	public class Blah {

		public int i;

		public static int Main ()
		{
			Blah k, l;

			k = new Blah (2) + new Blah (3);
			if (k.i != 5)
				return 1;
			
			k = ~ new Blah (5);
			if (k.i != -6)
				return 1;
			
			
			k = + new Blah (4);
			if (k.i != 4)
				return 1;
			
			k = - new Blah (21);
			if (k.i != -21)
				return 1;

			k = new Blah (22) - new Blah (21);
			if (k.i != 1)
				return 1;

			if (!k)
				Console.WriteLine ("! returned true");

			int number = k;
			if (number != 1)
				return 1;
			
			k++;	
			++k;

			if (k)
				Console.WriteLine ("k is definitely true");

			k = new Blah (30);

			double f = (double) k;

			if (f != 30.0)
				return 1;

			int i = new Blah (5) * new Blah (10);

			if (i != 50)
				return 1;

			k = new Blah (50);
			l = new Blah (10);
			
			i = k / l;

			if (i != 5)
				return 1;

			i = k % l;

			if (i != 0)
				return 1;

			MyBoolean myb = new MyBoolean ();

			if (!myb)
				return 10;

			//
			// Tests the conditional operator invoking operator true
			MyTrueFalse mf = new MyTrueFalse ();
			int x = mf ? 1 : 2;
			if (x != 1)
				return 11;
			
			Console.WriteLine ("Test passed");
			return 0;
		}
	
		public Blah (int v)
		{
			i = v;
		}
	
		public static Blah operator + (Blah i, Blah j)
		{
			Blah b = new Blah (i.i + j.i);
			Console.WriteLine ("Overload binary + operator");
			return b;
		}

		public static Blah operator + (Blah i)
		{
			Console.WriteLine ("Overload unary + operator");
			return new Blah (i.i);
		}

		public static Blah operator - (Blah i)
		{
			Console.WriteLine ("Overloaded unary - operator");
			return new Blah (- i.i);
		}

		public static Blah operator - (Blah i, Blah j)
		{
			Blah b = new Blah (i.i - j.i);
			Console.WriteLine ("Overloaded binary - operator");
			return b;
		}

		public static int operator * (Blah i, Blah j)
		{
			Console.WriteLine ("Overloaded binary * operator");
			return i.i * j.i;
		}

		public static int operator / (Blah i, Blah j)
		{
			Console.WriteLine ("Overloaded binary / operator");
			return i.i / j.i;
		}

		public static int operator % (Blah i, Blah j)
		{
			Console.WriteLine ("Overloaded binary % operator");
			return i.i % j.i;
		}
		
		public static Blah operator ~ (Blah i)
		{
			Console.WriteLine ("Overloaded ~ operator");
			return new Blah (~i.i);
		}
	
		public static bool operator ! (Blah i)
		{
			Console.WriteLine ("Overloaded ! operator");
			return (i.i == 1);
		}

		public static Blah operator ++ (Blah i)
		{
			Blah b = new Blah (i.i + 1);
			Console.WriteLine ("Incrementing i");
			return b;
		}

		public static Blah operator -- (Blah i)
		{
			Blah b = new Blah (i.i - 1);
			Console.WriteLine ("Decrementing i");
			return b;
		}	
	
		public static bool operator true (Blah i)
		{
			Console.WriteLine ("Overloaded true operator");
			return (i.i == 3);
		}

		public static bool operator false (Blah i)
		{
			Console.WriteLine ("Overloaded false operator");
			return (i.i != 1);
		}	
	
		public static implicit operator int (Blah i) 
		{	
			Console.WriteLine ("Converting implicitly from Blah->int");
			return i.i;
		}

		public static explicit operator double (Blah i)
		{
			Console.WriteLine ("Converting explicitly from Blah->double");
			return (double) i.i;
		}

	}

}