def test_get_balance_0(): """ test when no coins are inserted, and no purchases have been made, the balance should be zero """ machine = vending_machine.VendingMachine() assert machine.get_balance() == 0
def test_buy_product_with_integer_product(): """ test buy product with string input """ machine = vending_machine.VendingMachine() with pytest.raises(ValueError): machine.buy_product("not a product type")
def test_insert_dime(): """ test insert instance of Dime """ machine = vending_machine.VendingMachine() dime = coins.Dime() assert machine.insert_coin(dime) == [dime]
def test_insert_coin_reject_not_coin_class(): """ test if insert integer will raise ValueError """ machine = vending_machine.VendingMachine() with pytest.raises(ValueError): machine.insert_coin(25)
def test_insert_nickel(): """ test insert instance of Nickel """ machine = vending_machine.VendingMachine() nickel = coins.Nickel() assert machine.insert_coin(nickel) == [nickel]
def test_get_change_balance_25(): """ When the balance is 25, a quarter should be returned """ machine = vending_machine.VendingMachine() quarter = coins.Quarter() machine.insert_coin(quarter) assert machine.get_change() == [quarter]
def test_insert_dime_nickel(): """ test insert coin appended right """ machine = vending_machine.VendingMachine() dime = coins.Dime() nickel = coins.Nickel() machine.insert_coin(dime) machine.insert_coin(nickel) assert machine.insert_coins == [dime, nickel]
def test_buy_product_with_insufficient_funds(): """ test buy product with insufficient funds """ machine = vending_machine.VendingMachine() dime = coins.Dime() nickel = coins.Nickel() machine.insert_coin(dime) machine.insert_coin(nickel) drink = products.Drink() with pytest.raises(InsufficientFunds): machine.buy_product(drink)
def test_get_balance_two_loonie_candy_75(): """ given that two toonies are inserted into the machine and a candy bar was purchased, the method should return 85. """ machine = vending_machine.VendingMachine() toonie = coins.Toonie() candy = products.Candy() machine.insert_coin(toonie) machine.insert_coin(toonie) machine.buy_product(candy) assert machine.get_balance() == 85
def test_get_change_balance_265(): """ When the balance is 265, a toonie, two quarters, a dime and a nickel should be returned """ machine = vending_machine.VendingMachine() quarter = coins.Quarter() toonie = coins.Toonie() dime = coins.Dime() nickel = coins.Nickel() machine.insert_coin(quarter) machine.insert_coin(toonie) machine.insert_coin(quarter) machine.insert_coin(dime) machine.insert_coin(nickel) assert machine.get_change() == [toonie, quarter, quarter, dime, nickel]
def main(): root = tk.Tk() root.configure(background=ROOT_BG_COLOR, height=ROOT_HEIGHT, width=ROOT_WIDTH) products = [] for i in range(7): product_id = vm.MIN_PRODUCT_ID + (3 * i) products.append(vm.Product(product_id, "Coke", 220)) products.append(vm.Product(product_id + 1, "Fanta", 210)) products.append(vm.Product(product_id + 2, "Sprite", 250)) vending_machine = vm.VendingMachine(products) vending_machine_service = VendingMachineService(vending_machine) VendingMachineMainView(root, vending_machine_service, products) root.mainloop()
def test_vending_machine_whole(): """ Here we do a integrated test to simulate a action of using vending machine """ machine1 = vending_machine.VendingMachine() quarter = coins.Quarter() toonie = coins.Toonie() dime = coins.Dime() nickel = coins.Nickel() loonie = coins.Loonie() candy = products.Candy() chips = products.Chips() machine1.insert_coin(toonie) machine1.insert_coin(loonie) machine1.insert_coin(loonie) machine1.insert_coin(toonie) machine1.insert_coin(quarter) candy = products.Candy() chips = products.Chips() machine1.buy_product(candy) machine1.buy_product(chips) assert machine1.get_change() == [ quarter, quarter, dime, dime, dime, nickel ]
def test_get_change_balance_0(): """ When the balance is 0, no quarters should be returned """ machine = vending_machine.VendingMachine() assert machine.get_change() == []
def setUp(self): self.green_light = mock.MagicMock(spec=LED, autospec=True) self.vm = vending_machine.VendingMachine(self.green_light) self.green_blink = mock.MagicMock(spec=LED.blink) self.vm.green_light.blink = self.green_blink
def setUp(self): """This class tests VendingMachine class""" self.products = self.get_products() self.vending_machine = vm.VendingMachine(self.products)
#!/usr/bin/python3 import vending_machine import RPi.GPIO as GPIO # Must be done before instantiating a VendingMachine GPIO.setmode(GPIO.BCM) x = vending_machine.VendingMachine() run = True print(30 * '-') print(" V E N D - O - M A T I C ") print(30 * '-') print("Press X to Exit") print("Press C to see Cash Balance") print(30 * '-') message = "INSERT COIN" terminate = False product_selected = False selected_product = None product_price = None while not selected_product: print("") print(40 * "#") print("Choose a product") products = x.get_products() keys = list(products) for index in range(len(keys)):