def test_random(self): test_list = [ random.randint(0, 20), random.randint(0, 20), random.randint(0, 20), random.randint(0, 20) ] expected_list = test_list.copy() expected_list.sort() actual_list = bs.bubble_sort(test_list) self.assertEqual(actual_list, expected_list)
def test_one_item(self): self.assertEqual(bubble_sort([0]), [0])
def test_empty_array(self): self.assertEqual(bubble_sort([]), [])
def test_four_item(self): self.assertEqual(bubble_sort([3, 2, 1, 0]), [0, 1, 2, 3])
def test_three_item(self): self.assertEqual(bubble_sort([2, 1, 0]), [0, 1, 2])
def test_two_item(self): self.assertEqual(bubble_sort([1, 0]), [0, 1])
def test_simple(self): test_list = [4, 3, 2, 1] expected_list = test_list.copy() expected_list.sort() actual_list = bs.bubble_sort(test_list) self.assertEqual(actual_list, expected_list)
def test_negative(self): test_list = [-4, -3, -2, -1] expected_list = test_list.copy() expected_list.sort() actual_list = bs.bubble_sort(test_list) self.assertEqual(actual_list, expected_list)
def test_presorted(self): test_list = [1, 2, 3, 4] expected_list = test_list.copy() expected_list.sort() actual_list = bs.bubble_sort(test_list) self.assertEqual(actual_list, expected_list)
def test_empty(self): test_list = [] expected_list = test_list.copy() expected_list.sort() actual_list = bs.bubble_sort(test_list) self.assertEqual(actual_list, expected_list)