Skip to content

Commit b4050eb

Browse files
committed
Add test case
1 parent e4954f1 commit b4050eb

File tree

1 file changed

+32
-0
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests/cpyext

1 file changed

+32
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_object.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,38 @@ def test_int(self):
109109
tester = TestInt()
110110
assert int(tester) == 42
111111

112+
def test_float_binops(self):
113+
TestFloatBinop = CPyExtType("TestFloatBinop",
114+
"""
115+
PyObject* test_float(PyObject* self) {
116+
PyErr_SetString(PyExc_RuntimeError, "Should not call __float__");
117+
return NULL;
118+
}
119+
PyObject* test_add(PyObject* a, PyObject* b) {
120+
return PyLong_FromLong(42);
121+
}
122+
PyObject* test_sub(PyObject* a, PyObject* b) {
123+
return PyLong_FromLong(4242);
124+
}
125+
PyObject* test_mul(PyObject* a, PyObject* b) {
126+
return PyLong_FromLong(424242);
127+
}
128+
PyObject* test_pow(PyObject* a, PyObject* b, PyObject* c) {
129+
return PyLong_FromLong(42424242);
130+
}
131+
""",
132+
nb_float="test_float",
133+
nb_add="test_add",
134+
nb_subtract="test_sub",
135+
nb_multiply="test_mul",
136+
nb_power="test_pow"
137+
)
138+
x = TestFloatBinop()
139+
assert 10.0 + x == 42
140+
assert 10.0 - x == 4242
141+
assert 10.0 * x == 424242
142+
assert 10.0 ** x == 42424242
143+
112144
def test_index(self):
113145
TestIndex = CPyExtType("TestIndex",
114146
"""

0 commit comments

Comments
 (0)