示例#1
0
 def test_StoreAnswer_req(self):
     obj = Interface()
     obj.ask("What type of square is 1 1 1 1?")
     obj.teach(get_triangle_type)
     obj.correct(get_square_type)
     result = obj.ask("What type of square is 1 1 1 1?")
     self.assertEqual(result, "square")
示例#2
0
 def test_question_prev_question_known_answer(self):
     new_interface = Interface()
     test_string1 = "How is paul awesome?"
     result = new_interface.ask(test_string1)
     result = new_interface.teach("He just is.")
     result = new_interface.teach("Shouldn't allow change")
     self.assertEqual(result, NO_TEACH)
示例#3
0
 def test_provide_answer_corrected_fptr(self):
     obj = Interface()
     obj.ask('What shape is 2 5 2 5?')
     obj.teach(get_triangle_type)
     obj.correct(get_quadrilateral_type)
     result = obj.ask('What shape is 2 5 2 5?')
     self.assertEqual(result, 'rectangle')
示例#4
0
 def test_UpdateLearned_req(self):
     obj = Interface()
     obj.ask("What type of square is 1 1 1 1?")
     obj.teach(get_triangle_type)
     obj.correct(get_square_type)
     result = obj.ask(obj.last_question + "?")
     self.assertEqual(result, "invalid")
示例#5
0
 def test_provide_answer_corrected(self):
     obj = Interface()
     obj.ask('What color is the sky?')
     obj.teach('The sky is blue')
     obj.correct('The sky is a multitude of colors typically ranging from turquoise to indigo')
     result = obj.ask('What color is the sky?')
     self.assertEqual(result, 'The sky is a multitude of colors typically ranging from turquoise to indigo')
示例#6
0
 def test_provide_answer_corrected_strings(self):
     obj = Interface()
     obj.ask('Why did ancient egyptians build the pyramids?')
     obj.teach('To honor their royalty in tombs')
     obj.correct('Aliens')
     result = obj.ask('Why did ancient egyptians build the pyramids?')
     self.assertEqual(result, 'Aliens')
