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

Commit318d7ef

Browse files
committed
Add tuple comparison operator tests (2/6)
1 parent51f1f12 commit318d7ef

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎src/embed_tests/TestOperator.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,25 @@ public OperableObject(int num)
212212
return(a.Num>=b);
213213
}
214214

215+
publicstaticbooloperator>=(OperableObjecta,PyObjectb)
216+
{
217+
using(Py.GIL())
218+
{
219+
// Assuming b is a tuple, take the first element.
220+
intbNum=(int)b.ToArray()[0].AsManagedObject(typeof(int));
221+
returna.Num>=bNum;
222+
}
223+
}
224+
publicstaticbooloperator<=(OperableObjecta,PyObjectb)
225+
{
226+
using(Py.GIL())
227+
{
228+
// Assuming b is a tuple, take the first element.
229+
intbNum=(int)b.ToArray()[0].AsManagedObject(typeof(int));
230+
returna.Num<=bNum;
231+
}
232+
}
233+
215234
publicstaticbooloperator<(inta,OperableObjectb)
216235
{
217236
return(a<b.Num);
@@ -391,6 +410,27 @@ public void ForwardOperatorOverloads()
391410
");
392411
}
393412

413+
[Test]
414+
publicvoidTupleComparisonOperatorOverloads()
415+
{
416+
stringname=string.Format("{0}.{1}",
417+
typeof(OperableObject).DeclaringType.Name,
418+
typeof(OperableObject).Name);
419+
stringmodule=MethodBase.GetCurrentMethod().DeclaringType.Namespace;
420+
PythonEngine.Exec($@"
421+
from{module} import *
422+
cls ={name}
423+
a = cls(2)
424+
b = (1, 2)
425+
426+
c = a >= b
427+
assert c == (a.Num >= b[0])
428+
429+
c = a <= b
430+
assert c == (a.Num <= b[0])
431+
");
432+
}
433+
394434

395435
[Test]
396436
publicvoidReverseOperatorOverloads()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp