def test_insertion_sort(self): random_list = [random.randint(-10, 10) for _ in range(10)] print('None input') self.assertRaises(ValueError, insertion_sort, None) self.assertRaises(ValueError, insertion_sort, [], None) print('Empty input') self.assertEqual(insertion_sort([]), []) print('One element') self.assertEqual(insertion_sort([ 1, ]), [ 1, ]) print('Two or more elements') self.assertEqual(insertion_sort(random_list), sorted(random_list)) print('Two or more elements in reverse') self.assertEqual(insertion_sort(random_list, reverse=True), sorted(random_list, reverse=True)) print('Success: test_insertion_sort')
def test_insertion_sort(self) -> None: generator = ArrayGenerator() easy_test_cases = generator.generate(size=10) for test_case in easy_test_cases: answer = list(sorted(test_case)) self.assertEqual(answer, (insertion_sort(test_case))) hard_test_cases = generator.generate(size=1000) for test_case in hard_test_cases: answer = list(sorted(test_case)) self.assertEqual(answer, insertion_sort(test_case))
def test_insertion_sort(self): sorted = insertion_sort(self._unsorted) assert (sorted[0] == 1) assert (sorted[1] == 2) assert (sorted[2] == 3) assert (sorted[3] == 4) assert (sorted[4] == 5) assert (sorted[5] == 6) assert (sorted[6] == 7) assert (sorted[7] == 8) assert (sorted[8] == 9)
screen.blit(textSurface, [int(x - textSurface.get_width() / 2), int(y)]) if i == swap1 or i == swap2: pygame.draw.rect( screen, BLUE, pygame.rect.Rect(x - 40, y, 20, textSurface.get_height())) # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT: # If user clicked close sys.exit() if __name__ == "__main__": if True: my_list = [5, 1, 2, 9, 8, 6, 4, 3, 5, 0, 7, 3, 1, 4] else: my_list = [] for i in range(0, 100): my_list.append(random.randint(0, 9)) #sorting.bubble_sort(my_list, pygame_display_list, swap_animation) sorting.insertion_sort(my_list, pygame_display_list, swap_animation) #sorting.merge_sort(my_list,0,len(my_list)-1, pygame_display_list) #sorting.quick_sort(my_list, 0, len(my_list) - 1, pygame_display_list, swap_animation) time.sleep(3)
def test_insertionsort(test_input, expected): out = sorting.insertion_sort(test_input.copy()) np.testing.assert_allclose(expected, out)