Exemple #1
0
    def testsort(self):
        bsort = sorting.BubbleSort()
        qsort = sorting.QuickSort()
        isort = sorting.InsertionSort()
        ssort = sorting.SelectionSort()
        bsort.array = qsort.array = isort.array = ssort.array = [5, 9, 3, 7, 2, 7, 2, 1, 5]
        bsort.sorting()
        isort.sorting()
        ssort.sorting()
        self.assertEqual(bsort.array, [1, 2, 2, 3, 5, 5, 7, 7, 9])
        self.assertEqual(qsort.array, [1, 2, 2, 3, 5, 5, 7, 7, 9])
        self.assertEqual(isort.array, [1, 2, 2, 3, 5, 5, 7, 7, 9])
        self.assertEqual(ssort.array, [1, 2, 2, 3, 5, 5, 7, 7, 9])

        array = []
        while len(array) <= random.randint(10000, 100000):
            array.append(random.randint(0, 100000))
        print("Len:", len(array))
        bsort = sorting.BubbleSort()
        qsort = sorting.QuickSort()
        isort = sorting.InsertionSort()
        ssort = sorting.SelectionSort()
        bsort.array = qsort.array = isort.array = ssort.array = array
        bsort.sorting()
        isort.sorting()
        ssort.sorting()
        self.assertEqual(bsort.array, sorted(array))
        self.assertEqual(qsort.array, sorted(array))
        self.assertEqual(isort.array, sorted(array))
        self.assertEqual(ssort.array, sorted(array))
 def test_sequence_of_numbers(self):
     N = 20
     test_list = []
     for i in range(N):
         test_list.append(random.randint(-100, 100))
     expected_list = sorted(test_list.copy(), key=int)
     sorting.SelectionSort()(test_list)
     self.assertEquals(test_list, expected_list)
 def test_many_literals(self):
     N = 20
     test_list = []
     characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
     for i in range(N):
         test_list.append(random.choice(characters))
     expected_list = sorted(test_list)
     sorting.SelectionSort()(test_list)
     self.assertEquals(test_list, expected_list)
    def test_selectiontsort(self):
        s = sorting.SelectionSort(sample)
        s.sort()

        self.assertTrue(s.is_sorted())
        self.assertEqual(expected, s.vals)
Exemple #5
0
import sorting as sort

#bubblesort
mahasiswa = ['andi', 'budi', 'ana', 'rina', 'uswa']
mahasiswa.sort()
print(f'{mahasiswa}')

#sort.SelectionSort()
angka = [23, 7, 32, 99, 4, 15, 11, 20]
SelectionSort = sort.SelectionSort(angka)
print(angka)

#insert
list = [12, 23, 34, 52, 8, 44, 43, 45, 78]
print('Data sort :', list)
qs = sort.qs(list, 0, len(list) - 1)

#Mergesrt
print('Menggabungkan List', list)
list = [2, 5, 60, 43, 27, 10, 89, 17]
ms = sort.ms(list)

#quick
list = [67, 91, 87, 33, 49, 10, 16, 43, 65, 3]
print('Data yg akan di sort :', list)
print('Quick Sort :')
qs = sort.qs(list, 0, len(list) - 1)
 def test_single_literals(self):
     test_list = ['a']
     sorting.SelectionSort()(test_list)
     self.assertEquals(test_list, ['a'])
 def test_single_element(self):
     test_list = [1]
     sorting.SelectionSort()(test_list)
     self.assertEquals(test_list, [1])
 def test_empty_list(self):
     test_list = []
     self.assertEquals(sorting.SelectionSort()(test_list), None)