-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pattern.py
95 lines (74 loc) · 2.32 KB
/
test_pattern.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from typing import Tuple, List
from cubelang.cube import ICubeSide
from cubelang.orientation import Color
from cubelang.sides import Component
from cubelang.pattern import Pattern
class MockCubeSide(ICubeSide[None]):
def __init__(self, colors: List[List[Color]]):
super().__init__()
self._colors = colors
@property
def rows(self) -> int:
return len(self._colors)
@property
def columns(self) -> int:
return len(self._colors[0])
def __getitem__(self, item: Tuple[int, int]) -> Component[None]:
i, j = item
return Component(self._colors[i][j], None)
def __setitem__(self, key: Tuple[int, int], value: Component[None]) -> None:
raise NotImplementedError()
COLORS = [
[Color.RED, Color.GREEN, Color.BLUE],
[Color.WHITE, Color.WHITE, Color.ORANGE],
[Color.ORANGE, Color.YELLOW, Color.YELLOW]
]
def test_pattern_match_correct():
side = MockCubeSide(COLORS)
pattern = Pattern([
[None, Color.GREEN, None],
["g1", "g1", None],
[None, "g2", "g2"]
])
match = pattern.match(side, {"g1": Color.WHITE})
assert match == {"g2": Color.YELLOW}
def test_pattern_match_wrong_color():
side = MockCubeSide(COLORS)
pattern = Pattern([
[None, Color.RED, None],
["g1", "g1", None],
[None, None, None]
])
assert pattern.match(side, dict()) is None
def test_pattern_match_wrong_known():
side = MockCubeSide(COLORS)
pattern = Pattern([
[None, Color.GREEN, None],
["g1", Color.WHITE, None],
[None, "g2", "g2"]
])
assert pattern.match(side, {"g1": Color.YELLOW}) is None
def test_pattern_match_wrong_found():
side = MockCubeSide(COLORS)
pattern = Pattern([
[None, None, None],
["g1", None, None],
["g1", None, None]
])
assert pattern.match(side, dict()) is None
def test_pattern_multiple_fount():
side = MockCubeSide(COLORS)
pattern = Pattern([
[None, None, None],
["g1", "g2", None],
[None, None, None]
])
assert pattern.match(side, dict()) is None
def test_pattern_multiple():
side = MockCubeSide(COLORS)
pattern = Pattern([
[None, None, None],
["g1", "g2", None],
[None, None, None]
])
assert pattern.match(side, {"g1": Color.WHITE}) is None