def test_question_three(self): """using the 'median-of-three' pivot rule""" q3_list, q3_comparisons = quick_sort(self.orginal_list, median_of_three) self.orginal_list.sort() self.assertListEqual(self.orginal_list, q3_list) self.solution.write('Question three: {0}\n'.format(q3_comparisons))
def test_question_three(self): """using the 'median-of-three' pivot rule""" q3_list, q3_comparisons = quick_sort(self.orginal_list, median_of_three) self.orginal_list.sort() self.assertListEqual(self.orginal_list, q3_list) self.solution.write('Question three: {0}\n'.format(q3_comparisons))
def test_file_count_comparisons_from_1000txt(self): i = file_to_list('../test_files/1000.txt') expected = 8921 _, returned= quick_sort(i, median_of_three) self.assertEqual(expected, returned)
def test_question_two(self): """question two: if pivot is alaywas the last element""" q2_list, q2_comparisons = quick_sort(self.orginal_list, last) self.orginal_list.sort() self.assertListEqual(self.orginal_list, q2_list) self.solution.write('Question two: {0}\n'.format(q2_comparisons))
def test_question_one(self): """question one: if the first pivot is always the first one""" q1_list, q1_comparisons = quick_sort(self.orginal_list, first) self.orginal_list.sort() self.assertListEqual(self.orginal_list, q1_list) self.solution.writelines('Question one: {0}\n'.format(q1_comparisons))
def test_file_count_comparisons_from_1000txt(self): i = file_to_list('../test_files/1000.txt') expected = 10297 _, returned= quick_sort(i, first) self.assertEqual(expected, returned)
def test_file_count_comparisons_from_1000txt(self): i = file_to_list('../test_files/1000.txt') expected = 10297 _, returned = quick_sort(i, first) self.assertEqual(expected, returned)
def test_question_one(self): """question one: if the first pivot is always the first one""" q1_list, q1_comparisons = quick_sort(self.orginal_list, first) self.orginal_list.sort() self.assertListEqual(self.orginal_list, q1_list) self.solution.writelines('Question one: {0}\n'.format(q1_comparisons))
def test_question_two(self): """question two: if pivot is alaywas the last element""" q2_list, q2_comparisons = quick_sort(self.orginal_list, last) self.orginal_list.sort() self.assertListEqual(self.orginal_list, q2_list) self.solution.write('Question two: {0}\n'.format(q2_comparisons))
def test_four_equal(self): i = [0, 4, 4 ,4] expected = [0, 4, 4, 4] returned, _ = quick_sort(i) self.assertListEqual(expected, returned)
def test_file_10txt(self): i = file_to_list('../test_files/10.txt') expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] result, _ = quick_sort(i) self.assertListEqual(expected, result)
def test_four_items(self): i = [0, 3, 2 ,1] expected = [0, 1, 2, 3] returned,_ = quick_sort(i) self.assertListEqual(expected, returned)
def test_three_items(self): i = [3, 2 ,1] expected = [1, 2, 3] returned,_ = quick_sort(i) self.assertListEqual(expected, returned)
def test_two_items(self): i = [2,1] expected = [1, 2] returned, _ = quick_sort(i) self.assertListEqual(expected, returned)
def test_one_item(self): i = [1] expected = [1] returned, _ = quick_sort(i) self.assertListEqual(expected, returned)
def test_empty(self): i = [] expected = [] returned, _ = quick_sort(i) self.assertListEqual(expected, returned)