def test_always_happy(self):
     new_interface = Interface()
     start_time = time.clock()
     result = new_interface.ask("Are you happy?")
     end_time = time.clock()
     self.assertLess(end_time - start_time, .02)
     self.assertEqual(result, "I'm always happy!")
示例#2
0
 def test_convert_units_to_units(self):
     '''
     This function tests the interface for unit conversion.
     '''
     interface = Interface()
     result = interface.ask("Convert 1 meter to centimeters")
     self.assertEqual(result, "100.0 centimeters")
示例#3
0
 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")
 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))
 def test_my_subtract_invalid_number(self):
     new_interface = Interface()
     start_time = time.clock()
     result = new_interface.ask("Please subtract something with something.")
     end_time = time.clock()
     self.assertLess(end_time - start_time, .05)
     self.assertEqual(result, "I don't know, please provide the answer")
示例#6
0
 def test_prime_number(self):
     '''
     This function tests the interface for prime number retrieval.
     '''
     interface = Interface()
     result = interface.ask("What is the 10 prime number?")
     self.assertEqual(result, 29)
示例#7
0
 def test_current_directory(self):
     '''
     This function tests the interface for current directory retrieval.
     '''
     interface = Interface()
     result = interface.ask("What directory is this using?")
     self.assertEqual(result.lower(), os.getcwd().lower())
示例#8
0
 def test_teach(self):
     x = Interface()
     start = time.clock()
     val = x.teach("No respond")
     proc_time = time.clock() - start
     self.assertTrue(val)
     self.assertLessEqual(proc_time, 0.5)
示例#9
0
 def test_pi_digit(self):
     '''
     This function tests the interface for pi digits.
     '''
     interface = Interface()
     result = interface.ask("What is the 5 digit of pi?")
     self.assertEqual(result, 5)
示例#10
0
 def test_numberic_no_conversion(self):
     '''
     This function tests the interface for incorrect unit conversion.
     '''
     interface = Interface()
     result = interface.ask("Convert 1 meter to quadrillometers")
     self.assertEqual(result, "Sorry, I can't convert that.")
示例#11
0
 def test_question5(self):
     x = Interface()
     start = time.clock()
     val = x.ask("Why are you like this???")
     proc_time = time.clock() - start
     self.assertTrue(val)
     self.assertLessEqual(proc_time, 0.5)
示例#12
0
 def test_date_time(self):
     '''
     This function tests the interface for the corret time.
     '''
     interface = Interface()
     result = interface.ask("What time is it?")
     self.assertEqual(result[:17], datetime.datetime.now().isoformat()[:17])
示例#13
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')
示例#14
0
 def test_hello_valid(self):
     new_interface = Interface()
     test_string1 = "Hello?"
     result = new_interface.ask(test_string1)
     user = getuser()
     expected_result = ("Hello, I am " + user + "'s guide.")
     self.assertEqual(result, expected_result)
示例#15
0
 def test_fibonacci_digit(self):
     '''
     This function tests the interface for the fibonacci sequence.
     '''
     interface = Interface()
     result = interface.ask("What is the 10 digit of fibonacci?")
     self.assertEqual(result, 34)
示例#16
0
 def test_open_door(self):
     new_interface = Interface()
     test_string1 = "Open the door hal."
     result = new_interface.ask(test_string1)
     expected_user = getuser()
     expected_result = ("I'm afraid I can't do that " + expected_user)
     self.assertEqual(result, expected_result)
示例#17
0
 def test_question_datetime_correct(self):
     new_interface = Interface()
     test_string1 = "What time is it?"
     result = new_interface.ask(test_string1)
     curr_time = datetime.now()
     curr_time = curr_time.replace(second=0, microsecond=0)
     self.assertEqual(result, str(curr_time))
示例#18
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")
示例#19
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')
示例#20
0
 def test_set_user_name(self):
     '''
     This function tests the interface for username recognition.
     '''
     interface = Interface()
     result = interface.set_user("Dave")
     self.assertEqual(result, "Hello, Dave.")
示例#21
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')
 def test_my_subtract_float(self):
     new_interface = Interface()
     start_time = time.clock()
     result = new_interface.ask("Please subtract 1.0 and 2.0.")
     end_time = time.clock()
     self.assertLess(end_time - start_time, .05)
     self.assertEqual(result, -1.0)
示例#23
0
 def test_answer(self):
     x = Interface()
     start = time.clock()
     val = x.correct("No respond")
     proc_time = time.clock() - start
     self.assertTrue(val)
     self.assertLessEqual(proc_time, 0.5)
 def test_convert_cm_m_int(self):
     new_interface = Interface()
     start_time = time.clock()
     result = new_interface.ask("Convert 500 cm to m.")
     end_time = time.clock()
     self.assertLess(end_time - start_time, .05)
     self.assertEqual(result, 5)
 def test_my_add_int(self):
     new_interface = Interface()
     start_time = time.clock()
     result = new_interface.ask("Please add 1 and 2.")
     end_time = time.clock()
     self.assertLess(end_time - start_time, .05)
     self.assertEqual(result, 3)
 def test_ask_open_door(self):
     new_interface = Interface()
     start_time = time.clock()
     result = new_interface.ask("Open the door hal!")
     end_time = time.clock()
     self.assertLess(end_time - start_time, .05)
     self.assertEqual(result, "I'm afraid I can't do that " + getpass.getuser())
 def test_fileStatus_Dirty(self, mock_dirty, mock_untracked, mock_diff):
     obj = Interface()
     mock_diff.return_value = []
     mock_dirty.return_value = True
     mock_untracked.return_value = []
     result = obj.ask('What is the status of <requirements.txt>?')
     self.assertEqual(result, 'requirements.txt is a dirty repo')
 def test_get_git_file_info_upToDate(self, mock_is_repo_dirty, mock_get_untracked_files, mock_get_diff_files):
     obj = Interface()
     mock_get_diff_files.return_value = []
     mock_get_untracked_files.return_value = []
     mock_is_repo_dirty.return_value = False
     result = obj.ask('What is the status of <requirements.txt>?')
     self.assertEqual(result, 'requirements.txt is up to date')
示例#29
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)
示例#30
0
 def test_story_ten_unit_conversions(self):
     obj = Interface()
     result = obj.ask("What are numeric conversions?")
     self.assertEqual(result,
                      'tera = 6, giga = 5, mega = 4, kilo = 3, deca = 1, no_unit = 0, deci = -1, centi = -2, '
                      '\n milli = -3, micro = -4, nano = -5, pico = -6; '
                      '\n Format = "Convert <value> <unit> to <unit to convert to>"')
示例#31
0
 def test_question4(self):
     x = Interface()
     start = time.clock()
     val = x.ask("1236")
     proc_time = time.clock() - start
     self.assertTrue(val)
     self.assertLessEqual(proc_time, 0.5)
 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))
示例#33
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."
     )
示例#34
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')
示例#35
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")
示例#36
0
 def test_ask_open_door(self):
     obj = Interface()
     question = 'Open the door hal'
     result = obj.demand(question)
     output_to_file(question, result)
     self.assertEqual(result,
                      'I\'m afraid I can\'t do that ' + getpass.getuser())
