-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_grid.py
137 lines (98 loc) · 4.53 KB
/
test_grid.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"""
Module for testing the Grid class and its subclasses
"""
import grid, container as Container
def test_index_mapper():
"""Tests whether the single dimensional scalar is correctly mapped to an index on the grid"""
grid_type = grid.ShipBay()
assert grid_type.index_mapper(95) == (7, 11)
assert grid_type.index_mapper(0) == (0, 0)
assert grid_type.index_mapper(60) == (5, 0)
grid_type = grid.Buffer()
assert grid_type.index_mapper(95) == (3, 23)
assert grid_type.index_mapper(0) == (0, 0)
assert grid_type.index_mapper(60) == (2, 12)
def test_convert_to_stacks():
bay = grid.ShipBay()
c1 = Container.Container(weight=333, description="Walmart", on_ship=True)
c2 = Container.Container(weight=996, description="Costco", on_ship=True)
c3 = Container.Container(weight=996, description="Costco", on_ship=True)
c4 = Container.Container(weight=996, description="Costco", on_ship=True)
c5 = Container.Container(weight=333, description="Walmart", on_ship=True)
c6 = Container.Container(weight=520, description="Frice", on_ship=True)
bay.add_container(c1, 7, 1)
bay.add_container(c2, 6, 1)
bay.add_container(c3, 5, 1)
bay.add_container(c4, 7, 2)
bay.add_container(c5, 6, 2)
bay.add_container(c6, 5, 2)
bay.convert_grid_to_stack()
assert bay.get_stacks()[1].pop() == c3
assert bay.get_stacks()[1].pop() == c2
assert bay.get_stacks()[1].pop() == c1
assert bay.get_stacks()[2].pop() == c6
assert bay.get_stacks()[2].pop() == c5
assert bay.get_stacks()[2].pop() == c4
for i in {0, 3, 4, 5, 6, 7}:
assert bay.get_stacks(i).get_height() == 0
def test_get_containers():
bay = grid.ShipBay()
c1 = Container.Container(weight=333, description="Walmart", on_ship=True)
c2 = Container.Container(weight=996, description="Costco", on_ship=True)
c3 = Container.Container(weight=996, description="Costco", on_ship=True)
c4 = Container.Container(weight=996, description="Costco", on_ship=True)
c5 = Container.Container(weight=333, description="Walmart", on_ship=True)
c6 = Container.Container(weight=520, description="Frice", on_ship=True)
bay.add_container(c1, 7, 1)
bay.add_container(c2, 6, 1)
bay.add_container(c3, 5, 1)
bay.add_container(c4, 7, 2)
bay.add_container(c5, 6, 2)
bay.add_container(c6, 5, 2)
retrieved = bay.get_containers(Container.Container(weight=88, description="Ralphs"))
assert len(retrieved) == 0
retrieved = bay.get_containers(Container.Container(description="Frice"))
assert len(retrieved) == 1
assert retrieved[0][1].get_description() == "Frice"
assert retrieved[0][1].get_weight() == 520
retrieved = bay.get_containers(Container.Container(description="Costco"))
assert len(retrieved) == 3
for i in retrieved:
assert i[1].get_description() == "Costco"
assert i[1].get_weight() == 996
retrieved = bay.get_containers(Container.Container(description="Walmart"))
assert len(retrieved) == 2
prev = 0
for i in retrieved:
assert i != prev
assert i[1].get_description() == "Walmart"
assert i[1].get_weight() == 333
prev = i
def test_eq():
bay = grid.ShipBay()
c1 = Container.Container(weight=333, description="Walmart", on_ship=True)
c2 = Container.Container(weight=996, description="Costco", on_ship=True)
c3 = Container.Container(weight=996, description="Costco", on_ship=True)
c4 = Container.Container(weight=996, description="Costco", on_ship=True)
c5 = Container.Container(weight=333, description="Walmart", on_ship=True)
c6 = Container.Container(weight=520, description="Frice", on_ship=True)
bay.add_container(c1, 7, 1)
bay.add_container(c2, 6, 1)
bay.add_container(c3, 5, 1)
bay.add_container(c4, 7, 2)
bay.add_container(c5, 6, 2)
bay.add_container(c6, 5, 2)
bay2 = grid.ShipBay()
c1 = Container.Container(weight=333, description="Walmart", on_ship=True)
c2 = Container.Container(weight=996, description="Costco", on_ship=True)
c3 = Container.Container(weight=996, description="Costco", on_ship=True)
c4 = Container.Container(weight=996, description="Costco", on_ship=True)
c5 = Container.Container(weight=333, description="Walmart", on_ship=True)
c6 = Container.Container(weight=520, description="Frice", on_ship=True)
bay2.add_container(c1, 7, 1)
bay2.add_container(c2, 6, 1)
bay2.add_container(c3, 5, 1)
bay2.add_container(c4, 7, 2)
bay2.add_container(c5, 6, 2)
bay2.add_container(c6, 5, 2)
assert bay == bay2