summaryrefslogtreecommitdiff
path: root/tests/extmod/urandom_extra_float.py
diff options
context:
space:
mode:
authorAyke van Laethem <aykevanlaethem@gmail.com>2018-07-22 16:19:22 +0200
committerDamien George <damien.p.george@gmail.com>2018-08-04 15:14:23 +1000
commit6572029dc0665e58c2ea7355c9e541bdf83105a4 (patch)
tree7590e55e282f43050f0a1717c41fdc6667663f98 /tests/extmod/urandom_extra_float.py
parent7be5bb367212b6949e74f73d90af01f8b68f1352 (diff)
tests: Make tests work on targets without float support.
Diffstat (limited to 'tests/extmod/urandom_extra_float.py')
-rw-r--r--tests/extmod/urandom_extra_float.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/extmod/urandom_extra_float.py b/tests/extmod/urandom_extra_float.py
new file mode 100644
index 000000000..f665fd18a
--- /dev/null
+++ b/tests/extmod/urandom_extra_float.py
@@ -0,0 +1,24 @@
+try:
+ import urandom as random
+except ImportError:
+ try:
+ import random
+ except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+try:
+ random.randint
+except AttributeError:
+ print('SKIP')
+ raise SystemExit
+
+print('random')
+for i in range(50):
+ assert 0 <= random.random() < 1
+
+print('uniform')
+for i in range(50):
+ assert 0 <= random.uniform(0, 4) <= 4
+ assert 2 <= random.uniform(2, 6) <= 6
+ assert -2 <= random.uniform(-2, 2) <= 2