示例#37
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'
     )
 def test_question_90percentmatch(self):
     """
     Check returns proper output for question 90% similar to stored question.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What type of quadrilteral is: 2 2 2 2 90 90 90 90?")
     self.assertEqual(result, 'square')
 def test_question_string(self):
     """
     Check returns proper output for improper question
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What_type_of_triangle_is: 3 3 3?")
     self.assertEqual(result, 'Was that a question?')
 def test_question_string_noqmark(self):
     """
     Check returns proper output for now question mark.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What type of triangle is: 3 3 3")
     self.assertEqual(result, 'Was that a question?')
 def test_question_string_nokeyword(self):
     """
     Check returns proper output for unknown question.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("Is that a dog?")
     self.assertEqual(result, 'I don\'t know, please provide the answer')
 def test_question_string_answer(self):
     """
     Check triangle return correct
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask('What type of triangle is: 3 4 5?')
     self.assertEqual(result, 'scalene')
 def test_question_update_noprevious(self):
     """
     Check that correct responds correctly when no previous question exists.
     :return:
     """
     qaobject = Interface()
     result = qaobject.correct("42")
     self.assertEqual(result, 'Please ask a question first')
 def test_ask_quad_no_keyword(self):
     """
     Test ask function quadrilateral no keyword
     :return: assertion: Was that a question?
     """
     inquiry = Interface()
     result = inquiry.ask('many sides does a quadrilateral have?')
     self.assertEqual(result, "Was that a question?")
示例#45
0
 def test_story_ten_unit_conversions(self):
     obj = Interface()
     result = obj.ask("What are numeric conversions?")
     self.assertEqual(
         result,
         'tera = 6, giga = 5, mega = 4, kilo = 3, deca = 1, no_unit = 0, deci = -1, centi = -2, '
         '\n milli = -3, micro = -4, nano = -5, pico = -6; '
         '\n Format = "Convert <value> <unit> to <unit to convert to>"')
 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')
 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_quad_no_answer(self):
     """
     Test ask function quadrilateral no answer
     :return: assertion: ask to provide answer
     """
     inquiry = Interface()
     result = inquiry.ask('How many sides does a quadrilateral have?')
     self.assertEqual(result, "I don't know, please provide the answer")
 def test_ask_no_correct(self):
     """
     Test correct function, no question
     :return: assertion: ask question first
     """
     inquiry = Interface()
     result = inquiry.correct('polygon')
     self.assertEqual(result, 'Please ask a question first')
示例#50
0
 def test_file_not_in_repo(self, mock_subproc_popen):
     obj = Interface()
     process_mock = Mock()
     attrs = {'communicate.return_value': ('test.txt', '')}
     process_mock.configure_mock(**attrs)
     mock_subproc_popen.return_value = process_mock
     result = obj.ask('Is the <test.txt> in the repo?')
     self.assertEqual(result, 'No')
 def test_ask_bad_question(self):
     """
     Test ask function bad question
     :return: assertion: provide answer
     """
     inquiry = Interface()
     result = inquiry.ask('What kind of shape has sides 1 1 3?')
     self.assertEqual(result, "I don't know, please provide the answer")
 def test_ask_no_values(self):
     """
     Test ask function no values
     :return: assertion: invalid
     """
     inquiry = Interface()
     result = inquiry.ask('What type of triangle is this?')
     self.assertEqual(result, "invalid")
 def test_ask_no_question_mark(self):
     """
     Test ask function no question mark
     :return: assertion: Was that a question?
     """
     inquiry = Interface()
     result = inquiry.ask('What type of triangle is isosceles')
     self.assertEqual(result, "Was that a question?")
 def test_ask_tri_isosceles(self):
     """
     Test ask function triangle isosceles
     :return: assertion: isosceles
     """
     inquiry = Interface()
     result = inquiry.ask('What type of triangle is 1 1 3?')
     self.assertEqual(result, 'isosceles')
 def test_ask_tri_no_answer(self):
     """
     Test ask function triangle no answer
     :return: assertion: ask to provide answer
     """
     inquiry = Interface()
     result = inquiry.ask('What type of triangle is isosceles?')
     self.assertEqual(result, "I don't know, please provide the answer")
 def test_ask_tri_no_keyword(self):
     """
     Test ask function triangle no keyword
     :return: assertion: Was that a question?
     """
     inquiry = Interface()
     result = inquiry.ask('many sides does a triangle have?')
     self.assertEqual(result, "Was that a question?")
 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)
示例#58
0
 def test_get_rock_dropped(self):
     """
     Checks rock drop question for code coverage.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What is the velocity of a rock dropped from 10 meters"
                           " just before it hits the ground?")
     self.assertEqual(result, 14)
 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)
示例#60
0
 def test_get_boiing_elevation(self):
     """
     Checks boilng/elevation question for code coverage purposes.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What is the boiling temperaturem in degrees fahrenheit,"
                           " at 10000 feet?")
     self.assertEqual(result, 193.6)