Exemplo n.º 1
0
class TestSimplePlaceholders(unittest.TestCase):

    def setUp(self):
        story = "I had a ((an adjective)) sandwich for lunch today. It dripped all over my ((a body part)) and ((a noun))."
        self.madLibs = MadLibs(story)

    def test_extract_questions_from_story(self):
        self.assertEquals(['an adjective', 'a body part', 'a noun'], self.madLibs.questions)
        
    def test_feed_answers_to_story(self):
        answers = {'an adjective': 'smelly', 'a body part': 'toes', 'a noun': 'bathtub'}
        expected_story = "I had a smelly sandwich for lunch today. It dripped all over my toes and bathtub."
        self.assertEquals(expected_story, self.madLibs.tell_story(answers))
Exemplo n.º 2
0
class TestVariablePlaceholders(unittest.TestCase):

    def setUp(self):
        story = "Our favorite animal is a ((animal:an animal)). We think a ((animal)) is better than a ((another animal))."
        self.madLibs = MadLibs(story)

    def test_extract_reusable_variables_from_story(self):
        self.assertEquals(['an animal', 'another animal'], self.madLibs.questions)
        
    def test_feed_answers_to_story_with_reusable_variables(self):
        answers = {'an animal': 'python', 'another animal': 'unicorn'}
        expected_story = "Our favorite animal is a python. We think a python is better than a unicorn."
        self.assertEquals(expected_story, self.madLibs.tell_story(answers))
Exemplo n.º 3
0
def main():
    played = False
    madlib = MadLibs()
    while True:
        print("Welcome to MadLibs")
        print("1: New Mablib")
        if played:
            print("2: Same Madlib new Input")
            print("3: Same Input new Madlib")
        print("end: To Exit the game")
        num = input("Type number, to choose option: ")
        print()
        try:
            num = int(num)
            if (num > 0) and (num <= 3):
                if num == 1:
                    print_madlibs()
                    name = choose_madlibs()
                    madlib.get_inputs()
                    madlib.get_mad_libs(name)
                    played = True
                elif played:
                    if num == 2:
                        madlib.get_inputs()
                        madlib.get_mad_libs(name)
                    if num == 3:
                        print_madlibs()
                        name = choose_madlibs()
                        madlib.get_mad_libs(name)
        except ValueError:
            if num == "end":
                return
            print(f"{num} not a valid option!")
        
        print()
        input("Press Enter to continue...")
        print()
Exemplo n.º 4
0
 def setUp(self):
     story = "I had a ((an adjective)) sandwich for lunch today. It dripped all over my ((a body part)) and ((a noun))."
     self.madLibs = MadLibs(story)
Exemplo n.º 5
0
 def setUp(self):
     story = "Our favorite animal is a ((animal:an animal)). We think a ((animal)) is better than a ((another animal))."
     self.madLibs = MadLibs(story)