コード例 #1
0
 def test_question_prev_function_ptr(self):
     new_interface = Interface()
     test_string1 = "How did a function ptr get here?"
     result = new_interface.ask(test_string1)
     result = new_interface.teach(get_quadrilateral_type)
     result = new_interface.ask(test_string1)
     self.assertEqual(result, "invalid")
コード例 #2
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.")
コード例 #3
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')
コード例 #4
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')
コード例 #5
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')
コード例 #6
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")
コード例 #7
0
ファイル: main_test.py プロジェクト: david-barnes/CST236_Lab7
 def test_giving_answer_known(self):
     """ test teaching an answer to a question with a known answer  """
     attempt = Interface()
     question = "What type of quadrilateral is ?"
     attempt.ask(question)
     result = attempt.teach("square")
     self.assertEqual(result, "I don't know about that. I was taught differently")
コード例 #8
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')
コード例 #9
0
ファイル: main_test.py プロジェクト: OregonTech/JeredS
 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")
コード例 #10
0
 def test_questions_keywords(self):
     x = Interface()
     self.assertEqual(x.ask(question="How ?"), "I don't know, please provide the answer")
     self.assertEqual(x.ask(question="How ?"), "I don't know, please provide the answer")
     self.assertEqual(x.ask(question="Where ?"), "I don't know, please provide the answer")
     self.assertEqual(x.ask(question="Who ?"), "I don't know, please provide the answer")
     self.assertEqual(x.ask(question="Why ?"), "I don't know, please provide the answer")
コード例 #11
0
ファイル: main_test.py プロジェクト: OregonTech/JeredS
 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")
コード例 #12
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')
コード例 #13
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')
コード例 #14
0
ファイル: interface_test.py プロジェクト: Hyatus/CST236Lab7
 def test_numberic_conversion(self):
     '''
     This function tests the interface for multiple unit conversion.
     '''
     interface = Interface()
     result1 = interface.ask("Convert 1 meter to gigameters")
     self.assertEqual(result1, "1e-09 gigameters")
     result2 = interface.ask("Convert 1 meter to megameters")
     self.assertEqual(result2, "1e-06 megameters")
     result3 = interface.ask("Convert 1 meter to kilometers")
     self.assertEqual(result3, "0.001 kilometers")
     result4 = interface.ask("Convert 1 meter to hectometers")
     self.assertEqual(result4, "0.01 hectometers")
     result5 = interface.ask("Convert 10 meter to decameters")
     self.assertEqual(result5, "1 decameter")
     result6 = interface.ask("Convert 1 meter to decimeters")
     self.assertEqual(result6, "10.0 decimeters")
     result7 = interface.ask("Convert 1 meter to centimeters")
     self.assertEqual(result7, "100.0 centimeters")
     result8 = interface.ask("Convert 1 meter to millimeters")
     self.assertEqual(result8, "1000.0 millimeters")
     result9 = interface.ask("Convert 1 meter to micrometers")
     self.assertEqual(result9, "1000000.0 micrometers")
     result10 = interface.ask("Convert 1 meter to nanometers")
     self.assertEqual(result10, "1000000000.0 nanometers")
コード例 #15
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)
コード例 #16
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)
コード例 #17
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")
コード例 #18
0
ファイル: main_test.py プロジェクト: david-barnes/CST236_Lab7
 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.")
コード例 #19
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')
コード例 #20
0
 def test_ask_correct_quad(self):
     """
     Test correct function, quadrilateral polygon
     :return: assertion: none
     """
     inquiry = Interface()
     inquiry.ask('What type of quadrilateral is  1 1 1 1 90 90 90 90?')
     result = inquiry.correct('polygon')
     self.assertEqual(result, None)
コード例 #21
0
 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')
コード例 #22
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")
コード例 #23
0
ファイル: qa_checker_test.py プロジェクト: Hyatus/CST236Lab7
 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)
コード例 #24
0
 def test_ask_correct_tri(self):
     """
     Test correct function, triangle polygon
     :return: assertion: none
     """
     inquiry = Interface()
     inquiry.ask('What type of triangle is  1 1 1?')
     result = inquiry.correct('polygon')
     self.assertEqual(result, None)
