Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
67a48136
Commit
67a48136
authored
Sep 16, 2016
by
Damien George
Browse files
tests/extmod/urandom: Add urandom tests for error cases.
parent
f84b3416
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/extmod/urandom_basic.py
View file @
67a48136
...
...
@@ -17,3 +17,9 @@ random.seed(1)
r
=
random
.
getrandbits
(
16
)
random
.
seed
(
1
)
print
(
random
.
getrandbits
(
16
)
==
r
)
# check that it throws an error for zero bits
try
:
random
.
getrandbits
(
0
)
except
ValueError
:
print
(
'ValueError'
)
tests/extmod/urandom_extra.py
View file @
67a48136
...
...
@@ -16,6 +16,31 @@ for i in range(50):
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
):
...
...
@@ -23,11 +48,23 @@ for i in range(50):
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'
)
print
(
'random'
)
for
i
in
range
(
50
):
assert
0
<=
random
.
random
()
<
1
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment