示例#1
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')
示例#2
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")
示例#3
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')
示例#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_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_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')
示例#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(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
 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')
示例#10
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")
示例#11
0
 def test_correcting_answer(self):
     """ test correcting an answer """
     attempt = Interface()
     question = "How many sides and corners does a quadrilateral have?"
     attempt.ask(question)
     attempt.teach("four sides.")
     attempt.correct("four sides and corners.")
     result = attempt.ask(question)
     self.assertEqual(result, "four sides and corners.")
示例#12
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_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")
 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')
示例#15
0
 def test_job_story_case_fib(self):
     """
     Test job story case fib
     :return: assertion that the system returns the correct digit of the fibonacci
     sequence
     """
     inquiry = Interface()
     inquiry.ask("What is the 5 digit of fibonacci?")
     inquiry.teach(fib(9))
     result = inquiry.ask("What is the 5 digit of fibonacci?")
     self.assertEqual(result, 34)
     inquiry.ask("What is the 0 digit of fibonacci?")
     inquiry.correct(fib(0))
     result = inquiry.ask("What is the 0 digit of fibonacci?")
     self.assertEqual(result, 0)
示例#16
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)
示例#17
0
    def test_correct_no_question(self):
        """
        func that test for questions and answers
        :rtype: object

        """
        value = Interface()
        self.assertEqual(value.correct(answer="Inside the bag"), 'Please ask a question first')
 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')
 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_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')
 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")
示例#22
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)
 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)
 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)
 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)
 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)
示例#27
0
    def test_valid_match(self):
        """
        func that test for questions and answers
        :rtype: object

        """
        value = Interface()
        value.ask(question="Where is the library?")
        if value.correct(answer="across the street") == "across the street":
            self.assertEqual(value.ask(question="Where is the library?"), "across the street")
示例#28
0
    def test_question_answer_string_type(self):
        """
        func that test for questions and answers
        :rtype: object

        """
        value = Interface()
        self.assertEqual(
            value.ask(question="How are you doing?"),
            "I don't know, please provide the answer")
        self.assertEqual(value.correct(answer=" fine thank you "), None)
示例#29
0
 def test_answer(self):
     """
     func test answer performance
     :param self
     :return: performance time of correct method
     """
     interface = Interface()
     start = time.clock()
     val = interface.correct("No respond")
     proc_time = time.clock() - start
     self.assertTrue(val)
     self.assertLessEqual(proc_time, 0.5)
 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')
 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")
示例#32
0
 def test_no_prev_question_corrected(self):
     obj = Interface()
     result = obj.correct('answer')
     self.assertEqual(result, "Please ask a question first")
示例#33
0
 def test_correct_no_question(self):
     x = Interface()
     self.assertEqual(x.correct(answer="Inside the bag"), 'Please ask a question first')
示例#34
0
 def test_system_update(self):
     x = Interface()
     x.ask(question="Where is the library?")
     x.teach(answer="across the street")
     x.correct("across the river")
示例#35
0
 def test_valid_match(self):
     x = Interface()
     x.ask(question="Where is the library?")
     if x.correct(answer="across the street") == "across the street":
         self.assertEqual(x.ask(question="Where is the library?"), "across the street")
示例#36
0
 def test_exclude_numbers(self):
     x = Interface()
     x.ask(question="How old are you?")
     self.assertEqual(x.correct(answer=12), None)
示例#37
0
 def test_question_answer_string_type(self):
     x = Interface()
     self.assertEqual(x.ask(question="How are you doing?"), "I don't know, please provide the answer")
     self.assertEqual(x.correct(answer=" fine thank you "), None)
示例#38
0
 def test_correcting_no_question(self):
     """ test trying to correct an answer without asking a question """
     attempt = Interface()
     result = attempt.correct("four sides.")
     self.assertEqual(result, "Please ask a question first")
示例#39
0
 def test_correct_no_previous_question(self):
     obj = Interface()
     result = obj.correct('9-11, inside job')
     self.assertEqual(result, 'Please ask a question first')