コード例 #25
0
    def test_exclude_numbers(self):
        """
        func that test for questions and answers
        :rtype: object

        """
        value = Interface()
        value.ask(question="How old are you?")
        self.assertEqual(value.correct(answer=12), None)
コード例 #26
0
ファイル: mock_test.py プロジェクト: david-barnes/CST236_Lab7
 def test_mock_non_exist(self, mock_subproc_popen):
     """ test to see if an exception is raised """
     process_mock = mock.Mock()
     attrs = {'communicate.return_value': ('', '')}
     process_mock.configure_mock(**attrs)
     mock_subproc_popen.return_value = process_mock
     attempt = Interface()
     with self.assertRaises(Exception, msg="Path filename does not exist cannot get git file"):
         attempt.ask("What is the status of <filename>?")
コード例 #27
0
 def test_ask_correct_tri(self):
     """
     Test correct function, triangle polygon
     :return: assertion: none
     """
     inquiry = Interface()
     inquiry.ask('What type of triangle is  1 1 1?')
     result = inquiry.correct('polygon')
     self.assertEqual(result, None)
コード例 #28
0
ファイル: qa_checker_test.py プロジェクト: Hyatus/CST236Lab7
 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!")
コード例 #29
0
 def test_ask_correct_quad(self):
     """
     Test correct function, quadrilateral polygon
     :return: assertion: none
     """
     inquiry = Interface()
     inquiry.ask('What type of quadrilateral is  1 1 1 1 90 90 90 90?')
     result = inquiry.correct('polygon')
     self.assertEqual(result, None)
コード例 #30
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)
コード例 #31
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())
コード例 #32
0
 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')
コード例 #33
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()))
コード例 #34
0
 def test_question_validmatch(self):
     """
     Check returns valid mathc for question answer
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What of trangle is: 2 2 2?")
     self.assertEqual(result, 'I don\'t know, please provide the answer')
     result = qaobject.ask("What type of triangle is: 2.5 2.5 2.5?")
     self.assertEqual(result, 'equilateral')
コード例 #35
0
 def test_question_pi_nthdigit(self):
     """
     Tests for correct result of valid entries in Pi function.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What is the 3 digit of pi?")
     self.assertEqual(result, 4)
     result = qaobject.ask("What is the 9 digit of pi?")
     self.assertEqual(result, 5)
コード例 #36
0
ファイル: interface_test.py プロジェクト: Hyatus/CST236Lab7
 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.")
コード例 #37
0
 def test_ask_cat_color(self):
     """
     Test random result of colored kitten question.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What color is the kitten?")
     self.assertTrue(result in qaobject.colors)
     result = qaobject.ask("What color is the kitten?")
     self.assertTrue(result in qaobject.colors)
コード例 #38
0
 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')
コード例 #39
0
def time_performance(question):
    """
    Performance counter function. Times time taken to complete operation
    :param question: String
    :return: float of total_time for question operation
    """
    qaobject = Interface()
    start_time = time.clock()
    qaobject.ask(question)
    total_time = time.clock() - start_time
    return total_time
コード例 #40
0
 def test_performance_time_check(self):
     """
     Test how long it takes to return the date and time
     :return: Assert that it is less than 5ms
     """
     inquiry = Interface()
     start = time.clock()
     inquiry.ask("What time is it?")
     end = time.clock()
     result = (end - start)
     print result
     assert result <= 0.015
コード例 #41
0
 def test_coin_count(self):
     """
     Checks coin count, with different configurations, for code coverage.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What is the smallest amount of coins that"
                           " can be returned for: 1.75?")
     self.assertEqual(result, "7 quarters, 0 dimes, 0 nickels, and 0 pennies.")
     result = qaobject.ask("What is the smallest amount of coins that"
                           " can be returned for: 1.23?")
     self.assertEqual(result, "4 quarters, 2 dimes, 0 nickels, and 3 pennies.")
