diff options
| author | Jim Mussared <jim.mussared@gmail.com> | 2022-08-18 16:57:45 +1000 |
|---|---|---|
| committer | Jim Mussared <jim.mussared@gmail.com> | 2023-06-08 17:54:24 +1000 |
| commit | 4216bc7d1351feb8199e4ebbff1a9598aa1c5b02 (patch) | |
| tree | 5085738ef65ab377c221f290c7fa90ec2acd4d29 /tests/extmod/random_extra.py | |
| parent | 5e50975a6dd9466afafbcd012c00078093fe1f57 (diff) | |
tests: Replace umodule with module everywhere.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests/extmod/random_extra.py')
| -rw-r--r-- | tests/extmod/random_extra.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/extmod/random_extra.py b/tests/extmod/random_extra.py new file mode 100644 index 000000000..aa0505337 --- /dev/null +++ b/tests/extmod/random_extra.py @@ -0,0 +1,66 @@ +try: + import random +except ImportError: + print("SKIP") + raise SystemExit + +try: + random.randint +except AttributeError: + print("SKIP") + raise SystemExit + +print("randrange") +for i in range(50): + assert 0 <= random.randrange(4) < 4 + assert 2 <= random.randrange(2, 6) < 6 + assert -2 <= random.randrange(-2, 2) < 2 + assert random.randrange(1, 9, 2) in (1, 3, 5, 7) + assert random.randrange(2, 1, -1) in (1, 2) + +# empty range +try: + random.randrange(0) +except ValueError: + print("ValueError") + +# empty range +try: + random.randrange(2, 1) +except ValueError: + print("ValueError") + +# zero step +try: + random.randrange(2, 1, 0) +except ValueError: + print("ValueError") + +# empty range +try: + random.randrange(2, 1, 1) +except ValueError: + print("ValueError") + +print("randint") +for i in range(50): + assert 0 <= random.randint(0, 4) <= 4 + assert 2 <= random.randint(2, 6) <= 6 + assert -2 <= random.randint(-2, 2) <= 2 + +# empty range +try: + random.randint(2, 1) +except ValueError: + print("ValueError") + +print("choice") +lst = [1, 2, 5, 6] +for i in range(50): + assert random.choice(lst) in lst + +# empty sequence +try: + random.choice([]) +except IndexError: + print("IndexError") |
