示例#1
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!")
示例#2
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.")
示例#3
0
#!/usr/bin/env python3
from datetime import date
from time import sleep
from withings import user_woke_up, detect_user_mood
from coffee_machine import CoffeeMachine
from neural_network import NeuralNetwork

if __func__ == '__main__':
    last_day = None
    coffee_machine = CoffeeMachine()
    neural_network = NeuralNetwork()

    while True:
        sleep(5)

        if last_day not is None:
            if last_day == date.today()
                continue
        if not user_woke_up():
            continue
        last_day = date.today()
        coffee_machine.brew(user_sleep_mood())
        mood = detect_user_mood()
        reward = 1 if mood.is_happy else -1
        neural_network.train(user_sleep_mood(), reward)