Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neel Shah
NIFTy
Commits
6e9dca27
Commit
6e9dca27
authored
Apr 01, 2020
by
Martin Reinecke
Browse files
fix and stricter tests
parent
a5930cf9
Changes
2
Hide whitespace changes
Inline
Side-by-side
nifty6/random.py
View file @
6e9dca27
...
...
@@ -243,4 +243,5 @@ class Context(object):
push_sseq
(
self
.
_sseq
)
def
__exit__
(
self
,
exc_type
,
exc_value
,
tb
):
pop_sseq
()
return
exc_type
is
None
test/test_random.py
View file @
6e9dca27
...
...
@@ -20,11 +20,17 @@ import numpy as np
import
nifty6
as
ift
def
check_state_back_to_orig
():
np
.
testing
.
assert_equal
(
len
(
ift
.
random
.
_rng
),
1
)
np
.
testing
.
assert_equal
(
len
(
ift
.
random
.
_sseq
),
1
)
def
test_rand1
():
with
ift
.
random
.
Context
(
31
):
a
=
ift
.
random
.
current_rng
().
integers
(
0
,
1000000000
)
with
ift
.
random
.
Context
(
31
):
b
=
ift
.
random
.
current_rng
().
integers
(
0
,
1000000000
)
check_state_back_to_orig
()
np
.
testing
.
assert_equal
(
a
,
b
)
...
...
@@ -34,6 +40,7 @@ def test_rand2():
a
=
ift
.
random
.
current_rng
().
integers
(
0
,
1000000000
)
with
ift
.
random
.
Context
(
sseq
[
2
]):
b
=
ift
.
random
.
current_rng
().
integers
(
0
,
1000000000
)
check_state_back_to_orig
()
np
.
testing
.
assert_equal
(
a
,
b
)
...
...
@@ -48,6 +55,7 @@ def test_rand3():
sseq
=
ift
.
random
.
spawn_sseq
(
1
)
with
ift
.
random
.
Context
(
sseq
[
0
]):
b
=
ift
.
random
.
current_rng
().
integers
(
0
,
1000000000
)
check_state_back_to_orig
()
np
.
testing
.
assert_equal
(
a
,
b
)
...
...
@@ -68,6 +76,7 @@ def test_rand5():
ift
.
random
.
pop_sseq
()
d
=
ift
.
random
.
current_rng
().
integers
(
0
,
1000000000
)
ift
.
random
.
pop_sseq
()
check_state_back_to_orig
()
np
.
testing
.
assert_equal
(
a
,
b
)
np
.
testing
.
assert_equal
(
c
,
d
)
...
...
@@ -79,4 +88,5 @@ def test_rand6():
b
=
ift
.
random
.
current_rng
().
integers
(
0
,
1000000000
)
np
.
testing
.
assert_equal
(
a
,
b
)
ift
.
random
.
pop_sseq
()
check_state_back_to_orig
()
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