コード例 #1
0
 def test_selection_sort_unsortable_list(self, mock_stdout):
     selection_sort(['2', 'a'])
     actual = mock_stdout.getvalue()
     expected = ""
     self.assertEqual(expected, actual)
コード例 #2
0
 def test_selection_sort_all_integers(self):
     actual = selection_sort(['2', '1', '5', '4', '3', '6'])
     expected = ['1', '2', '3', '4', '5', '6']
     self.assertEqual(expected, actual)
コード例 #3
0
 def test_selection_sort_integers_and_floats(self):
     actual = selection_sort(['2', '1.3', '5.3', '4', '2.3', '6'])
     expected = ['1.3', '2', '2.3', '4', '5.3', '6']
     self.assertEqual(expected, actual)
コード例 #4
0
 def test_selection_sort_empty_list(self, mock_stdout):
     selection_sort([])
     actual = mock_stdout.getvalue()
     expected = "Error: Empty list is not a valid value.\n"
     self.assertEqual(expected, actual)
コード例 #5
0
 def test_selection_sort_all_floats(self):
     actual = selection_sort(['2.3', '2.7', '5.1', '5.9', '4.2', '1.3'])
     expected = ['1.3', '2.3', '2.7', '4.2', '5.1', '5.9']
     self.assertEqual(expected, actual)
コード例 #6
0
 def test_selection_sort_all_strings(self):
     actual = selection_sort(['e', 'a', 'c', 'd', 'b', 'f'])
     expected = ['a', 'b', 'c', 'd', 'e', 'f']
     self.assertEqual(expected, actual)
コード例 #7
0
 def test_selection_sort_normal_list(self):
     self.assertEqual([-4, 1, 3, 5, 9], selection_sort([3, 5, 1, 9, -4]))
コード例 #8
0
 def test_selection_sort_already_sorted_list(self):
     self.assertEqual([-4, 1, 3, 5, 9], selection_sort([-4, 1, 3, 5, 9]))
コード例 #9
0
 def test_selection_non_sortable_list_raises_error(self):
     with self.assertRaises(TypeError):
         selection_sort(['aardvark', True, 'zebra'])
コード例 #10
0
 def test_selection_sort_non_list_raises_error(self):
     with self.assertRaises(TypeError):
         selection_sort('boo')
コード例 #11
0
 def test_selection_sort_empty_list_raises_error(self):  # ToDo: FAILED
     with self.assertRaises(IndexError):
         selection_sort([])
コード例 #12
0
 def test_selection_sort_elements_are_strings(self):
     self.assertEqual(['aardvark', 'apple', 'b', 'b', 'berry', 'cherry'], selection_sort(['cherry', 'b', 'apple',
                                                                                          'berry', 'aardvark', 'b']))
コード例 #13
0
 def test_selection_sort_duplicates_exist(self):
     self.assertEqual([1, 2, 2, 4, 6, 7], selection_sort([4, 1, 2, 6, 7, 2]))