circuitpython/tests/float/complex1.py
Damien George 214179b430 tests: Add tests for SyntaxError, TypeError, and other missing things.
This is intended to improve coverage of the test suite.
2015-03-25 23:10:09 +00:00

44 lines
822 B
Python

# test basic complex number functionality
# constructor
print(complex(1))
print(complex(1.2))
print(complex(1.2j))
print(complex("1"))
print(complex("1.2"))
print(complex("1.2j"))
print(complex(1, 2))
print(complex(1j, 2j))
# unary ops
print(bool(1j))
print(+(1j))
print(-(1 + 2j))
# binary ops
print(1j + False)
print(1j + True)
print(1j + 2)
print(1j + 2j)
print(1j - 2)
print(1j - 2j)
print(1j * 2)
print(1j * 2j)
print(1j / 2)
print(1j / (1 + 2j))
ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag))
ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
# builtin abs
print(abs(1j))
print("%.5g" % abs(1j + 2))
# convert bignum to complex on rhs
ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag))
# can't convert rhs to complex
try:
1j + []
except TypeError:
print("TypeError")