summaryrefslogtreecommitdiff
path: root/tests/float
diff options
context:
space:
mode:
authorGlenn Ruben Bakke <glennbakke@gmail.com>2017-04-09 17:45:32 +0200
committerGlenn Ruben Bakke <glennbakke@gmail.com>2017-04-09 17:45:32 +0200
commit360243af92bd096522153521bce323f60bdb1b80 (patch)
treee3b0e94099da7ce5e9d895e22e02435c61f205e0 /tests/float
parent5d06aa32609959115b496ac0e596438bfdbda038 (diff)
parentb87432b8fb8332548be11b63c9139065ce565f91 (diff)
Merge branch 'master' into nrf5_no_sdk
Diffstat (limited to 'tests/float')
-rw-r--r--tests/float/builtin_float_hash.py22
-rw-r--r--tests/float/builtin_float_round.py7
-rw-r--r--tests/float/builtin_float_round_intbig.py4
-rw-r--r--tests/float/bytearray_construct.py7
-rw-r--r--tests/float/bytes_construct.py7
-rw-r--r--tests/float/complex1.py4
-rw-r--r--tests/float/math_fun_int.py15
-rw-r--r--tests/float/math_fun_intbig.py12
8 files changed, 76 insertions, 2 deletions
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/builtin_float_round.py b/tests/float/builtin_float_round.py
index de72514db..63cb39aa3 100644
--- a/tests/float/builtin_float_round.py
+++ b/tests/float/builtin_float_round.py
@@ -15,3 +15,10 @@ for i in range(11):
# test second arg
for i in range(-1, 3):
print(round(1.47, i))
+
+# test inf and nan
+for val in (float('inf'), float('nan')):
+ try:
+ round(val)
+ except (ValueError, OverflowError) as e:
+ print(type(e))
diff --git a/tests/float/builtin_float_round_intbig.py b/tests/float/builtin_float_round_intbig.py
new file mode 100644
index 000000000..2083e3ea3
--- /dev/null
+++ b/tests/float/builtin_float_round_intbig.py
@@ -0,0 +1,4 @@
+# test round() with floats that return large integers
+
+for x in (-1e25, 1e25):
+ print('%.3g' % round(x))
diff --git a/tests/float/bytearray_construct.py b/tests/float/bytearray_construct.py
index f72926635..db946a99d 100644
--- a/tests/float/bytearray_construct.py
+++ b/tests/float/bytearray_construct.py
@@ -1,5 +1,10 @@
# test construction of bytearray from array with float type
-from array import array
+try:
+ from array import array
+except ImportError:
+ import sys
+ print("SKIP")
+ sys.exit()
print(bytearray(array('f', [1, 2.3])))
diff --git a/tests/float/bytes_construct.py b/tests/float/bytes_construct.py
index 0a57e08a2..8664d7296 100644
--- a/tests/float/bytes_construct.py
+++ b/tests/float/bytes_construct.py
@@ -1,5 +1,10 @@
# test construction of bytearray from array with float type
-from array import array
+try:
+ from array import array
+except ImportError:
+ import sys
+ print("SKIP")
+ sys.exit()
print(bytes(array('f', [1, 2.3])))
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)
diff --git a/tests/float/math_fun_int.py b/tests/float/math_fun_int.py
new file mode 100644
index 000000000..ee54f0995
--- /dev/null
+++ b/tests/float/math_fun_int.py
@@ -0,0 +1,15 @@
+# test the math functions that return ints
+
+try:
+ import math
+except ImportError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+for fun in (math.ceil, math.floor, math.trunc):
+ for x in (-1.6, -0.2, 0, 0.6, 1.4, float('inf'), float('nan')):
+ try:
+ print(fun(x))
+ except (ValueError, OverflowError) as e:
+ print(type(e))
diff --git a/tests/float/math_fun_intbig.py b/tests/float/math_fun_intbig.py
new file mode 100644
index 000000000..962c10daa
--- /dev/null
+++ b/tests/float/math_fun_intbig.py
@@ -0,0 +1,12 @@
+# test the math functions that return ints, with very large results
+
+try:
+ import math
+except ImportError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+for fun in (math.ceil, math.floor, math.trunc):
+ for x in (-1e25, 1e25):
+ print('%.3g' % fun(x))