Skip to content

Commit a3ff553

Browse files
committed
[GR-10283] Int and float don't have implemented conjugate function.
1 parent 6964c99 commit a3ff553

File tree

4 files changed

+80
-7
lines changed

4 files changed

+80
-7
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_float.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,11 @@ def fromhex(cls, value1, value2):
576576
self.assertEqual(17.0, f)
577577
self.assertEqual(F, type(f))
578578

579-
class RealImagTests(unittest.TestCase):
579+
class MyFloat(float):
580+
pass
581+
582+
class RealImagConjugateTests(unittest.TestCase):
583+
580584
def test_real_imag(self):
581585
def builtinTest(number):
582586
a = float(number)
@@ -596,9 +600,6 @@ def builtinTest(number):
596600
builtinTest(9999992432902008176640000999999.1)
597601

598602
def test_real_imag_subclass(self):
599-
class MyFloat(float):
600-
pass
601-
602603
def subclassTest(number):
603604
a = MyFloat(number)
604605
b = a.real
@@ -615,3 +616,33 @@ def subclassTest(number):
615616
subclassTest(9.1)
616617
subclassTest(6227020800.2)
617618
subclassTest(9999992432902008176640000999999.33)
619+
620+
def test_conjugate(self):
621+
def builtinTest(number):
622+
a = float(number)
623+
b = a.conjugate()
624+
assert a == b
625+
assert a is b
626+
assert type(a) == float
627+
assert type(b) == float
628+
629+
builtinTest(-9.1)
630+
builtinTest(0.0)
631+
builtinTest(9.2)
632+
builtinTest(6227020800.90)
633+
builtinTest(9999992432902008176640000999999.1)
634+
635+
def test_conjugate_subclass(self):
636+
def subclassTest(number):
637+
a = MyFloat(number)
638+
b = a.conjugate()
639+
assert a == b
640+
assert a is not b
641+
assert type(a) == MyFloat
642+
assert type(b) == float
643+
644+
subclassTest(-9.0)
645+
subclassTest(0.0)
646+
subclassTest(9.1)
647+
subclassTest(6227020800.2)
648+
subclassTest(9999992432902008176640000999999.33)

graalpython/com.oracle.graal.python.test/src/tests/test_int.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ def builtinTest(number):
166166
assert False.denominator == 1
167167

168168
def test_mumerator_denominator_subclass():
169-
class MyInt(int):
170-
pass
171-
172169
def subclassTest(number):
173170
a = MyInt(number)
174171
b = a.numerator
@@ -185,3 +182,36 @@ def subclassTest(number):
185182
subclassTest(9)
186183
subclassTest(6227020800)
187184
subclassTest(9999992432902008176640000999999)
185+
186+
def test_conjugate():
187+
def builtinTest(number):
188+
a = int(number)
189+
b = a.conjugate()
190+
assert a == b
191+
assert a is b
192+
assert type(a) == int
193+
assert type(b) == int
194+
195+
builtinTest(-9)
196+
builtinTest(0)
197+
builtinTest(9)
198+
builtinTest(6227020800)
199+
builtinTest(9999992432902008176640000999999)
200+
201+
assert True.conjugate() == 1
202+
assert False.conjugate() == 0
203+
204+
def test_conjugate_subclass():
205+
def subclassTest(number):
206+
a = MyInt(number)
207+
b = a.conjugate()
208+
assert a == b
209+
assert a is not b
210+
assert type(a) == MyInt
211+
assert type(b) == int
212+
213+
subclassTest(-9)
214+
subclassTest(0)
215+
subclassTest(9)
216+
subclassTest(6227020800)
217+
subclassTest(9999992432902008176640000999999)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,12 @@ static abstract class ImagNode extends PythonBuiltinNode {
918918

919919
}
920920

921+
@GenerateNodeFactory
922+
@Builtin(name = "conjugate", fixedNumOfArguments = 1, doc = "Returns self, the complex conjugate of any float.")
923+
static abstract class ConjugateNode extends RealNode {
924+
925+
}
926+
921927
@Builtin(name = __GETFORMAT__, fixedNumOfArguments = 2)
922928
@GenerateNodeFactory
923929
abstract static class GetFormatNode extends PythonUnaryBuiltinNode {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,12 @@ static abstract class NumeratorNode extends RealNode {
19071907

19081908
}
19091909

1910+
@GenerateNodeFactory
1911+
@Builtin(name = "conjugate", fixedNumOfArguments = 1, doc = "Returns self, the complex conjugate of any int.")
1912+
static abstract class ConjugateNode extends RealNode {
1913+
1914+
}
1915+
19101916
@GenerateNodeFactory
19111917
@Builtin(name = "denominator", fixedNumOfArguments = 1, isGetter = true, doc = "the denominator of a rational number in lowest terms")
19121918
static abstract class DenominatorNode extends PythonBuiltinNode {

0 commit comments

Comments
 (0)