def test_sort_simple(self): '''Test if Array is being sorted''' array = [2, 5, 1] bubble.sort(array) self.assertTrue( all(array[x] <= array[x + 1] for x in range(len(array) - 1)))
def test_negative_numbers(self): '''Test sorting behaviour with negative Numbers''' array = [-2, 5, 1] bubble.sort(array) self.assertTrue( all(array[x] <= array[x + 1] for x in range(len(array) - 1)))
def test_double_entries(self): '''Test sorting behaviour with double entries''' array = [2, 5, 2] bubble.sort(array) self.assertTrue( all(array[x] <= array[x + 1] for x in range(len(array) - 1)))
def test_kitchensink(self): self.assertEqual( sorter.sort([1,2,5,72,3,6,3,234,5,6,4,2,1,7,9,6,4,322,7,56,23,4,6,4,2,3,6,8,5,3,1,3]), [1,1,1,2,2,2,3,3,3,3,3,4,4,4,4,5,5,5,6,6,6,6,6,7,7,8,9,23,56,72,234,322] ) self.assertEqual( sorter.sort([9,5,4,3,1,6,5,7,5,8,9,9,8,0,8,9,8,7,4,2,1,5,4,6,7,3,1,4,3,5,7,8,9,3]), [0,1,1,1,2,3,3,3,3,4,4,4,4,5,5,5,5,5,6,6,7,7,7,7,8,8,8,8,8,9,9,9,9,9] )
def test_kitchensink(self): self.assertEqual( sorter.sort([ 1, 2, 5, 72, 3, 6, 3, 234, 5, 6, 4, 2, 1, 7, 9, 6, 4, 322, 7, 56, 23, 4, 6, 4, 2, 3, 6, 8, 5, 3, 1, 3 ]), [ 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 8, 9, 23, 56, 72, 234, 322 ]) self.assertEqual( sorter.sort([ 9, 5, 4, 3, 1, 6, 5, 7, 5, 8, 9, 9, 8, 0, 8, 9, 8, 7, 4, 2, 1, 5, 4, 6, 7, 3, 1, 4, 3, 5, 7, 8, 9, 3 ]), [ 0, 1, 1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9 ])
def test_double_entry(): '''Handling of repeating numbers''' array = [2, 5, 2] bubble.sort(array) assert all(array[x] <= array[x + 1] for x in range(len(array) - 1))
def test_negative(): '''Handling of negative numbers''' array = [2, -5, 1] bubble.sort(array) assert all(array[x] <= array[x + 1] for x in range(len(array) - 1))
def test_sorting(): '''Test if Array is being sorted''' array = [2, 5, 1] bubble.sort(array) assert all(array[x] <= array[x + 1] for x in range(len(array) - 1))
def test_bsort(self): assert (bubble.sort([4, 3, 2, 1]) == [1, 2, 3, 4])
def test_two(self): self.assertEqual(sorter.sort([2, 1]), [1, 2]) self.assertEqual(sorter.sort([1, 2]), [1, 2]) self.assertEqual(sorter.sort([7, 8]), [7, 8]) self.assertEqual(sorter.sort([7, 4]), [4, 7])
def test_sorted(self): self.assertEqual(sorter.sort([1]), [1]) self.assertEqual(sorter.sort([1,2]), [1,2]) self.assertEqual(sorter.sort([1,2,3]), [1,2,3]) self.assertEqual(sorter.sort([1,2,3,4]), [1,2,3,4])
def test_two(self): self.assertEqual(sorter.sort([2,1]), [1,2]) self.assertEqual(sorter.sort([1,2]), [1,2]) self.assertEqual(sorter.sort([7,8]), [7,8]) self.assertEqual(sorter.sort([7,4]), [4,7])
def test_bubblesort(self): source = randnum.rand(50) target = copy.deepcopy(source) bubble.sort(source) self.assertEqual(source, sorted(target))
import bubble import selection import insertion array = [1, 3, 20, 18, 7, 50, 2] print('Sorting using BubbleSort Algorithm:') bubble.sort(array) print('Sorting using SelectionSort Algorithm') selection.sort(array) print('Sorting using InsertionSort Algorithm') insertion.sort(array)
def test_single(self): self.assertEqual(sorter.sort([1]), [1]) self.assertEqual(sorter.sort([0]), [0]) self.assertEqual(sorter.sort([-1]), [-1])
def test_empty(self): self.assertEqual(sorter.sort([]), [])
def test_sorted(self): self.assertEqual(sorter.sort([1]), [1]) self.assertEqual(sorter.sort([1, 2]), [1, 2]) self.assertEqual(sorter.sort([1, 2, 3]), [1, 2, 3]) self.assertEqual(sorter.sort([1, 2, 3, 4]), [1, 2, 3, 4])
def test_multiples(self): self.assertEqual(sorter.sort([1, 1]), [1, 1]) self.assertEqual(sorter.sort([5, 5, 5, 5]), [5, 5, 5, 5]) self.assertEqual(sorter.sort([5, 5, 4, 5]), [4, 5, 5, 5])
def test_single_entry(): '''Handling one number''' array = [2] bubble.sort(array) assert all(array[x] <= array[x + 1] for x in range(len(array) - 1))
def test_doubles(): '''Handling of double values''' array = [3.1, 2.9, 2.4] bubble.sort(array) assert all(array[x] <= array[x + 1] for x in range(len(array) - 1))
summary.write("System: " + platform.platform() + "(" + platform.system() + ")" + "\n") summary.write("Arch: " + ("64bit" if sys.maxsize > 2 ** 32 else "32bit") + "\n") summary.write("Computer: " + platform.node() + "\n") summary.write("CPU: " + platform.processor() + "\n") summary.write("Python: " + platform.python_version() + "\n") summary.write("Run At: " + time.strftime("%Y/%m/%d %H:%M:%S") + "\n\n") # BubbleSort summary.write("[BubbleSort]\n") for variable in N: summary.write("> " + str(variable) + " variable: \n") total = 0 for job in range(jobsLimit): data = randnum.rand(variable) start = timeit.default_timer() bubble.sort(data) end = timeit.default_timer() summary.write(str((end-start)*1000) + "\n") total += (end-start)*1000 summary.write("Avg: " + str(total/jobsLimit) + "\n\n") # SelectionSort summary.write("[SelectionSort]\n") for variable in N: summary.write("> " + str(variable) + " variable: \n") total = 0 for job in range(jobsLimit): data = randnum.rand(variable) start = timeit.default_timer()
def test_multiples(self): self.assertEqual(sorter.sort([1,1]), [1,1]) self.assertEqual(sorter.sort([5,5,5,5]), [5,5,5,5]) self.assertEqual(sorter.sort([5,5,4,5]), [4,5,5,5])
tmpTime = 'i' for j in range(5): if j == 0: x = setupRandom(seed, i) elif j == 1: x = setupConst(i) elif j == 2: x = setupDesc(i) elif j == 3: x = setupAsc(i) elif j == 4: x = setupA(i) #print(x) # tablica przed posortowaniem before = round(time.time_ns() / (10**9), 10) if s == 0: x = bubble.sort(x) elif s == 1: x = insertion.sort(x) elif s == 2: x = selection.sort(x) elif s == 3: x = counting.sort(x, i, maxNumber) elif s == 4: x = heap.sort(x) elif s == 5: x = quickRight.sort(x, 0, i - 1) elif s == 6: x = quickRandom.sort(x, 0, i - 1) elif s == 7: x = shell.sort(x) elif s == 8:
def test_single_entry(self): array = [2] bubble.sort(array) self.assertTrue( all(array[x] <= array[x + 1] for x in range(len(array) - 1)))
def test_sort(self): list = generate_list(1000) x = bubble.sort(list) self.assertTrue(x == sorted_list(list))
def test_bsort(self): assert (bubble.sort([4,3,2,1]) == [1,2,3,4])