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
FSL
fslpy
Commits
156454ec
Commit
156454ec
authored
Jul 27, 2017
by
Paul McCarthy
🚵
Browse files
New Unit tests for memoize
parent
01a60b6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test_memoize.py
View file @
156454ec
...
...
@@ -51,6 +51,72 @@ def test_memoize():
assert
timesCalled
[
0
]
==
7
def
test_memoize_create
():
timesCalled
=
{
'without_brackets'
:
0
,
'with_brackets'
:
0
}
@
memoize
.
memoize
def
without_brackets
():
timesCalled
[
'without_brackets'
]
+=
1
return
5
@
memoize
.
memoize
()
def
with_brackets
():
timesCalled
[
'with_brackets'
]
+=
1
return
10
for
i
in
range
(
10
):
assert
without_brackets
()
==
5
assert
with_brackets
()
==
10
assert
timesCalled
[
'without_brackets'
]
==
1
assert
timesCalled
[
'with_brackets'
]
==
1
def
test_memoize_invalidate
():
timesCalled
=
collections
.
defaultdict
(
lambda
:
0
)
@
memoize
.
memoize
def
func
(
arg
):
timesCalled
[
arg
]
+=
1
return
arg
*
5
for
i
in
range
(
5
):
assert
func
(
5
)
==
25
assert
func
(
10
)
==
50
assert
timesCalled
[
5
]
==
1
assert
timesCalled
[
10
]
==
1
func
.
invalidate
()
for
i
in
range
(
5
):
assert
func
(
5
)
==
25
assert
func
(
10
)
==
50
assert
timesCalled
[
5
]
==
2
assert
timesCalled
[
10
]
==
2
func
.
invalidate
(
5
)
for
i
in
range
(
5
):
assert
func
(
5
)
==
25
assert
func
(
10
)
==
50
assert
timesCalled
[
5
]
==
3
assert
timesCalled
[
10
]
==
2
func
.
invalidate
(
10
)
for
i
in
range
(
5
):
assert
func
(
5
)
==
25
assert
func
(
10
)
==
50
assert
timesCalled
[
5
]
==
3
assert
timesCalled
[
10
]
==
3
def
test_memoizeMD5
():
timesCalled
=
[
0
]
...
...
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