示例#7
0
 def test_provide_answer_corrected_sentence(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     obj.correct('Because Abe wants to add to his glitter collection')
     result = obj.ask('Why did Abe Lincoln start killing vampires?')
     self.assertEqual(result, 'Because Abe wants to add to his glitter collection')
示例#8
0
 def test_provide_answer_corrected_square2(self):
     obj = Interface()
     obj.ask('What type of flamingo is this 1 1 1 1?')
     obj.teach(get_triangle_type)
     obj.correct(get_quad_type)
     result = obj.ask('What type of flamingo is this 1 1 1 1?')
     self.assertEqual(result, 'Square')
示例#9
0
 def test_provide_answer_already_asked2(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     result = obj.teach('Because Abe hates glitter')
     self.assertEqual(result,
                      "I don\'t know about that. I was taught differently")
示例#10
0
 def test_question_ask_90_similar(self):
     new_interface = Interface()
     test_string = "How is pual awesom?"
     result = new_interface.ask(test_string)
     new_interface.teach("He just is.")
     result = new_interface.ask(test_string)
     self.assertEqual(result, "He just is.")
示例#11
0
 def test_provide_answer_corrected_square2(self):
     obj = Interface()
     obj.ask('What type of flamingo is this 1 1 1 1?')
     obj.teach(get_triangle_type)
     obj.correct(get_quad_type)
     result = obj.ask('What type of flamingo is this 1 1 1 1?')
     self.assertEqual(result, 'Square')
示例#12
0
 def test_job_story_clear(self):
     ''' test to see if the user set question answers are cleared '''
     attempt = Interface()
     attempt.ask("What is the meaning of life?")
     attempt.teach("42")
     attempt.ask("Please clear memory?")
     result4 = attempt.ask("What is the meaning of life?")
     self.assertEqual(result4, "I don't know, please provide the answer")
示例#13
0
 def test_story_clear_mem_teach(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.ask("Please clear memory?")
     result = obj.ask('Why did Abe Lincoln start killing vampires?')
     self.assertEqual(result, 'I don\'t know, please provide the answer')
示例#14
0
 def test_giving_answer(self):
     """ test teaching an answer """
     attempt = Interface()
     question = "How many sides does a quadrilateral have?"
     attempt.ask(question)
     attempt.teach("four sides.")
     result = attempt.ask(question)
     self.assertEqual(result, "four sides.")
示例#15
0
 def test_question_ask_0_similar(self):
     new_interface = Interface()
     test_string1 = "How is paul awesome?"
     result = new_interface.ask(test_string1)
     new_interface.teach("He just is.")
     dif_str = "jack do knot scar."
     result = new_interface.ask(dif_str)
     self.assertEqual(result, NOT_A_QUESTION_RETURN)
示例#16
0
 def test_question_ask_89_similar(self):
     new_interface = Interface()
     test_string = "How is paul awesome?"
     result = new_interface.ask(test_string)
     new_interface.teach("He just is.")
     test_string2 = "How is pual awesum?"
     result = new_interface.ask(test_string2)
     self.assertEqual(result, UNKNOWN_QUESTION)
示例#17
0
 def test_story_clear_mem_teach(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.ask("Please clear memory?")
     result = obj.ask('Why did Abe Lincoln start killing vampires?')
     self.assertEqual(result, 'I don\'t know, please provide the answer')
示例#18
0
 def test_provide_answer_corrected_sentence(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     obj.correct('Because Abe wants to add to his glitter collection')
     result = obj.ask('Why did Abe Lincoln start killing vampires?')
     self.assertEqual(result,
                      'Because Abe wants to add to his glitter collection')
示例#19
0
 def test_previous_question_answer(self):
     '''
     This tests the interface for previous question teaching.
     '''
     interface = Interface()
     interface.ask("What makes you think she is a witch?")
     interface.teach("Oh, she turned me into a newt!")
     result = interface.ask("What makes you think she is a witch?")
     self.assertEqual(result, "Oh, she turned me into a newt!")
示例#20
0
 def test_stored_string_answer(self):
     '''
     This tests the interface for storing answers as strings.
     '''
     interface = Interface()
     interface.ask("What is your quest?")
     interface.teach("To seek the Holy Grail.")
     result = interface.question_answers["What is your quest"].value
     self.assertEqual(isinstance(result, str), True)
示例#21
0
    def test_question_ask_correct_valid(self):
        new_interface = Interface()
        test_string = "How is paul awesome?"
        result = new_interface.ask(test_string)
        new_interface.teach("He just is.")

        new_interface.correct("He is not awesome")
        result = new_interface.ask(test_string)
        self.assertEqual(result, "He is not awesome")
 def test_ask_teach_previous(self):
     """
     Test teach function, teach previous answer
     :return: assertion: isosceles
     """
     inquiry = Interface()
     answer = inquiry.ask('What type of triangle is 1 1 3?')
     inquiry.teach(answer)
     result = answer
     self.assertEqual(result, "isosceles")
示例#23
0
 def test_job_story_case_door(self):
     """
     Test job story case hal_at_the_door
     :return: assertion that the system returns the correct answer and username
     """
     inquiry = Interface()
     inquiry.ask("Will you open the door hal?")
     inquiry.teach(hal_at_the_door())
     result = inquiry.ask("Will you open the door hal?")
     self.assertEqual(result, 'I\'m afraid I can\'t do that {0}'.format(getpass.getuser()))
示例#24
0
 def test_clear_qa_userquestions(self):
     '''
     This function tests the interface for clearing QA.
     '''
     interface = Interface()
     interface.ask("Who are you?")
     interface.teach("I am who I am.")
     interface.clear()
     result = interface.ask("Who are you?")
     self.assertNotEqual(result, "I am who I am.")
示例#25
0
 def test_job_story_case_fortune(self):
     """
     Test job story case random_fortune().
     :return: assertion that the system returns a string of a random fortune.
     """
     inquiry = Interface()
     inquiry.ask("What should I keep in mind today?")
     inquiry.teach(random_fortune())
     result = inquiry.ask("What should I keep in mind today?")
     assert isinstance(result, str)
示例#26
0
    def test_question_ask_100_no_question(self):
        new_interface = Interface()
        test_string = "How is paul awesome?"

        result = new_interface.ask(test_string)
        new_interface.teach("He just is.")

        test_string = test_string.strip('?')
        result = new_interface.ask(test_string)
        self.assertEqual(result, NOT_A_QUESTION_RETURN)
示例#27
0
 def test_job_story_case_name(self):
     """
     Test job story case computer_name().
     :return: assertion that the system returns the computer name when asked
     """
     inquiry = Interface()
     inquiry.ask("What is this computer\'s hostname?")
     inquiry.teach(host_name())
     result = inquiry.ask("What is this computer\'s hostname?")
     self.assertEqual(result, socket.gethostname())
示例#28
0
 def test_job_story_case_meaning(self):
     """
     Test job story case meaning_of_life().
     :return: assertion that the system returns the correct meaning of life when asked
     """
     inquiry = Interface()
     inquiry.ask("What is the meaning of life, the universe, and everything?")
     inquiry.teach(meaning_of_life())
     result = inquiry.ask("What is the meaning of life, the universe, and everything?")
     self.assertEqual(result, "42")
 def test_ask_teach_previous(self):
     """
     Test teach function, teach previous answer
     :return: assertion: isosceles
     """
     inquiry = Interface()
     answer = inquiry.ask('What type of triangle is 1 1 3?')
     inquiry.teach(answer)
     result = answer
     self.assertEqual(result, "isosceles")
 def test_question_insert_answer(self):
     """
     Check returns correct answer after teach function.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What triangle is: 5, 6, 5?")
     self.assertEqual(result, 'I don\'t know, please provide the answer')
     qaobject.teach("isosceles")
     result = qaobject.ask("What triangle is: 5, 6, 5?")
     self.assertEqual(result, 'isosceles')
示例#31
0
 def test_update_answered_question(self):
     '''
     This tests the interface for updating an answer with correct().
     '''
     interface = Interface()
     interface.ask("What is your name?")
     interface.teach("My name is Sir Lancelot of Camelot.")
     interface.ask("What is your name?")
     interface.correct("Sir Robin of Camelot.")
     result = interface.ask("What is your name?")
     self.assertEqual(result, "Sir Robin of Camelot.")
 def test_ask_clear_memory(self):
     new_interface = Interface()
     new_interface.ask("How crappy are you?")
     new_interface.teach("I am very crappy")
     clear_mem_return = new_interface.ask("Please clear memory.")
     self.assertEqual(clear_mem_return, "Memory cleared!")
     start_time = time.clock()
     result = new_interface.ask("How crappy are you?")
     end_time = time.clock()
     self.assertLess(end_time - start_time, .05)
     self.assertEqual(result, "I don't know, please provide the answer")
示例#33
0
 def test_job_story_case_get_pi(self):
     """
     Test job story case get_pi()
     :return: assertion that the system returns the correct digit of pi when asked
     """
     inquiry = Interface()
     pi_value = 3
     inquiry.ask("What is the 16 digit of pi?")
     inquiry.teach(get_pi(16))
     result = inquiry.ask("What is the 16 digit of pi?")
     self.assertEqual(result, pi_value)
示例#34
0
 def test_job_story_case_encrypt(self):
     """
     Test job story case caesar_encrypt().
     :return: assertion that the system returns the correct shift caesar cipher
     for a given message
     """
     inquiry = Interface()
     inquiry.ask("What is 'mysecretpassword' in a 5 level caesar cipher?")
     inquiry.teach(caesar_encrypt('mysecretpassword', 5))
     result = inquiry.ask("What is 'mysecretpassword' in a 5 level caesar cipher?")
     self.assertEqual(result, 'rdxjhwjyufxxbtwi')
示例#35
0
 def test_stored_function_answer(self):
     '''
     This tests the interface for storing answers as functions.
     '''
     interface = Interface()
     interface.ask("What is your favorite color?")
     interface.teach(fave_color_function)
     result = interface.question_answers["What is your favorite color"]
     # pylint's recommended syntax does not work here
     # pylint: disable=singleton-comparison
     self.assertEqual(not (result.function == None), True)
示例#36
0
 def test_noupdate_answer_question(self):
     '''
     This tests the interface for not updating an answer with teach().
     '''
     interface = Interface()
     interface.ask("What is your name?")
     interface.teach("My name is Sir Lancelot of Camelot.")
     interface.ask("What is your name?")
     result = interface.teach("Sir Robin of Camelot.")
     self.assertEqual(result, "I don\'t know about that. "+
                      "I was taught differently")
 def test_question_hasanswer(self):
     """
     Check that can not cover question that has already been taught an answer.
     :return:
     """
     qaobject = Interface()
     qaobject.ask("What triangle is: 5, 6, 5?")
     qaobject.teach("isosceles")
     result = qaobject.ask("What triangle is: 5, 6, 5?")
     self.assertEqual(result, 'isosceles')
     result = qaobject.teach("Two sides equal")
     self.assertEqual(result, 'I don\'t know about that. I was taught differently')
 def test_question_updateanswer(self):
     """
     Check that correct function performs correctly.
     :return:
     """
     qaobject = Interface()
     qaobject.ask("What triangle is: 5, 6, 5?")
     qaobject.teach("scalene")
     result = qaobject.ask("What triangle is: 5, 6, 5?")
     self.assertEqual(result, 'scalene')
     qaobject.correct('isosceles')
     result = qaobject.ask("What triangle is: 5, 6, 5?")
     self.assertEqual(result, 'isosceles')
示例#39
0
 def test_performance_caesar_23(self):
     """
     Test how long it takes to encrypt a message with a shift of 23
     :return: Assert that it is less than 5ms
     """
     inquiry = Interface()
     start = time.clock()
     inquiry.ask("What is 'mysecretpassword' in a 23 level caesar cipher?")
     inquiry.teach(caesar_encrypt('mysecretpassword', 23))
     inquiry.ask("What is 'mysecretpassword' in a 23 level caesar cipher?")
     end = time.clock()
     result = (end - start)
     assert result <= 0.015
示例#40
0
 def test_performance_fibonacci_1000(self):
     """
     Test how long it takes to return 1,000th digit from the fibonacci sequence
     :return: Assert that it is less than 5ms
     """
     inquiry = Interface()
     start = time.clock()
     inquiry.ask("What is the 1000 digit of fibonacci?")
     inquiry.teach(fib(1000))
     inquiry.ask("What is the 1000 digit of fibonacci?")
     end = time.clock()
     result = (end - start)
     assert result <= 0.015
示例#41
0
 def test_performance_logic_and(self):
     """
     Test how long it takes to return the output of an AND gate
     :return: Assert that it is less than 8ms
     """
     inquiry = Interface()
     start = time.clock()
     inquiry.ask("What is the output of 1 AND 0?")
     inquiry.teach(logic_gate("What is the output of 1 AND 0?"))
     inquiry.ask("What is the output of 1 AND 0?")
     end = time.clock()
     result = (end - start)
     assert result <= 0.015
示例#42
0
 def test_performance_shape_sides_14(self):
     """
     Test how long it takes to return the name of a 14 sided shape
     :return: Assert that it is less than 5ms
     """
     inquiry = Interface()
     start = time.clock()
     inquiry.ask("What shape has 14 sides?")
     inquiry.teach(number_of_sides(14))
     inquiry.ask("What shape has 14 sides?")
     end = time.clock()
     result = (end - start)
     assert result <= 0.015
 def test_question_answer_noprevious(self):
     """
     Check returns proper output when no question mark.
     :return:
     """
     qaobject = Interface()
     result = qaobject.teach("How now brown cow.")
     self.assertEqual(result, 'Please ask a question first')
 def test_ask_teach_no_previous(self):
     """
     Test teach function, no previous question
     :return: assertion: ask a question
     """
     inquiry = Interface()
     answer = None
     result = inquiry.teach(answer)
     self.assertEqual(result, 'Please ask a question first')
 def test_ask_no_teach(self):
     """
     Test teach function, wrong answer
     :return: assertion: refuse answer
     """
     inquiry = Interface()
     inquiry.ask('What type of triangle is  1 1 1?')
     result = inquiry.teach('trapezoid')
     self.assertEqual(result,
                      'I don\'t know about that. I was taught differently')
 def test_question_update_previous(self):
     """
     Check that correct function works correctly
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What color is the cow?")
     self.assertEqual(result, 'I don\'t know, please provide the answer')
     result = qaobject.teach("The cow is brown")
     self.assertEqual(result, None)
     result = qaobject.correct("The cow is red")
     self.assertEqual(result, None)
     result = qaobject.ask("What color is the cow?")
     self.assertEqual(result, 'The cow is red')
示例#47
0
 def test_ask_store_previous_answer(self):
     obj = Interface()
     obj.ask('What t o t is 5 5 5?')
     obj.teach(get_triangle_type)
     result = obj.ask('What type of triangle is 5 5 5?')
     self.assertEqual(result, 'equilateral')
示例#48
0
 def test_ask_teach_provide_answer(self):
     obj = Interface()
     obj.ask('Who let the dogs out, yesterday?')
     obj.teach('James let the dogs out')
     result = obj.ask('Who let the dogs out, yesterday?')
     self.assertEqual(result, 'James let the dogs out')
示例#49
0
 def test_ask_tri(self):
     obj = Interface()
     obj.ask('What type of t is 1.0 1 1?')
     obj.teach(get_triangle_type)
     result = obj.ask('What type of tri is 1.0 1 1?')
     self.assertEqual(result, 'equilateral')
示例#50
0
 def test_provide_answer(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     result = obj.ask('Why did Abe Lincoln start killing vampires?')
     self.assertEqual(result, 'Because Abe hates glitter')
示例#51
0
 def test_ask_no_previous_question(self):
     obj = Interface()
     result = obj.teach('hello')
     self.assertEqual(result, 'Please ask a question first')
示例#52
0
 def test_no_prev_question(self):
     obj = Interface()
     result = obj.teach('answer')
     self.assertEqual(result, 'Please ask a question first')
示例#53
0
 def test_teach_same_answer(self):
     obj = Interface()
     obj.ask('What color is the sky?')
     obj.teach('The sky is blue')
     result = obj.teach('The sky is blue')
     self.assertEqual(result, 'I don\'t know about that. I was taught differently')