def test_cant_buy_unavailable_product(self):
     machine = Machine(slots=3, slot_depth=10)
     products = {
         ProductName("coca-cola"):
         Product(name=ProductName("coca-cola"),
                 quantity=1,
                 price=Decimal('2.1')),
         ProductName("mars"):
         Product(name=ProductName("mars"), quantity=5,
                 price=Decimal('1.9')),
         ProductName("orbit"):
         Product(name=ProductName("orbit"),
                 quantity=6,
                 price=Decimal('2.3')),
     }
     machine.load_products(products)
     money = Coins({Decimal(5): 1})
     nonexistent_slot_code = SlotCode("doesn't exist")
     self.assertNotIn(
         nonexistent_slot_code,
         [code for code, _ in machine.get_available_products().items()])
     product, change = machine.choose_product(nonexistent_slot_code, money)
     self.assertIsNone(product)
     self.assertEqual(money, change)
     self.assertEqual(machine.get_balance(), Decimal(0))
 def test_buy_a_product_if_cant_give_a_change(self):
     machine = Machine(slots=3, slot_depth=10)
     products = {
         ProductName("coca-cola"): Product(name=ProductName("coca-cola"), quantity=1, price=Decimal('2.1')),
         ProductName("mars"): Product(name=ProductName("mars"), quantity=5, price=Decimal('1.9')),
         ProductName("orbit"): Product(name=ProductName("orbit"), quantity=6, price=Decimal('2.3')),
     }
     machine.load_products(products)
     money = Coins({Decimal(5): 1})
     slot_code, _ = machine.get_available_products()[ProductName("coca-cola")]
     product, change = machine.choose_product(slot_code, money)
     self.assertIsNone(product)
     self.assertEqual(money, change)
     self.assertEqual(machine.get_balance(), Decimal(0))
 def test_loading_coins(self):
     machine = Machine(slots=2, slot_depth=10)
     money = Coins({(Decimal(1) / Decimal(5)): 5, Decimal(1): 1})
     machine.load_coins(money)
     self.assertEqual(machine.get_balance(), Decimal(2))