Пример #1
0
    start = time.time()
    BubbleSort.bubble_sort(test_list)
    finish = time.time()
    print("********************************")
    print("BubbleSort: ", test_list)
    print("time: %f" % (finish - start))
    print("\n")

    test_list = [
        1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19, 4234, 100, 2, 3, 45, 68, 125, 37,
        54614, 2, 46, 67, 1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19, 4234, 100, 2, 3,
        45, 68, 125, 37, 54614, 2, 46, 67, 1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19,
        4234, 100, 2, 3, 45, 68, 125, 37, 54614, 2, 46, 67
    ]
    start = time.time()
    SelectionSort.selection_sort(test_list)
    finish = time.time()
    print("********************************")
    print("SelectionSort: ", test_list)
    print("time: %f" % (finish - start))
    print("\n")

    test_list = [
        1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19, 4234, 100, 2, 3, 45, 68, 125, 37,
        54614, 2, 46, 67, 1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19, 4234, 100, 2, 3,
        45, 68, 125, 37, 54614, 2, 46, 67, 1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19,
        4234, 100, 2, 3, 45, 68, 125, 37, 54614, 2, 46, 67
    ]
    start = time.time()
    InsertionSort.insertion_sort(test_list)
    finish = time.time()
 def test_random_input_list(self):
     self.assertTrue(SelectionSort.selection_sort([5, 3, 7, 2]) == [2, 3, 5, 7])
 def test_reversed_input_list(self):
     self.assertTrue(SelectionSort.selection_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5])
 def test_edge_case_one_item_input_list(self): #Expected to return input_list as it is
     self.assertTrue(SelectionSort.selection_sort([1]) == [1])
 def test_edge_case_empty_input_list(self): #Exepcted to return input_list as it is
     self.assertTrue(SelectionSort.selection_sort([]) == [])
Пример #6
0
# we have a data set starting with the very basic happy path to complex
data = {
    "data1": range(10000)  #Large sorted array
}

#-----------------------------------------------------------------------------#
#                        BRUTE FORCE SORTING                                  #
#-----------------------------------------------------------------------------#

#                        SELECTION SORTING

for i in range(len(data)):
    # invoke the start time to measure the performance
    start_time = time.time()
    # Calling selection_sort for each data set
    SelectionSort.selection_sort(data["data" + str(i + 1)])
    print("Selection time for data" + str(i + 1) + " = " +
          str(time.time() - start_time))

    #                        BUBBLE SORTING
for i in range(len(data)):
    # invoke the start time to measure the performance
    start_time = time.time()
    # Calling bubble_sort for each data set
    BubbleSort.bubble_sort(data["data" + str(i + 1)])
    print("Bubble time for data" + str(i + 1) + " = " +
          str(time.time() - start_time))

#-----------------------------------------------------------------------------#
#                  DECREASE AND CONQUER                                  #
#-----------------------------------------------------------------------------#