コード例 #42
0
 def test_performance_log_file(self):
     """
     Test how long it takes to write a test to log_file.
     :return: Assert that it is less than 50ms
     """
     inquiry = Interface()
     start = time.clock()
     inquiry.ask('What type of triangle is 1 1 3?')
     end = time.clock()
     result = (end - start)
     print result
     assert result <= 0.050
コード例 #43
0
 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')
コード例 #44
0
 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')
コード例 #45
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
コード例 #46
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
コード例 #47
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
コード例 #48
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
コード例 #49
0
 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')
コード例 #50
0
 def test_right_triangle_angles(self):
     """
     Does right angle triangle tests for code coverage.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What are the angle measurements of a right triangle"
                           " with side lengths: 3 4 5?")
     self.assertEqual(result, "90.0 degrees, 53.13 degrees, and 36.87 degrees")
     result = qaobject.ask("What are the angle measurements of a right triangle"
                           " with side lengths: 10 10 14.1?")
     self.assertEqual(result, "90.0 degrees, 45.0 degrees, and 45.0 degrees")
     result = qaobject.ask("What are the angle measurements of a right triangle"
                           " with side lengths: 6 6 6?")
     self.assertEqual(result, "Not a right triangle")
コード例 #51
0
 def test_git_utils_path_untracked(self, mock_subproc_popen):
     """
     Checks if ability to detected files which have not been checked in, is operational
     :param mock_subproc_popen: Function who's return is mocked
     :return:
     """
     p_mock1 = mock.Mock()
     attrs = {'communicate.return_value': ('', '')}
     p_mock1.configure_mock(**attrs)
     attrs = {'communicate.return_value': ('', '')}
     p_mock2 = mock.Mock()
     p_mock2.configure_mock(**attrs)
     attrs = {'communicate.return_value': ('didntcommit.txt', '')}
     p_mock3 = mock.Mock()
     p_mock3.configure_mock(**attrs)
     attrs = {'communicate.return_value': (PARENT_DIRECTORY, '')}
     p_mock4 = mock.Mock()
     p_mock4.configure_mock(**attrs)
     mock_subproc_popen.side_effect = [p_mock1, p_mock2, p_mock3, p_mock4]
     qaobject = Interface()
     result = qaobject.ask("What is the status of <didntcommit.txt>?")
     self.assertEqual(result,
                      'didntcommit.txt has been not been checked in')
     self.assertRaises(Exception, git_utils.get_git_file_info,
                       'X/:somethingnottrue')
コード例 #52
0
 def test_story_color_list(self):
     obj = Interface()
     result = obj.ask("What are color conversions?")
     self.assertEqual(
         result,
         'yellow, red, and blue are the primary colors available for mixing'
     )
コード例 #53
0
 def test_story_joke(self):
     obj = Interface()
     result = obj.ask("Tell me a joke!")
     self.assertEqual(
         result,
         "To whoever took my Microsoft Office: I will find you. You have my Word."
     )
コード例 #54
0
 def test_file_dirty(self, mock_dirty, mock_untracked, mock_diff):
     obj = Interface()
     mock_diff.return_value = []
     mock_dirty = True
     mock_untracked.return_value = []
     result = obj.ask('What is the status of <requirements.txt>?')
     self.assertEqual(result, 'requirements.txt is a dirty repo')
コード例 #55
0
    def test_ask_who_let_dogs_out(self):
        obj = Interface()
        question = 'Who let the dogs out?'
        result = obj.ask(question)
        output_to_file(question, result)

        self.assertEqual(result, getpass.getuser() + ' let the dogs out')
コード例 #56
0
 def test_ask_not_string(self):
     """
     Test ask function not string
     :return: assertion: exception: not string
     """
     inquiry = Interface()
     self.assertRaises(Exception, lambda: inquiry.ask(12))
コード例 #57
0
 def test_question_number_placement(self):
     """
     Check returns correct answer when numbers are placed incorrectly.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What type 2 of trangle is: 2 2?")
     self.assertEqual(result, 'equilateral')