Пример #1
0
 def testGoogleInterviewReplaceVarsInStringShorterNames(self):
     input_string = "/user/%USER%/home/%TMP%"
     vars_dict = {"USER": "******", "TMP": "ba"}
     expected_result = "/user/foo/home/ba"
     actual_result = GoogleInterview().replace_vars_in_string(
         input_string, vars_dict)
     self.assertEqual(expected_result, actual_result)
Пример #2
0
 def testGoogleInterviewReplaceVarsInStringMixedLength(self):
     input_string = "/user/%USER%/home/%TMP%"
     vars_dict = {"USER": "******", "TMP": "tmp_folder"}
     expected_result = "/user/foo/home/tmp_folder"
     actual_result = GoogleInterview().replace_vars_in_string(
         input_string, vars_dict)
     self.assertEqual(expected_result, actual_result)
Пример #3
0
 def testGoogleInterviewProcessStringMultiEmpty(self):
     given_string = 'Google,GOO21W,"",'
     expected_result = {
         'Company': 'Google',
         'SKU': 'GOO21W',
         'Description': '',
         'Price': ''
     }
     actual_result = GoogleInterview().process_string(given_string)
     self.assertEqual(expected_result, actual_result)
Пример #4
0
 def testGoogleInterviewProcessStringMiddleEmpty(self):
     given_string = 'Google,,"Pixel 5, 5G, Google-assistance",629.10'
     expected_result = {
         'Company': 'Google',
         'SKU': '',
         'Description': 'Pixel 5, 5G, Google-assistance',
         'Price': '629.10'
     }
     actual_result = GoogleInterview().process_string(given_string)
     self.assertEqual(expected_result, actual_result)
Пример #5
0
 def testGoogleInterviewProcessStringProcessStringStartQuotes(self):
     given_string = '"Google",GOO21W,Pixel,629.10'
     expected_result = {
         'Company': 'Google',
         'SKU': 'GOO21W',
         'Description': 'Pixel',
         'Price': '629.10'
     }
     actual_result = GoogleInterview().process_string(given_string)
     self.assertEqual(expected_result, actual_result)
Пример #6
0
 def testGoogleInterviewCountDistanceBFS0(self):
     start = "A"
     finish = "A"
     connections = [
         ("A", "C"),
         ("B", "C"),
     ]
     expected_result = 0
     actual_result = GoogleInterview().count_distance_bfs(
         start, finish, connections)
     self.assertEqual(expected_result, actual_result)
Пример #7
0
 def testGoogleInterviewCountDistanceBFSLooped2Way(self):
     start = "A"
     finish = "G"
     connections = [
         ("A", "C"),
         ("B", "C"),
         ("C", "D"),
         ("E", "D"),
         ("E", "B"),
         ("F", "E"),
         ("F", "G"),
         ("G", "E"),
     ]
     expected_result = 4
     actual_result = GoogleInterview().count_distance_bfs(
         start, finish, connections)
     self.assertEqual(expected_result, actual_result)
Пример #8
0
 def testGoogleInterviewReplaceVarsInStringNoVariable(self):
     input_string = "/user/%USER%/home/%TMP%"
     vars_dict = {"USER": "******"}
     with self.assertRaises(Exception) as error:
         GoogleInterview().replace_vars_in_string(input_string, vars_dict)
     self.assertEqual(str(error.exception), 'No variable %TMP% is found')
Пример #9
0
 def testGoogleInterviewLuggageHandlingEmpty(self):
     luggage_input = []
     with self.assertRaises(ValueError) as error:
         GoogleInterview().luggage_handling(luggage_input)
     self.assertEqual(str(error.exception), 'Nothing to transport')
Пример #10
0
 def testGoogleInterviewLuggageHandlingTooBig(self):
     luggage_input = [1, 2, 5, 4, 41]
     with self.assertRaises(ValueError) as error:
         GoogleInterview().luggage_handling(luggage_input)
     self.assertEqual(str(error.exception), 'This is too big')
Пример #11
0
 def testGoogleInterviewLuggageHandlingMultipleZeros(self):
     luggage_input = [0, 0, 0, 0]
     expected_result = [0, 0, 0, 0]
     actual_result = GoogleInterview().luggage_handling(luggage_input)
     self.assertEqual(expected_result, actual_result)
Пример #12
0
 def testGoogleInterviewLuggageHandlingWithZero(self):
     luggage_input = [10, 0, 15, 40, 25]
     expected_result = [25, 40, 10, 0, 15]
     actual_result = GoogleInterview().luggage_handling(luggage_input)
     self.assertEqual(expected_result, actual_result)
Пример #13
0
 def testGoogleInterviewLuggageHandlingOneContainer(self):
     luggage_input = [1, 2, 5, 4, 15]
     expected_result = [1, 2, 5, 4, 15]
     actual_result = GoogleInterview().luggage_handling(luggage_input)
     self.assertEqual(expected_result, actual_result)