コード例 #1
0
 def test_empty_array(self):
     sorted_arr = heapsort.sort(numpy.empty(0))
     try:
         numpy.testing.assert_array_equal(sorted_arr, [])
         self.assertTrue(True)
     except AssertionError as error:
         self.assertTrue(False, error)
コード例 #2
0
 def test_one_element_array(self):
     sorted_arr = heapsort.sort(numpy.array([2]))
     try:
         numpy.testing.assert_array_equal(sorted_arr, numpy.array([2]))
         self.assertTrue(True)
     except AssertionError as error:
         self.assertTrue(False, error)
コード例 #3
0
 def test_small_array(self):
     sorted_arr = heapsort.sort(numpy.array([4, 8, 3, 9, 0, 8]))
     try:
         numpy.testing.assert_array_equal(sorted_arr,
                                          numpy.array([0, 3, 4, 8, 8, 9]))
         self.assertTrue(True)
     except AssertionError as error:
         self.assertTrue(False, error)
コード例 #4
0
def sort(method, isSorted, i):

    # Tuple that is returned from the getDB() method
    # ITEM_DATABASE is a dictionary where the keys are integers and the values are an array
    # upc14_collection is an array of integers
    ITEM_DATABASE, upc14_collection = getDB(isSorted)

    while i < len(upc14_collection):
        if i == 0:
            break
        else:
            del upc14_collection[i]
    # Tracks the amount of time it takes for the algorithm to run
    start_time = time.clock()

    # Checks to see which method the user wants to use
    if method == 'QUICKSORT':
        quicksort.sort(upc14_collection)
    elif method == 'RADIXSORT':
        radixsort.sort(upc14_collection)
    elif method == 'HEAPSORT':
        heapsort.sort(upc14_collection)

    # Ends the time when the algorithm is finished
    end_time = time.clock()
    # Prints the algorithm used and how long it took to compute
    clock = end_time - start_time
    print('{} DONE: {} seconds'.format(method, clock))

    #Opens the output sorted file and writes to the file to enter the newly sorted data
    with open('Sorted Database.csv', 'w') as file:

        #For each upc code, a new line in the file will be written
        for i in range(0, len(upc14_collection)):
            #Written in the format: UPC14 CODE, BRAND, PRODUCT NAME
            file.write('{}, {}, {} \n'.format(
                ITEM_DATABASE.get(upc14_collection[i])[0],
                ITEM_DATABASE.get(upc14_collection[i])[1],
                ITEM_DATABASE.get(upc14_collection[i])[2]))

        file.close()
        # OS opens the sorted text file
        os.system('open Sorted\ Database.csv')
コード例 #5
0
 def testSingleElem(self):
     A = [1]
     heapsort.sort(A)
     self.assertEqual(A, [1])
コード例 #6
0
 def testGeneralCase(self):
     A = [3,2,6,5,1,8,7,9,4,10]
     heapsort.sort(A)
     self.assertEqual(A, [1,2,3,4,5,6,7,8,9,10])
コード例 #7
0
def random_list(list):
    size = len(list)
    for i in range(1, size):
        r1 = rn(size)
        r2 = rn(size)
        heapsort.swap(list, r1, r2)


list = [1, 2, 8, 4, 7, 0, 9, 6, 3, 5]
qsortlist = list.copy()
simpleselectsortlist = list.copy()
bubblesortlist = list.copy()
mergesortlist = list.copy()

heapsort.sort(list)
print(list)

list = qsortlist
qsort.sort(list)
print(list)

list = simpleselectsortlist
simpleselectsort.sort(list)
print(list)

bubblesort.sort(bubblesortlist)
print(bubblesortlist)

mergesort.sort(mergesortlist)
print(mergesortlist)
コード例 #8
0
 def testSingleElem(self):
     A = [1]
     heapsort.sort(A)
     self.assertEqual(A, [1])
コード例 #9
0
 def testGeneralCase(self):
     A = [3, 2, 6, 5, 1, 8, 7, 9, 4, 10]
     heapsort.sort(A)
     self.assertEqual(A, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
コード例 #10
0
ファイル: test.py プロジェクト: samuelcstewart/ads
 def test_heapsort(self):
     heapsort.sort(self.test)
     self.assertItemsEqual(self.test, self.expected)