def test_coffee_refill(self): test_data = read_json_file(self.test_file) coffee_machine = CoffeeMachine(2) coffee_machine.add_items(test_data['machine']['total_items_quantity']) coffee_machine.refill("hot_water", 100) coffee_machine.ingredient_store_read() self.assertEqual(coffee_machine.items['hot_water'], 600) coffee_machine.delete_storage()
def test_returnIngredientLevel(): """ Test to see if returning ingredient level works. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) assert CM.returnIngredientLevel() == total_items_qty
def test_canMakeDrink_functionality_possible(): """ Test to see if canMake works if drink is possible to make. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) assert CM._CoffeeMachine__canMakeDrink("hot_tea") == 1
def test_refill_functionality(): """ Test if the refill function works properly """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {"milk": 1} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.refill("milk", 1) assert CM.raw_material_qty["milk"] == 2
def test_refill_positive_value(): """ Test to check if refill method works if final value after adding ingredient becomes negative. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {"milk": 1} with pytest.raises(ValueError, match="Cannot add because final quantity"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.refill("milk", -2)
def test_refill_unknown_ingredient(): """ Test to check if refill method works if ingredient is not in coffee machine. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {} with pytest.raises(ValueError, match="Ingredient not in coffee machine."): CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.refill("milk", 1)
def test_refill_qty_type(): """ Test to check if refill method works if ingredient quantity given is not an int. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {} with pytest.raises(ValueError, match="Quantity is not an integer."): CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.refill("milk", "hello")
def test_refill_ingredient_type(): """ Test to check if refill method works if ingredient given is not a string. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {} with pytest.raises(ValueError, match="Ingredient is not a string."): CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.refill(1, 1)
def test_canMakeDrink_functionality_impossible(): """ Test to see if canMake works if drink is not possible to make because of non-existent ingredient. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"cocoa": 2}} total_items_qty = {"milk": 1} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) assert CM._CoffeeMachine__canMakeDrink("hot_tea") == -1
def test_pourDrink_functionality(): """ Test to see if pourDrink works correctly. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM._CoffeeMachine__pourDrink("hot_tea") assert CM.raw_material_qty["milk"] == 1
def test_makeDrink_drink_type(): """ Test to see if makeDrink works when drink name is not a string. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) with pytest.raises(ValueError, match="Drink name is not a string."): CM._CoffeeMachine__makeDrink(1, 1)
class coffee_machine_handler: ingredient_quantity_mapping = { "hot_water": 500, "hot_milk": 500, "ginger_syrup": 100, "sugar_syrup": 100, "tea_leaves_syrup": 100, "green_mixture": 100 } drink_types = { "hot_tea": { "hot_water": 200, "hot_milk": 100, "ginger_syrup": 10, "sugar_syrup": 10, "tea_leaves_syrup": 30 }, "hot_coffee": { "hot_water": 100, "ginger_syrup": 30, "hot_milk": 400, "sugar_syrup": 50, "tea_leaves_syrup": 30 }, "black_tea": { "hot_water": 300, "ginger_syrup": 30, "sugar_syrup": 50, "tea_leaves_syrup": 30 }, "green_tea": { "hot_water": 100, "ginger_syrup": 30, "sugar_syrup": 50, "green_mixture": 30 } } def __init__(self): self.__coffee_machine = CoffeeMachine( outlets=3, ingredients_dict=self.ingredient_quantity_mapping, drink_types=self.drink_types) def make_coffee(self, drink_type): return self.__coffee_machine.make_drink(drink_type=drink_type) def add_ingredients(self, ingredient_name, quantity): return self.__coffee_machine.add_quantity_ingredient( ingredient_name, quantity)
def test_makeDrink_recipe_unkown(): """ Test to see if makeDrink works when drink recipe is not known. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.running_threads = [1] with pytest.raises(ValueError, match="Drink recipe is not known."): CM._CoffeeMachine__makeDrink("hot_tea", 1)
def test_makeOrder_order_type(): """ Test to see if makeOrder works with wrong order type. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} orders = {} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) with pytest.raises(ValueError, match="Orders were expected in a list."): CM.makeOrder(orders)
def test_makeOrder_order_unknown_drink(): """ Test to see if makeOrder works with wrong drink type in order. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} orders = ["coffee"] CM = CoffeeMachine(num_outlets, beverages, total_items_qty) with pytest.raises(ValueError, match="for ordered drink is not known."): CM.makeOrder(orders)
def test_makeDrink_functionality_possible(): """ Test to see if makeDrink works if drink is possible to make. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.running_threads = [1] CM._CoffeeMachine__makeDrink("hot_tea", 1) assert CM.raw_material_qty["milk"] == 1
def test_makeOrder_functionality_str_input(): """ Test to see if makeOrder works for single string input. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} orders = "hot_tea" CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.makeOrder(orders) assert CM.raw_material_qty["milk"] == 1
def test_makeOrder_functionality_multiple_orders_with_wait(): """ Test to see if makeOrder works for multiple orders. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} orders = ["hot_tea", "hot_tea", "hot_tea", "hot_tea", "hot_tea", "hot_tea"] CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.makeOrder(orders) assert CM.raw_material_qty["milk"] == 0
def test_makeOrder_zero_len(): """ Test to see if makeOrder works with zero length order. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": 1}} total_items_qty = {"milk": 2} orders = [] CM = CoffeeMachine(num_outlets, beverages, total_items_qty) CM.makeOrder(orders) assert CM.raw_material_qty["milk"] == 2
def main(): coffee_machine = CoffeeMachine() while True: if coffee_machine.state == 'waiting': command = input('Write action (buy, fill, take, remaining, exit): ') if command == 'exit': break elif coffee_machine.state == 'choosing_coffee': command = input('What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu: ') elif coffee_machine.state == 'filling_water': command = input('Write how many ml of water do you want to add: ') elif coffee_machine.state == 'filling_milk': command = input('Write how many ml of milk do you want to add: ') elif coffee_machine.state == 'filling_beans': command = input('Write how many grams of coffee beans do you want to add: ') elif coffee_machine.state == 'filling_cups': command = input('Write how many disposable cups of coffee do you want to add: ') coffee_machine.run_command(command)
def test_checkFormat_bevs_type(): """ Test to check if non dict beverages is handled correctly. """ # assign data to pass to coffee machine num_outlets = 1 beverages = "hello" total_items_qty = {} with pytest.raises(ValueError, match="Beverage list is not a dict."): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkSemantics_num_outlets(): """ Test to check if number of outlets supplied makes semantic sense. """ # assign data to pass to coffee machine num_outlets = -1 beverages = {} total_items_qty = {} with pytest.raises(ValueError, match="outlets must be more than 0"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkFormat_raw_mat_type(): """ Test to check if non dict raw_material_qty is handled correctly. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = "hello" with pytest.raises(ValueError, match="Raw material list is not a dict."): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkFormat_num_type(): """ Test to check if non integer num outlets is handled correctly. """ # assign data to pass to coffee machine num_outlets = "hello" beverages = {} total_items_qty = {} with pytest.raises(ValueError, match="Number of outlets is not"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkFormat_beverage_drink_not_str(): """ Test to check if a drink name in beverages dict is not a string. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {1: {}} total_items_qty = {} with pytest.raises(ValueError, match="Name of drink in beverage list not"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkFormat_beverage_drink_ingredient_not_str(): """ Test to check if a drink's ingredients (key) in beverages dict is not a string. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {1: 52}} total_items_qty = {} with pytest.raises(ValueError, match="Name of ingredient for drink in"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkFormat_beverage_drink_ingredient_not_dict(): """ Test to check if a drink's ingredients in beverages dict is not passed as a dict. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": "hello"} total_items_qty = {} with pytest.raises(ValueError, match="Ingredients for drink in beverage"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkFormat_raw_mat_qty_amount_type(): """ Test to check if a raw material quantity value in raw_material_qty dict is not an integer. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {"milk": "hello"} with pytest.raises(ValueError, match="Quantity of ingredient in raw"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkSemantics_beverages(): """ Test to check if beverages ingredient quantity supplied makes semantic sense. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {"hot_tea": {"milk": -1}} total_items_qty = {} with pytest.raises(ValueError, match="Quantity of ingredient in drink"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def test_checkSemantics_raw_material_qty(): """ Test to check if raw materials ingredient quantity supplied makes semantic sense. """ # assign data to pass to coffee machine num_outlets = 1 beverages = {} total_items_qty = {"hot_tea": -1} with pytest.raises(ValueError, match="Quantity of a raw material cannot"): CM = CoffeeMachine(num_outlets, beverages, total_items_qty)
def __init__(self): self.sut = CoffeeMachine() self.handled = []
print('\nStudents:') for i in range(len(codecool_bp.students)): print(' ', codecool_bp.students[i].full_name) input() print("\nMentors arrive at school. They welcome students with a cheery smile\n") input() codecool_bp.mentors[1].check_energy_level(codecool_bp.students) input() codecool_bp.mentors[0].check_mood(codecool_bp.students) input() codecool_bp.students[3].use_EKI(codecool_bp.EKI_list[7]) input() code = Code(215, "Fakkin' Hard Shit") code.get_worked_on(codecool_bp.students[1]) input() codecool_bp.students[3].use_EKI(codecool_bp.EKI_list[10]) input() creepy = Management("Creepy", "Guy", 0, "male", 0, True) creepy.creeping(codecool_bp.mentors, codecool_bp.students) input() coffeemachine = CoffeeMachine(70, 0, True, True) coffeemachine.make_coffee() input() coffeemachine.get_filled_water() input() coffeemachine.make_coffee() boda = Management("Boda", "Józsi", 0, "male", 0, True) boda.change_life(codecool_bp.mentors, codecool_bp.students) input() print ("Happy End")
def __init__(self, test): self.sut = CoffeeMachine() self.test = test self.handled = []
class Actionwords: def __init__(self, test): self.sut = CoffeeMachine() self.test = test self.handled = [] def i_start_the_coffee_machine(self, lang = "en"): self.sut.start(lang) def i_shutdown_the_coffee_machine(self): self.sut.stop() def message_message_should_be_displayed(self, message): self.test.assertEqual(self.sut.message, message) def coffee_should_be_served(self): self.test.assertTrue(self.sut.coffee_served) def coffee_should_not_be_served(self): self.test.assertFalse(self.sut.coffee_served) def i_take_a_coffee(self): self.sut.take_coffee() def i_empty_the_coffee_grounds(self): self.sut.empty_grounds() def i_fill_the_beans_tank(self): self.sut.fill_beans() def i_fill_the_water_tank(self): self.sut.fill_tank() def i_take_coffee_number_coffees(self, coffee_number = 10): while (coffee_number > 0): self.i_take_a_coffee() coffee_number = coffee_number - 1 if 'water' in self.handled: self.i_fill_the_water_tank() if 'beans' in self.handled: self.i_fill_the_beans_tank() if 'grounds' in self.handled: self.i_empty_the_coffee_grounds() def the_coffee_machine_is_started(self): self.i_start_the_coffee_machine() def i_handle_everything_except_the_water_tank(self): self.i_handle_coffee_grounds() self.i_handle_beans() def i_handle_water_tank(self): self.handled.append('water') def i_handle_beans(self): self.handled.append('beans') def i_handle_coffee_grounds(self): self.handled.append('grounds') def i_handle_everything_except_the_beans(self): self.i_handle_water_tank() self.i_handle_coffee_grounds() def i_handle_everything_except_the_grounds(self): self.i_handle_water_tank() self.i_handle_beans()
class CoffeeMachineLibrary(object): def __init__(self): self.sut = CoffeeMachine() self.handled = [] def i_start_the_coffee_machine(self, lang = 'en'): self.sut.start(lang) def i_shutdown_the_coffee_machine(self): self.sut.stop() def message_message_should_be_displayed(self, message = ''): if self.sut.message != message: raise AssertionError('%s != %s' % (self.sut.message, message)) def coffee_should_be_served(self): if not self.sut.coffee_served: raise AssertionError('No coffee served') def coffee_should_not_be_served(self): if self.sut.coffee_served: raise AssertionError('A coffee is served') def i_take_a_coffee(self): self.sut.take_coffee() def i_empty_the_coffee_grounds(self): self.sut.empty_grounds() def i_fill_the_beans_tank(self): self.sut.fill_beans() def i_fill_the_water_tank(self): self.sut.fill_tank() def i_take_coffee_number_coffees(self, coffee_number = 10): coffee_number = int(coffee_number) while (coffee_number > 0): self.i_take_a_coffee() coffee_number = coffee_number - 1 if 'water' in self.handled: self.i_fill_the_water_tank() if 'beans' in self.handled: self.i_fill_the_beans_tank() if 'grounds' in self.handled: self.i_empty_the_coffee_grounds() def i_handle_water_tank(self): self.handled.append('water') def i_handle_beans(self): self.handled.append('beans') def i_handle_coffee_grounds(self): self.handled.append('grounds')