예제 #1
0
def test_selection_sort_float_int_mixed():
    for _ in range(NUMBER_OF_TESTS):
        array_size = randint(0, ARRAY_MAX_LEN)
        array = [(randint(-MAX_INT_ARRAY, MAX_INT_ARRAY) -
                  (0 if random() < .5 else random()))
                 for _ in range(array_size)]

        assert selection_sort(array) == sorted(array)
예제 #2
0
def test_selection_sort_integer():
    for _ in range(NUMBER_OF_TESTS):
        array_size = randint(0, ARRAY_MAX_LEN)
        array = [
            randint(-MAX_INT_ARRAY, MAX_INT_ARRAY) for _ in range(array_size)
        ]

        assert selection_sort(array) == sorted(array)
예제 #3
0
 def test_selection_sort(self):
     print('Selection sort')
     result = selection_sort(self.arr)
     self.assertEquals(result, sorted(self.arr))
예제 #4
0
    def test_selection_sort(self):
        alist = [54, 26, 93, 17, 77, 31, 44, 55, 20]
        sorted_list = [17, 20, 26, 31, 44, 54, 55, 77, 93]

        self.assertEqual(sorting_algorithms.selection_sort(alist), sorted_list)
예제 #5
0
 def test_selection_sort(self):
     actual_sorted = sorting_algorithms.selection_sort(
         TestSortingAlgorithms.unsorted_list)
     self.assertEqual(actual_sorted, TestSortingAlgorithms.sorted_list)
예제 #6
0
import sorting_algorithms

print('This script will sort your array of numbers')

string_of_numbers = input('Print your numbers, devided by commas\n')

list_of_strings = string_of_numbers.split(',')

list_of_numbers = [int(x) for x in list_of_strings]

print(f'Your list of numbers is {list_of_numbers}')

user_choice = input('Instruction: \n'
                    'Choose sorting algorithm: \n'
                    'For bubble sort choose "b"\n'
                    'For insertion sort choose "i"\n'
                    'For quick sort choose "q"\n'
                    'For selection sort choose "s"\n')

if user_choice == 'b':
    sorting_algorithms.bubble_sort(list_of_numbers)
elif user_choice == 'i':
    sorting_algorithms.insertion_sort(list_of_numbers)
elif user_choice == 'q':
    sorting_algorithms.quick_sort(list_of_numbers)
elif user_choice == 's':
    sorting_algorithms.selection_sort(list_of_numbers)
else:
    user_choice = input('Incorrect choice.')

print(f'Your sorted list is {list_of_numbers}')
예제 #7
0
 def test_selection_sort_basic(self):
     input = [5, 3, 1, 4, 2]
     sorted_input = selection_sort(input)
     self.assertEqual([1, 2, 3, 4, 5], sorted_input)
예제 #8
0
 def test_selection_sort_list_already_sorted(self):
     input = [1, 2, 3, 4, 5]
     sorted_input = selection_sort(input)
     self.assertEqual([1, 2, 3, 4, 5], sorted_input)
예제 #9
0
 def test_selection_sort_negative_numbers(self):
     input = [5, 3, -2, -1, 1]
     sorted_input = selection_sort(input)
     self.assertEqual([-2, -1, 1, 3, 5], sorted_input)
예제 #10
0
 def test_selection_sort_duplicate_numbers(self):
     input = [6, 4, 3, 1, 6, 2]
     sorted_input = selection_sort(input)
     self.assertEqual([1, 2, 3, 4, 6, 6], sorted_input)
 def test_2(self):
     self.assertEqual(selection_sort([1, 4, 2, 7, 9, 3]),
                      [1, 2, 3, 4, 7, 9])
 def test_1(self):
     self.assertEqual(selection_sort([32, 3, 5, 1, 23, 2]),
                      [1, 2, 3, 5, 23, 32])
예제 #13
0
import sorting_algorithms

print(sorting_algorithms.selection_sort([54, 26, 93, 17, 77, 31, 44, 55, 20]))
print(sorting_algorithms.bubble_sort([54, 26, 93, 17, 77, 31, 44, 55, 20]))
print(sorting_algorithms.quick_sort([54, 26, 93, 17, 77, 31, 44, 55, 20]))
print(sorting_algorithms.insertion_sort([54, 26, 93, 17, 77, 31, 44, 55, 20]))