-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathevaluator_cache_test.py
More file actions
103 lines (65 loc) · 2.09 KB
/
evaluator_cache_test.py
File metadata and controls
103 lines (65 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pytest
from icepool import MultisetEvaluator, NoCache, multiset_function, d6
class CacheTestEvaluator(MultisetEvaluator):
def next_state(self, state, order, outcome, /, *counts):
return 0
def final_outcome(self, final_state, order, outcomes, /, *sizes, **kwargs):
return 0
class KeyedEvaluator(CacheTestEvaluator):
@property
def next_state_key(self):
return type(self)
class KeylessEvaluator(CacheTestEvaluator):
pass
class NoCacheEvaluator(CacheTestEvaluator):
@property
def next_state_key(self):
return NoCache
def test_keyed_bare():
evaluator = KeyedEvaluator()
evaluator(d6.pool(1))
assert len(evaluator._cache) == 1
evaluator(d6.pool(1))
assert len(evaluator._cache) == 1
def test_keyless_bare():
evaluator = KeylessEvaluator()
evaluator(d6.pool(1))
assert len(evaluator._cache) == 1
evaluator(d6.pool(1))
assert len(evaluator._cache) == 1
def test_nocache_bare():
evaluator = NoCacheEvaluator()
evaluator(d6.pool(1))
assert len(evaluator._cache) == 0
def test_keyed_wrapped():
@multiset_function
def evaluator(x):
return KeyedEvaluator().evaluate(x)
evaluator(d6.pool(1))
assert len(evaluator._cache) == 1
def test_keyless_wrapped():
@multiset_function
def evaluator(x):
return KeylessEvaluator().evaluate(x)
evaluator(d6.pool(1))
assert len(evaluator._cache) == 0
def test_nocache_wrapped():
@multiset_function
def evaluator(x):
return NoCacheEvaluator().evaluate(x)
evaluator(d6.pool(1))
assert len(evaluator._cache) == 0
def test_joint_cache():
@multiset_function
def evaluator(x):
return KeyedEvaluator().evaluate(x), KeyedEvaluator().evaluate(x)
evaluator(d6.pool(1))
assert len(evaluator._cache) == 1
evaluator(d6.pool(1))
assert len(evaluator._cache) == 1
def test_joint_nocache():
@multiset_function
def evaluator(x):
return KeyedEvaluator().evaluate(x), NoCacheEvaluator().evaluate(x)
evaluator(d6.pool(1))
assert len(evaluator._cache) == 0