-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_vending_machine.py
43 lines (32 loc) · 1.59 KB
/
test_vending_machine.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
import unittest
from vending_machine import give_change, give_item_and_change
class TestVendingMachine(unittest.TestCase):
def test_return_change(self):
self.assertEqual(give_change(.17), [.10, .05, .02])
self.assertEqual(give_change(.18), [.10, .05, .02, .01])
self.assertEqual(give_change(.04), [.02, .02])
def test_multiple_same_coins(self):
self.assertEqual(give_change(.04), [.02, .02])
def test_unavailable_item(self):
"""if user asks for an item that's unavailable, they should not be given the item, and their money should be returned"""
item, change, _ = give_item_and_change('crisps', .50)
self.assertIsNone(item)
self.assertEqual(change, 0.5)
def test_give_item_and_change_amount_less_than_cost(self):
"""tests is amount is less than the cost"""
item, change, _ = give_item_and_change('coke', .50)
self.assertIsNone(item)
self.assertEqual(change, 0.5)
def test_give_item_and_change_amount_works_with_correct_money(self):
"""tests is amount is less than the cost"""
item, change, _ = give_item_and_change('coke', .73)
self.assertIsNotNone(item)
self.assertEqual(item, 'coke')
self.assertEqual(change, [])
def test_give_item_and_change_amount_works_with_correct_money(self):
"""tests is amount is less than the cost"""
item, change, _ = give_item_and_change('coke', 2.0)
self.assertIsNotNone(item)
self.assertEqual(item, 'coke')
self.assertEqual(change, [1,.20, .05, .02])
# AssertionError: [] != 0.73