-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_p0146_lru_cache.py
79 lines (74 loc) · 1.53 KB
/
test_p0146_lru_cache.py
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
# flake8: noqa: F403, F405
import pytest
from leetcode.p0146_lru_cache import *
solutions = [
LRUCache,
LRUCache2,
]
test_cases = [
[
("n", 4, None),
("g", 4, -1),
("p", 1, 1),
("p", 2, 2),
("p", 3, 3),
("p", 4, 4),
("p", 5, 5),
("g", 3, 3),
("g", 1, -1),
("p", 6, 6),
("g", 2, -1),
("g", 6, 6),
("p", 5, 5),
("p", 7, 7),
("g", 4, -1),
("g", 7, 7),
("g", 5, 5),
("g", 6, 6),
("g", 3, 3),
("p", 8, 8),
("g", 7, -1),
("g", 5, 5),
("p", 9, 9),
("g", 6, -1),
("g", 9, 9),
("g", 3, 3),
("g", 8, 8),
("g", 5, 5),
("g", 9, 9),
],
[
("n", 1, None),
("g", 1, -1),
("p", 1, 1),
("g", 1, 1),
("p", 2, 2),
("g", 1, -1),
("g", 2, 2),
("g", 3, -1),
],
[
("n", 2, None),
("p", 1, 1),
("p", 2, 2),
("p", 3, 3),
("g", 1, -1),
("p", 4, 4),
("g", 2, -1),
("g", 3, 3),
("p", 5, 5),
("g", 4, -1),
("g", 3, 3),
],
]
@pytest.mark.timeout(1)
@pytest.mark.parametrize("args", test_cases)
@pytest.mark.parametrize("solution", solutions)
def test_solution(args, solution):
_, n, _ = args[0]
lru = solution(n)
for action, a1, a2 in args[1:]:
if action == "g":
assert lru.get(a1) == a2
elif action == "p":
lru.put(a1, a2)