示例#40
0
class PYTONA(unittest.TestCase):
    def setUp(self):
        self.obj = Interface()

    def test_exceptions(self):
        self.assertRaises(Exception, self.obj.ask, 7)
        self.assertRaises(Exception, self.obj.ask, "Who are 17 you?")

    @requirements(['#0017'])
    def test_teach(self):
        ret = self.obj.teach()
        self.assertEqual(ret, "Please ask a question first")

    @requirements(['#0021'])
    def test_correct(self):
        ret = self.obj.correct()
        self.assertEqual(ret, "Please ask a question first")

    @requirements(['#0016', '#0018'])
    def test_teach_2(self):
        self.obj.ask("What is my name?")
        self.obj.teach("Bubba")
        ret = self.obj.ask("What is my name?")
        self.assertEqual(ret, "Bubba")
        ret = self.obj.teach("Fred")
        self.assertEqual(ret, "I don\'t know about that. I was taught differently")
        ret = self.obj.ask("What is my name?")
        self.assertEqual(ret, "Bubba")

    @requirements(['#0006', '#0007', '#0014'])
    def test_ask(self):
        ret = self.obj.ask("What is 8 feet in miles?")
        self.assertEqual(ret, "I don't know, please provide the answer")
        ret = self.obj.ask("How many seconds since?")
        self.assertEqual(ret, "I don't know, please provide the answer")
        ret = self.obj.ask("Who invented Python?")
        self.assertEqual(ret, "I don't know, please provide the answer")
        ret = self.obj.ask("Why don\'t you understand me?")
        self.assertEqual(ret, "I don't know, please provide the answer")
        ret = self.obj.ask("Why don\'t you shutdown?")
        self.assertEqual(ret, "I don't know, please provide the answer")
        ret = self.obj.ask("Where am I?")
        self.assertEqual(ret, "I don't know, please provide the answer")


    @requirements(['#0008'])
    def test_ask_again(self):
        ret = self.obj.ask("Half Life 3 confirmed?")
        self.assertEqual(ret, "Was that a question?")
        
    @requirements(['#0009'])
    def test_ask_no_question_mark(self):
        ret = self.obj.ask("Half Life 3 confirmed")
        self.assertEqual(ret, "Was that a question?")
                   
    @requirements(['#0010', '#0011', '#0012', '#0013', '#0016'])
    def test_ask_more_questions(self):
        ret = self.obj.ask("What type tf triangle is 5 5 5?")#swapped 'of' with 'tf'
        self.assertEqual(ret, "equilateral")

        ret = self.obj.ask("What typ tf trIange iz 5 5 5?")#really messed up the grammar
        self.assertEqual(ret, "I don't know, please provide the answer")


    @requirements(['#0019', '#0020'])            
    def test_correct_2(self):
        self.obj.ask("What type of quadrilateral is 5 5 5 5 90 90 90 90?")
        self.obj.correct("circle")

        ret = self.obj.ask("What type of quadrilateral is 5 5 5 5 90 90 90 90?")
        self.assertEqual(ret, "circle")

#-------------------------------------------------------------------------------------------------
    @stories(['*0005'])
    def test_job_story_hal(self):
        ret = self.obj.ask("Open the door hal?")
        self.assertEqual(ret, "I'm afraid I can't do that {0}".format(getpass.getuser()))

    @stories(['*0001'])
    def test_job_story_time(self):
        ret = self.obj.ask("What time is it?")
        self.assertEqual(ret, datetime.datetime.now())

    @stories(['*0002'])
    def test_job_story_fibonacci(self):
        ret = self.obj.ask("What is 15 the digit of fibonacci?")
        self.assertEqual(ret, 610)

    @stories(['*0006', '*0007'])
    def test_job_story_unit_conversions(self):
        ret = self.obj.ask("Convert 13 megameters to kilometers?")
        self.assertEqual(ret, 13000.0)
        ret = self.obj.ask("Convert 24 hectometers to decameters?")
        self.assertEqual(ret, 240.0)
        ret = self.obj.ask("Convert 1 meters to decimeters?")
        self.assertEqual(ret, 10)
        ret = self.obj.ask("Convert 54 centimeters to millimeters?")
        self.assertEqual(ret, 540.0)
        ret = self.obj.ask("Convert 62 micrometers to nanometers?")
        self.assertEqual(ret, 61999.99999999999)

    @stories(['*0004'])
    def test_job_story_clear(self):

        self.obj.ask("What is my name?")
        self.obj.teach("Jack")
        ret = self.obj.ask("What is my name?")
        self.assertEqual(ret, "Jack")
        self.obj.ask("Please clear memory?")

        ret = self.obj.ask("What is my name?")
        self.assertEqual(ret, "I don't know, please provide the answer")


    @stories(['*0008', '*0009', '*0010', '*0011', '*0012'])
    def test_more_job_stories(self):
        ret = self.obj.ask("Where is my car?")
        self.assertEqual(ret, "In the driveway {0}".format(getpass.getuser()))

        ret = self.obj.ask("What is the answer to everything?")
        self.assertEqual(ret, "42")

        ret = self.obj.ask("How are you?")
        self.assertEqual(ret, "I am doing well {0}".format(getpass.getuser()))

        ret = self.obj.ask("Who are you?")
        self.assertEqual(ret, "My name is PyTona")

        ret = self.obj.ask("Please shut down hal?")
        self.assertEqual(ret, "I am afraid I cannot do that right now {0}".format(getpass.getuser()))
#------------------------------------------------------------------------------------------

    @requirements(['#0022']) 
    def test_factorial(self):
        ret = self.obj.ask("What is 6 factorial?")
        self.assertEqual(ret, 720)
        
    @requirements(['#0023']) 
    def test_power(self):
        ret = self.obj.ask("What is 2 to the 3 power?")
        self.assertEqual(ret, 8)
        
    @requirements(['#0024']) 
    def test_root(self):
        ret = self.obj.ask("What is the square root of 256?")
        self.assertEqual(ret, 16)
        
    @requirements(['#0025']) 
    def test_degress_to_radians(self):
        ret = self.obj.ask("What is 78 degrees in radians?")
        self.assertEqual(ret, 1)
        
    @requirements(['#0026']) 
    def test_radians_to_degrees(self):
        ret = self.obj.ask("What is 2 radians in degrees?")
        self.assertEqual(ret, 114)

#--------------------------------------------------------------------------------------------------------

    @patch('git_utils.subprocess.Popen')
    def test_if_file_is_in_repo(self, mock_subproc_popen):
        process_mock = mock.Mock()
        attrs = {'communicate.return_value': ('stdout', 'stderr')}
        process_mock.configure_mock(**attrs)
        mock_subproc_popen.return_value = process_mock 
        ret = self.obj.ask("Is the <C:\Python27\Scripts> in the repo?")
        self.assertTrue(mock_subproc_popen.called)
        self.assertEqual(ret, "Yes")

#--------------------------------------------------------------------------------
    @requirements(['#0050', '#0051', '#0052'])
    def test_speed_of_file(self):
        start = time.clock()
        ret = self.obj.ask("What is 2 radians in degrees?")
        proc_time = time.clock() - start
        self.assertLess(proc_time, 0.05)
        self.assertEqual(ret, 114)
        
    @requirements(['#0053'])
    def test_speed_of_convert(self):
        start = time.clock()
        ret = self.obj.ask("Convert 62 micrometers to nanometers?")
        proc_time = time.clock() - start
        self.assertLess(proc_time, 0.005)
        self.assertEqual(ret, 61999.99999999999)

    @requirements(['#0054'])
    def test_speed_of_fib(self):
        start = time.clock()
        ret = self.obj.ask("What is the 11 digit of fibonacci?")
        proc_time = time.clock() - start
        self.assertLess(proc_time, 0.01)
        self.assertEqual(ret, 89)
        
    @requirements(['#0055'])
    def test_speed_of_fac(self):
        start = time.clock()
        ret = self.obj.ask("What is 10 factorial?")
        proc_time = time.clock() - start
        self.assertLess(proc_time, 0.015)
        self.assertEqual(ret, 3628800)
        
    @requirements(['#0056'])
    def test_speed_of_sqrt(self):
        start = time.clock()
        ret = self.obj.ask("What is the square root of 256?")
        proc_time = time.clock() - start
        self.assertLess(proc_time, 0.015)
        self.assertEqual(ret, 16.0)
        
    @requirements(['#0057'])
    def test_speed_of_pwr(self):
        start = time.clock()
        ret = self.obj.ask("What is 4 to the 3 power?")
        proc_time = time.clock() - start
        self.assertLess(proc_time, 0.015)
        self.assertEqual(ret, 64)