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

Commitd19e1bd

Browse files
committed
Add tests for logical (bool) comparison operators
1 parent0fa8d43 commitd19e1bd

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
@@ -149,6 +149,58 @@ public OperableObject(int num)
149149
returnnewOperableObject(a.Num^b);
150150
}
151151

152+
publicstaticbooloperator<=(inta,OperableObjectb)
153+
{
154+
return(a<=b.Num);
155+
}
156+
publicstaticbooloperator<=(OperableObjecta,OperableObjectb)
157+
{
158+
return(a.Num<=b.Num);
159+
}
160+
publicstaticbooloperator<=(OperableObjecta,intb)
161+
{
162+
return(a.Num<=b);
163+
}
164+
165+
publicstaticbooloperator>=(inta,OperableObjectb)
166+
{
167+
return(a>=b.Num);
168+
}
169+
publicstaticbooloperator>=(OperableObjecta,OperableObjectb)
170+
{
171+
return(a.Num>=b.Num);
172+
}
173+
publicstaticbooloperator>=(OperableObjecta,intb)
174+
{
175+
return(a.Num>=b);
176+
}
177+
178+
publicstaticbooloperator<(inta,OperableObjectb)
179+
{
180+
return(a<b.Num);
181+
}
182+
publicstaticbooloperator<(OperableObjecta,OperableObjectb)
183+
{
184+
return(a.Num<b.Num);
185+
}
186+
publicstaticbooloperator<(OperableObjecta,intb)
187+
{
188+
return(a.Num<b);
189+
}
190+
191+
publicstaticbooloperator>(inta,OperableObjectb)
192+
{
193+
return(a>b.Num);
194+
}
195+
publicstaticbooloperator>(OperableObjecta,OperableObjectb)
196+
{
197+
return(a.Num>b.Num);
198+
}
199+
publicstaticbooloperator>(OperableObjecta,intb)
200+
{
201+
return(a.Num>b);
202+
}
203+
152204
publicstaticOperableObjectoperator<<(OperableObjecta,intoffset)
153205
{
154206
returnnewOperableObject(a.Num<<offset);
@@ -161,7 +213,7 @@ public OperableObject(int num)
161213
}
162214

163215
[Test]
164-
publicvoidOperatorOverloads()
216+
publicvoidSymmetricalOperatorOverloads()
165217
{
166218
stringname=string.Format("{0}.{1}",
167219
typeof(OperableObject).DeclaringType.Name,
@@ -206,6 +258,18 @@ public void OperatorOverloads()
206258
207259
c = a ^ b
208260
assert c.Num == a.Num ^ b.Num
261+
262+
c = a <= b
263+
assert c == (a.Num <= b.Num)
264+
265+
c = a >= b
266+
assert c == (a.Num >= b.Num)
267+
268+
c = a < b
269+
assert c == (a.Num < b.Num)
270+
271+
c = a > b
272+
assert c == (a.Num > b.Num)
209273
");
210274
}
211275

@@ -263,6 +327,18 @@ public void ForwardOperatorOverloads()
263327
264328
c = a ^ b
265329
assert c.Num == a.Num ^ b
330+
331+
c = a <= b
332+
assert c == (a.Num <= b)
333+
334+
c = a >= b
335+
assert c == (a.Num >= b)
336+
337+
c = a < b
338+
assert c == (a.Num < b)
339+
340+
c = a > b
341+
assert c == (a.Num > b)
266342
");
267343
}
268344

@@ -304,6 +380,18 @@ public void ReverseOperatorOverloads()
304380
305381
c = a ^ b
306382
assert c.Num == a ^ b.Num
383+
384+
c = a <= b
385+
assert c == (a <= b.Num)
386+
387+
c = a >= b
388+
assert c == (a >= b.Num)
389+
390+
c = a < b
391+
assert c == (a < b.Num)
392+
393+
c = a > b
394+
assert c == (a > b.Num)
307395
");
308396

309397
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp