summaryrefslogtreecommitdiffstatshomepage
path: root/tests/float
diff options
context:
space:
mode:
Diffstat (limited to 'tests/float')
-rw-r--r--tests/float/builtin_float_round.py4
-rw-r--r--tests/float/complex1.py3
-rw-r--r--tests/float/float1.py37
-rw-r--r--tests/float/math_fun.py12
4 files changed, 52 insertions, 4 deletions
diff --git a/tests/float/builtin_float_round.py b/tests/float/builtin_float_round.py
index afde6ff16c..6759d0fd5a 100644
--- a/tests/float/builtin_float_round.py
+++ b/tests/float/builtin_float_round.py
@@ -10,3 +10,7 @@ for t in tests:
# check .5 cases
for i in range(11):
print(round((i - 5) / 2))
+
+# test second arg
+# TODO uPy currently only supports second arg being 0
+print(round(1.4, 0))
diff --git a/tests/float/complex1.py b/tests/float/complex1.py
index eafa53746a..2fb95c6908 100644
--- a/tests/float/complex1.py
+++ b/tests/float/complex1.py
@@ -33,6 +33,9 @@ ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
print(abs(1j))
print("%.5g" % abs(1j + 2))
+# float on lhs should delegate to complex
+print(1.2 + 3j)
+
# convert bignum to complex on rhs
ans = 1j + (1 << 70); print("%.5g %.5g" % (ans.real, ans.imag))
diff --git a/tests/float/float1.py b/tests/float/float1.py
index 9e4bb85cd1..2539d89dc3 100644
--- a/tests/float/float1.py
+++ b/tests/float/float1.py
@@ -1,4 +1,15 @@
-# basic float
+# test basic float capabilities
+
+# float construction
+print(float(1.2))
+
+# unary operators
+print(bool(0.0))
+print(bool(1.2))
+print(+(1.2))
+print(-(1.2))
+
+# division of integers
x = 1 / 2
print(x)
@@ -7,9 +18,16 @@ a = 1
a /= 2
print(a)
+# floor division
print(1.0 // 2)
print(2.0 // 2)
+# comparison
+print(1.2 <= 3.4)
+print(1.2 <= -3.4)
+print(1.2 >= 3.4)
+print(1.2 >= -3.4)
+
try:
1.0 / 0
except ZeroDivisionError:
@@ -20,6 +38,23 @@ try:
except ZeroDivisionError:
print("ZeroDivisionError")
+try:
+ 1.2 % 0
+except ZeroDivisionError:
+ print("ZeroDivisionError")
+
+# unsupported unary ops
+
+try:
+ ~1.2
+except TypeError:
+ print("TypeError")
+
+try:
+ 1.2 in 3.4
+except TypeError:
+ print("TypeError")
+
# can't convert list to float
try:
float([])
diff --git a/tests/float/math_fun.py b/tests/float/math_fun.py
index 03ee8e85d2..16aec76f92 100644
--- a/tests/float/math_fun.py
+++ b/tests/float/math_fun.py
@@ -33,7 +33,9 @@ functions = [('sqrt', sqrt, p_test_values),
('ceil', ceil, test_values),
('fabs', fabs, test_values),
('floor', floor, test_values),
- ('trunc', trunc, test_values)
+ ('trunc', trunc, test_values),
+ ('radians', radians, test_values),
+ ('degrees', degrees, test_values),
]
for function_name, function, test_vals in functions:
@@ -52,10 +54,14 @@ for function_name, function, test_vals in tuple_functions:
print("{:.5g} {:.5g}".format(x, y))
binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.),
- (-23., -42.), (1., 0.0), (1., -0.0)])
+ (-23., -42.), (1., 0.0), (1., -0.0)]),
+ ('pow', pow, ((1., 0.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
+ ('atan2', atan2, ((1., 0.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
+ ('fmod', fmod, ((1., 1.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
+ ('ldexp', ldexp, ((1., 0), (0., 1), (2., 2), (3., -2), (-3., -4),)),
]
for function_name, function, test_vals in binary_functions:
print(function_name)
for value1, value2 in test_vals:
- print("{:.7g}".format(function(value1, value2)))
+ print("{:.5g}".format(function(value1, value2)))