-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwarehouse.py
39 lines (32 loc) · 1.02 KB
/
warehouse.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
class BinItem:
"""A warehouse bin item consisting of a sku number and quantity."""
def __init__(self, sku, quantity):
self.sku = sku
self.quantity = quantity
def __str__(self):
return "SKU {0}: {1}".format(self.sku, self.quantity)
class Bin:
"""A location for storing BinItems."""
def __init__(self, name):
self.name = name
self.contents = []
def __str__(self):
s = "Bin {0}:".format(self.name)
for item in self.contents:
s += '\n ' + item.__str__()
return s
def add(self, item):
for index, value in enumerate(self.contents):
if value.sku == item.sku:
value.quantity += item.quantity
break
if value.sku < item.sku:
continue
else:
self.contents.insert(index, item)
break
else:
self.contents.append(item)
if __name__ == '__main__':
import doctest
doctest.testfile("bin_tests.txt")