示例#1
0
def main():

    machine = CoffeeMachine()

    machine.add_drink("espresso", 20, 30, 0)
    machine.add_drink("latte", 30, 180, 120)
    machine.add_drink("cappucino", 15, 120, 180)
    machine.add_drink("super strong coffee", 70, 180, 30)

    while True:
        print_menu()

        action = input("Choose an action. ")

        try:
            choice = int(action)

            for i in range(len(CoffeeMachine.available_drinks)):
                if choice == i + 1:
                    print(machine.brew(machine.available_drinks[i]))
                    input("Press any key to continue...")
                    break

            if choice == len(CoffeeMachine.available_drinks) + 1:
                machine.show_ingredients_lvl()
                input("Press any key to continue...")
            elif choice == len(CoffeeMachine.available_drinks) + 2:
                machine.fill()
                input("Press any key to continue...")
            elif choice == len(CoffeeMachine.available_drinks) + 3:
                print("Goodbye!")
                input("Press any key to continue...")
                break
            else:
                print("Please input correct number.")

        except ValueError:
            print("Please input a number.")
示例#2
0
class TestCoffeeMachine(unittest.TestCase):
    def setUp(self):
        self.testMachine = CoffeeMachine()

    def test_adding_drinks(self):
        self.testMachine.add_drink("possible_drink", 100, 100, 100)
        self.testMachine.add_drink("impossible_drink", 9999, 9999, 9999)

        coffees = len(self.testMachine.available_drinks)

        self.assertEqual(coffees, 2,
                         "Something went wrong while adding drinks!")

    def test_can_brew(self):
        tested = [
            self.testMachine.can_brew(self.testMachine.available_drinks[0]),
            self.testMachine.can_brew(self.testMachine.available_drinks[1])
        ]

        expected = [True, False]

        self.assertEqual(tested, expected,
                         "Machine can't check if it is able to brew a drink!")

    def test_brewing(self):
        tested = [
            self.testMachine.brew(self.testMachine.available_drinks[0]),
            self.testMachine.brew(self.testMachine.available_drinks[1])
        ]

        expected = [
            "Beep beep! Your {} is ready!".format(
                self.testMachine.available_drinks[0].name),
            "Not enough ingredients. Refill the machine!"
        ]
        self.assertEqual(tested, expected, "Error while brewing a drink!")

    def test_filling(self):
        self.assertEqual(self.testMachine.fill(), "Machine refilled.",
                         "Error while refilling the machine!")