Beispiel #1
0
def test_inserted_coins_are_appended_to_coin_list():
    machine = VendingMachine()
    machine.insert_coin(coins.Loonie())
    machine.insert_coin(coins.Toonie())
    machine.insert_coin(coins.Quarter())

    assert machine.inserted_coins == [
        coins.Loonie(), coins.Toonie(),
        coins.Quarter()
    ]
Beispiel #2
0
 def get_change(self):
     """
     method to return change, larger coin value first
     not perfect one since when test 85 we expect 3 quarter and 1 dime
     this will give 2 quarter 3 dime 1 nickel
     """
     coins_list = [
         coins.Toonie(),
         coins.Loonie(),
         coins.Quarter(),
         coins.Dime(),
         coins.Nickel()
     ]
     list_changes = []
     temp = self.get_balance()
     temp -= temp % 5
     while temp > 0:
         for coin in coins_list:
             if temp % coin.value == 0:
                 list_changes.append(coin)
                 temp -= coin.value
                 break
     return sorted(list_changes,
                   key=lambda customer: customer.value,
                   reverse=True)
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
    ]
Beispiel #4
0
def test_loonie_str():
    coin = coins.Loonie()
    assert str(coin) == '$1'
Beispiel #5
0
def test_loonie_value():
    coin = coins.Loonie()
    assert coin.value == 100
def test_loonie_str_label():
    """
    test loonie child class of Coin label is $1
    """
    coin = coins.Loonie()
    assert str(coin) == '$1'
def test_loonie_value_100():
    """
    test child class loonie of Coin value is 100
    """
    coin = coins.Loonie()
    assert coin.value == 100
Beispiel #8
0
def test_get_balance_returns_sum_value_of_coins():
    machine = VendingMachine()
    machine.insert_coin(coins.Quarter())
    machine.insert_coin(coins.Loonie())

    assert machine.get_balance() == 125
Beispiel #9
0
def test_buy_product_accepts_drink():
    machine = VendingMachine()
    machine.insert_coin(coins.Toonie())
    machine.insert_coin(coins.Loonie())
    machine.buy_product(products.Drink)