diff --git a/Examples/test-suite/python/python_builtin_runme.py b/Examples/test-suite/python/python_builtin_runme.py index 7afab2a39..26e757ca7 100644 --- a/Examples/test-suite/python/python_builtin_runme.py +++ b/Examples/test-suite/python/python_builtin_runme.py @@ -83,6 +83,7 @@ if is_python_builtin(): if MyClass.less_than_counts != 6: raise RuntimeError("python:compare feature not working") +# Test 6 sa = SimpleArray(5) elements = [x for x in sa] if elements != [0, 10, 20, 30, 40]: @@ -96,3 +97,17 @@ subslice = sa[1:3] elements = [x for x in subslice] if elements != [10, 20]: raise RuntimeError("slice not working") + +# Test 7 mapping to Python's pow +x = ANumber(2) +y = ANumber(4) +z = x ** y +if z.Value() != 16: + raise RuntimeError("x ** y wrong") +z = pow(x, y) +if z.Value() != 16: + raise RuntimeError("pow(x, y) wrong") +z = ANumber(9) +z = pow(x, y, z) +if z.Value() != 7: + raise RuntimeError("pow(x, y, z) wrong") diff --git a/Examples/test-suite/python_builtin.i b/Examples/test-suite/python_builtin.i index c48867853..f47e937c8 100644 --- a/Examples/test-suite/python_builtin.i +++ b/Examples/test-suite/python_builtin.i @@ -226,3 +226,22 @@ void Dealloc2Destroyer(PyObject *v) { }; %} +// Test 7 mapping to Python's pow +%pybinoperator(__pow__, ANumber::power, ternaryfunc, nb_power); + +%inline %{ +class ANumber { + int num; +public: + ANumber(int d = 0) : num(d) {} + ANumber __pow__(const ANumber &other, const ANumber *x) const { + int val = (int)pow(num, other.num); + val = x ? val % x->num : val; + return ANumber(val); + } + int Value() const { + return num; + } +}; +%} +