From 213a7189537fc7b9cc96f0259e5b7b9e46121927 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 19 Jan 2017 23:37:21 +1100 Subject: tests/float: Add test for assigning to attribute of complex number. --- tests/float/complex1.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/float/complex1.py') diff --git a/tests/float/complex1.py b/tests/float/complex1.py index 027d12583..fed65d5d5 100644 --- a/tests/float/complex1.py +++ b/tests/float/complex1.py @@ -51,6 +51,12 @@ print(float('-inf') * (1 + 1j)) # convert bignum to complex on rhs ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag)) +# can't assign to attributes +try: + (1j).imag = 0 +except AttributeError: + print('AttributeError') + # can't convert rhs to complex try: 1j + [] -- cgit v1.2.3 From 8a39e18f5fc960eb0901b8e219b7026ebe466f3d Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 3 Feb 2017 00:04:13 +1100 Subject: tests/float: Add tests for zero to a negative power. --- tests/float/complex1.py | 5 +++++ tests/float/float1.py | 5 +++++ tests/float/int_divzero.py | 5 +++++ 3 files changed, 15 insertions(+) (limited to 'tests/float/complex1.py') diff --git a/tests/float/complex1.py b/tests/float/complex1.py index fed65d5d5..1031111f3 100644 --- a/tests/float/complex1.py +++ b/tests/float/complex1.py @@ -28,6 +28,7 @@ print(1j / 2) print((1j / 2j).real) print(1j / (1 + 2j)) ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag)) +ans = 0j ** 1; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag)) ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag)) @@ -94,6 +95,10 @@ except ZeroDivisionError: print("ZeroDivisionError") # zero division via power +try: + 0j ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") try: 0j ** 1j except ZeroDivisionError: diff --git a/tests/float/float1.py b/tests/float/float1.py index 0e115032b..93f6f014c 100644 --- a/tests/float/float1.py +++ b/tests/float/float1.py @@ -75,6 +75,11 @@ try: except ZeroDivisionError: print("ZeroDivisionError") +try: + 0.0 ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") + # unsupported unary ops try: diff --git a/tests/float/int_divzero.py b/tests/float/int_divzero.py index b037dd8c7..b311a1dbc 100644 --- a/tests/float/int_divzero.py +++ b/tests/float/int_divzero.py @@ -2,3 +2,8 @@ try: 1 / 0 except ZeroDivisionError: print("ZeroDivisionError") + +try: + 0 ** -1 +except ZeroDivisionError: + print("ZeroDivisionError") -- cgit v1.2.3 From 325c4473a5b760a2251a6e0e418abf218741fb1f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 6 Mar 2017 15:46:01 +0100 Subject: tests/float/complex1: Split out intbig test. --- tests/float/complex1.py | 3 --- tests/float/complex1_intbig.py | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 tests/float/complex1_intbig.py (limited to 'tests/float/complex1.py') diff --git a/tests/float/complex1.py b/tests/float/complex1.py index 1031111f3..8c8d285e1 100644 --- a/tests/float/complex1.py +++ b/tests/float/complex1.py @@ -49,9 +49,6 @@ print(float('nan') * 1j) print(float('inf') * (1 + 1j)) print(float('-inf') * (1 + 1j)) -# convert bignum to complex on rhs -ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag)) - # can't assign to attributes try: (1j).imag = 0 diff --git a/tests/float/complex1_intbig.py b/tests/float/complex1_intbig.py new file mode 100644 index 000000000..ed2390bba --- /dev/null +++ b/tests/float/complex1_intbig.py @@ -0,0 +1,4 @@ +# test basic complex number functionality + +# convert bignum to complex on rhs +ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag)) -- cgit v1.2.3 From 677fb3101525bc655d9fd548b8c2cecfc8deefd2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 4 Apr 2017 12:14:34 +1000 Subject: tests/float: Add tests for hashing float and complex numbers. --- tests/float/builtin_float_hash.py | 22 ++++++++++++++++++++++ tests/float/complex1.py | 4 ++++ 2 files changed, 26 insertions(+) create mode 100644 tests/float/builtin_float_hash.py (limited to 'tests/float/complex1.py') diff --git a/tests/float/builtin_float_hash.py b/tests/float/builtin_float_hash.py new file mode 100644 index 000000000..ba6b63907 --- /dev/null +++ b/tests/float/builtin_float_hash.py @@ -0,0 +1,22 @@ +# test builtin hash function with float args + +# these should hash to an integer with a specific value +for val in ( + '0.0', + '1.0', + '2.0', + '-12.0', + '12345.0', + ): + print(val, hash(float(val))) + +# just check that these values are hashable +for val in ( + '0.1', + '-0.1', + '10.3', + 'inf', + '-inf', + 'nan', + ): + print(val, type(hash(float(val)))) diff --git a/tests/float/complex1.py b/tests/float/complex1.py index 8c8d285e1..a6038de04 100644 --- a/tests/float/complex1.py +++ b/tests/float/complex1.py @@ -41,6 +41,10 @@ print(1j == 1j) print(abs(1j)) print("%.5g" % abs(1j + 2)) +# builtin hash +print(hash(1 + 0j)) +print(type(hash(1j))) + # float on lhs should delegate to complex print(1.2 + 3j) -- cgit v1.2.3