Commit fb612f83 authored by Boxiang Sun's avatar Boxiang Sun

add some tests to complex

parent 1ebb95b4
......@@ -22,3 +22,49 @@ try:
complex(1, 1.0).real = 1
except TypeError, e:
print e
class C(complex):
pass
print(1j - C(1))
print(1j + C(1))
print(1j * C(1))
print(1j / C(1))
class C1(complex):
def __complex__(self):
return 1j
print(C1(1) + 1j)
print(C1(1) - 1j)
print(C1(1) * 1j)
print(C1(1) / 1j)
types = [int, float, long]
for _type in types:
try:
_type(1j)
except TypeError as e:
print(e.message)
data = ["-1j", "0j", "1j",
"5+5j", "5-5j",
"5", "5L", "5.5",
"\"5\"", "None",
]
operations = ["__mod__", "__rmod__",
"__divmod__", "__rdivmod__",
"__truediv__", "__rtruediv__",
"__floordiv__", "__rfloordiv__",
]
for x in data:
for y in data:
for operation in operations:
try:
print(eval("complex.{op}({arg1}, {arg2})".format(op=operation,
arg1=x,
arg2=y)))
except Exception as e:
print(e.message)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment