Ejemplo n.º 1
0
 def test_heap_sort(self):
     collection = utils.random_list(10000, 1, 1000)
     result = sorting.heap_sort(collection)
     is_sorted = sorting.isSorted(result)
     self.assertEqual(True, is_sorted)
     collection = utils.reversed_sorted_list(1, 10000)
     result = sorting.heap_sort(collection)
     is_sorted = sorting.isSorted(result)
     self.assertEqual(True, is_sorted)
     collection = utils.sorted_list(1, 1000)
     result = sorting.heap_sort(collection)
     is_sorted = sorting.isSorted(result)
     self.assertEqual(True, is_sorted)
Ejemplo n.º 2
0
    if type(args.items) == str:
        items = [int(i) for i in args.items[1:-1].split(",")]
    else:
        items = args.items

    if args.algorithm == "bubble sort":
        sorted_list = sorting.bubble_sort(items)

    elif args.algorithm == "selection sort":
        sorted_list = sorting.selection_sort(items)

    elif args.algorithm == "insertion sort":
        sorted_list = sorting.insertion_sort(items)

    elif args.algorithm == "shell sort":
        sorted_list = sorting.shell_sort(items, args.sequence)

    elif args.algorithm == "heap sort":
        sorted_list = sorting.heap_sort(items)

    elif args.algorithm == "merge sort":
        sorted_list = sorting.merge_sort(items)

    elif args.algorithm == "quick sort":
        sorted_list = sorting.quick_sort(items)

    else:
        raise ValueError("Please specify the algorithm.")

    print("Sorted list: {}".format(sorted_list))
Ejemplo n.º 3
0
 def test_normalList(self):
     sorting.heap_sort(self.nums)
     self.assertEqual(self.nums, self.expected)
Ejemplo n.º 4
0
 def test_heap_sort(self):
     sorting.heap_sort(self.list_a)
     sorting.heap_sort(self.list_b)
     sorting.heap_sort(self.list_c)
     sorting.heap_sort(self.list_d)
     sorting.heap_sort(self.list_one)
     sorting.heap_sort(self.list_two)
     self.assertEqual(self.list_a, self.list_sorted)
     self.assertEqual(self.list_b, self.list_sorted)
     self.assertEqual(self.list_c, self.list_sorted)
     self.assertEqual(self.list_d, self.list_sorted)
     self.assertEqual(self.list_one, [1])
     self.assertEqual(self.list_two, [-10, -5])
Ejemplo n.º 5
0
 def test_empty_list(self):
     empty_list = []
     sorting.heap_sort(empty_list)
     self.assertEqual(len(empty_list), 0)