User Stories:
-
As a user, I can use the make dough with 'water' and 'flour' to make 'dough'.
-
As a user, I can use the bake dough with dough to get naan.
-
As a user, I can user the run factory with water and flour and get naan.
Necessary: You must have python installed.
Optional: It is easier to complete this task when using a code editor, such as Visual Studio Code or PyCharm. You can learn how to install VSC or install PyCharm using these hyperlinks.
# import necessary files and modules
from factory_class import Factory
# this class doesn't exist yet so it's important to remember to keep this name
# when we make the class later
import unittest
import pytest2. Create a test class and a method to check whether our to-be-created class meets our requirements:
# creating testing class, it is a child of unittest.TestCase
class TestFactory(unittest.TestCase):
# instantiating the class so we can test it
factory_instance = Factory()
# test fails when the outcome of the funciton is not 'naan', provided the input is 'water' and 'bread'
def test_make_naan(self):
self.assertEqual(self.factory_instance.make_naan('water','bread'), 'naan')class Factory:
passUse the command python -m pytestin your terminal to test your code. Note: you should be in the directory where your files for this tasks are stored. The test should fail because we have not met the requirements yet.
# creating Factory class
class Factory:
# make dough function takes water & bread and returns dough.
def make_dough(self, water_string, bread_string):
# makes sure if the input is not 'water' and 'bread'
if water_string == 'water' and bread_string == 'bread':
return 'dough'
# make naan function takes outcome of make_dough function and makes naan with it
def make_naan(self,water_string, bread_string):
# works if make_dough returned dough
if self.make_dough(water_string, bread_string) == 'dough':
return 'naan'Again, in your terminal type python -m pytest, and if nothing is wrong you should see this result.
# import our class
from factory_class import Factory
# instantiate our class so we can use it
factory_instance = Factory()
# while loop so we can keep prompting the user for input if they want to keep making bread
while True:
# takes input for ingredients
water_string = input('Please insert your water. (Type "water").').lower()
bread_string = input('Please insert your bread. (Type "bread").').lower()
print(factory_instance.make_naan(water_string,bread_string))
# check if the user wants to make more bread
again = input('would you like to make more bread?').lower()
if again == 'no':
break
else:
continue
