Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2fe1de7

Browse files
committed
Add tests for logical (bool) comparison operators
1 parentad2b377 commit2fe1de7

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

‎src/embed_tests/TestOperator.cs

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,58 @@ public OperableObject(int num)
121121
returnnewOperableObject(a.Num^b);
122122
}
123123

124+
publicstaticbooloperator<=(inta,OperableObjectb)
125+
{
126+
return(a<=b.Num);
127+
}
128+
publicstaticbooloperator<=(OperableObjecta,OperableObjectb)
129+
{
130+
return(a.Num<=b.Num);
131+
}
132+
publicstaticbooloperator<=(OperableObjecta,intb)
133+
{
134+
return(a.Num<=b);
135+
}
136+
137+
publicstaticbooloperator>=(inta,OperableObjectb)
138+
{
139+
return(a>=b.Num);
140+
}
141+
publicstaticbooloperator>=(OperableObjecta,OperableObjectb)
142+
{
143+
return(a.Num>=b.Num);
144+
}
145+
publicstaticbooloperator>=(OperableObjecta,intb)
146+
{
147+
return(a.Num>=b);
148+
}
149+
150+
publicstaticbooloperator<(inta,OperableObjectb)
151+
{
152+
return(a<b.Num);
153+
}
154+
publicstaticbooloperator<(OperableObjecta,OperableObjectb)
155+
{
156+
return(a.Num<b.Num);
157+
}
158+
publicstaticbooloperator<(OperableObjecta,intb)
159+
{
160+
return(a.Num<b);
161+
}
162+
163+
publicstaticbooloperator>(inta,OperableObjectb)
164+
{
165+
return(a>b.Num);
166+
}
167+
publicstaticbooloperator>(OperableObjecta,OperableObjectb)
168+
{
169+
return(a.Num>b.Num);
170+
}
171+
publicstaticbooloperator>(OperableObjecta,intb)
172+
{
173+
return(a.Num>b);
174+
}
175+
124176
publicstaticOperableObjectoperator<<(OperableObjecta,intoffset)
125177
{
126178
returnnewOperableObject(a.Num<<offset);
@@ -133,7 +185,7 @@ public OperableObject(int num)
133185
}
134186

135187
[Test]
136-
publicvoidOperatorOverloads()
188+
publicvoidSymmetricalOperatorOverloads()
137189
{
138190
stringname=string.Format("{0}.{1}",
139191
typeof(OperableObject).DeclaringType.Name,
@@ -165,6 +217,18 @@ public void OperatorOverloads()
165217
166218
c = a ^ b
167219
assert c.Num == a.Num ^ b.Num
220+
221+
c = a <= b
222+
assert c == (a.Num <= b.Num)
223+
224+
c = a >= b
225+
assert c == (a.Num >= b.Num)
226+
227+
c = a < b
228+
assert c == (a.Num < b.Num)
229+
230+
c = a > b
231+
assert c == (a.Num > b.Num)
168232
");
169233
}
170234
[Test]
@@ -200,6 +264,18 @@ public void ForwardOperatorOverloads()
200264
201265
c = a ^ b
202266
assert c.Num == a.Num ^ b
267+
268+
c = a <= b
269+
assert c == (a.Num <= b)
270+
271+
c = a >= b
272+
assert c == (a.Num >= b)
273+
274+
c = a < b
275+
assert c == (a.Num < b)
276+
277+
c = a > b
278+
assert c == (a.Num > b)
203279
");
204280
}
205281

@@ -235,6 +311,18 @@ public void ReverseOperatorOverloads()
235311
236312
c = a ^ b
237313
assert c.Num == a ^ b.Num
314+
315+
c = a <= b
316+
assert c == (a <= b.Num)
317+
318+
c = a >= b
319+
assert c == (a >= b.Num)
320+
321+
c = a < b
322+
assert c == (a < b.Num)
323+
324+
c = a > b
325+
assert c == (a > b.Num)
238326
");
239327

240328
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp