forked from keeppythonweird/catinabox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_pantry.py
75 lines (60 loc) · 2.81 KB
/
test_pantry.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
import pytest
from catinabox import pantry
class TestPantry(object):
###########################################################################
# add_food
###########################################################################
def test__add_food__succeeds(self):
p = pantry.Pantry()
assert False
def test__add_food__quantity_0__raises(self):
p = pantry.Pantry()
with pytest.raises(pantry.InvalidQuantity):
p.add_food(food_type="liver", quantity=0)
def test__add_food__quantity_less_than_0__raises(self):
p = pantry.Pantry()
with pytest.raises(pantry.InvalidQuantity):
p.add_food(food_type="liver", quantity=-10)
###########################################################################
# list_food
###########################################################################
def test__list_food__food_in_pantry__returns_all_food(self):
p = pantry.Pantry()
p.add_food(food_type="burger", quantity=3)
p.add_food(food_type="pancake", quantity=4)
assert p.list_food() == ["burger",
"burger",
"burger",
"pancake",
"pancake",
"pancake",
"pancake"]
def test__list_food__no_food_in_pantry__returns_nothing(self):
p = pantry.Pantry()
assert p.list_food() == []
###########################################################################
# retrieve_food
###########################################################################
def test__retrieve_food__food_in_pantry__removes_and_returns(self):
p = pantry.Pantry()
p.add_food(food_type="pickle", quantity=1)
p.add_food(food_type="bacon", quantity=2)
p.add_food(food_type="tuna", quantity=3)
assert p.retrieve_food(quantity=4) == ["pickle",
"bacon",
"bacon",
"tuna"]
assert p.list_food() == ["tuna", "tuna"]
def test__retrieve_food__all_food_in_pantry__removes_and_returns(self):
p = pantry.Pantry()
p.add_food(food_type="bacon", quantity=2)
assert p.retrieve_food(quantity=2) == ["bacon", "bacon"]
assert p.list_food() == []
def test__retrieve_food__no_food_in_pantry__fails(self):
p = pantry.Pantry()
with pytest.raises(pantry.NotEnoughItemsInPantry):
p.retrieve_food(quantity=1)
def test__retrieve_food__not_enough_food_in_pantry__fails(self):
p = pantry.Pantry()
with pytest.raises(pantry.NotEnoughItemsInPantry):
p.retrieve_food(quantity=1)