Exemplo n.º 1
0
 def test_case_8(self):
     self.assertEqual(
         selection_sort.sort([
             -7, 2, 3, 8, -10, 4, -6, -10, -2, -7, 10, 5, 2, 9, -9, -5, 3, 8
         ]),
         [-10, -10, -9, -7, -7, -6, -5, -2, 2, 2, 3, 3, 4, 5, 8, 8, 9, 10],
     )
def run_tests():
    print("\nSelection Sort tests")
    # setup
    numbers = [4, 1, 6, 2, 7, 9, 4, 3]
    sorted_numbers = [1, 2, 3, 4, 4, 6, 7, 9]

    # multiple_iterations
    test.are_equal("one iteration",
                   selection_sort.multiple_iterations(numbers, 1),
                   [1, 4, 6, 2, 7, 9, 4, 3])
    test.are_equal("two iterations",
                   selection_sort.multiple_iterations(numbers, 2),
                   [1, 2, 6, 4, 7, 9, 4, 3])
    test.are_equal("three iterations",
                   selection_sort.multiple_iterations(numbers, 3),
                   [1, 2, 3, 4, 7, 9, 4, 6])
    test.are_equal("four iterations",
                   selection_sort.multiple_iterations(numbers, 4),
                   [1, 2, 3, 4, 7, 9, 4, 6])
    test.are_equal("five iterations",
                   selection_sort.multiple_iterations(numbers, 5),
                   [1, 2, 3, 4, 4, 9, 7, 6])
    test.are_equal("six iterations",
                   selection_sort.multiple_iterations(numbers, 6),
                   sorted_numbers)

    # selection_sort
    test.are_equal("selection sort",
                   selection_sort.sort(numbers),
                   sorted_numbers)
Exemplo n.º 3
0
 def test_case_7(self):
     self.assertEqual(
         selection_sort.sort([
             -4,
             5,
             10,
             8,
             -10,
             -6,
             -4,
             -2,
             -5,
             3,
             5,
             -4,
             -5,
             -1,
             1,
             6,
             -7,
             -6,
             -7,
             8,
         ]),
         [
             -10, -7, -7, -6, -6, -5, -5, -4, -4, -4, -2, -1, 1, 3, 5, 5, 6,
             8, 8, 10
         ],
     )
Exemplo n.º 4
0
def run_tests():
    print("\nSelection Sort tests")
    # setup
    numbers = [4, 1, 6, 2, 7, 9, 4, 3]
    sorted_numbers = [1, 2, 3, 4, 4, 6, 7, 9]

    # multiple_iterations
    test.are_equal("one iteration",
                   selection_sort.multiple_iterations(numbers, 1),
                   [1, 4, 6, 2, 7, 9, 4, 3])
    test.are_equal("two iterations",
                   selection_sort.multiple_iterations(numbers, 2),
                   [1, 2, 6, 4, 7, 9, 4, 3])
    test.are_equal("three iterations",
                   selection_sort.multiple_iterations(numbers, 3),
                   [1, 2, 3, 4, 7, 9, 4, 6])
    test.are_equal("four iterations",
                   selection_sort.multiple_iterations(numbers, 4),
                   [1, 2, 3, 4, 7, 9, 4, 6])
    test.are_equal("five iterations",
                   selection_sort.multiple_iterations(numbers, 5),
                   [1, 2, 3, 4, 4, 9, 7, 6])
    test.are_equal("six iterations",
                   selection_sort.multiple_iterations(numbers, 6),
                   sorted_numbers)

    # selection_sort
    test.are_equal("selection sort", selection_sort.sort(numbers),
                   sorted_numbers)
Exemplo n.º 5
0
 def test_case_9(self):
     self.assertEqual(
         selection_sort.sort([
             8,
             -6,
             7,
             10,
             8,
             -1,
             6,
             2,
             4,
             -5,
             1,
             10,
             8,
             -10,
             -9,
             -10,
             8,
             9,
             -2,
             7,
             -2,
             4,
         ]),
         [
             -10,
             -10,
             -9,
             -6,
             -5,
             -2,
             -2,
             -1,
             1,
             2,
             4,
             4,
             6,
             7,
             7,
             8,
             8,
             8,
             8,
             9,
             10,
             10,
         ],
     )
def test_selection_sort():
    list_of_items = [54, 26, 93, 17, 77, 31, 44, 55, 20]
    print(list_of_items)
    selection_sort.sort(list_of_items)
    print(list_of_items)
Exemplo n.º 7
0
 def test_selectionsort_should_handle_edge_cases(self):
     for k, v in self.i_o:
         self.assertEqual(selection_sort.sort(k), v)
Exemplo n.º 8
0
 def test_selectionsort_should_sort_lists_correctly(self):
     for k, v in self.i_o:
         self.assertEqual(selection_sort.sort(k), v)
Exemplo n.º 9
0
	def test_selectionsort_should_handle_edge_cases(self):
		for k,v in self.i_o:
			self.assertEqual(selection_sort.sort(k), v)
Exemplo n.º 10
0
 def test_selection(self):
     for arr in self.test_arr:
         selection_sort.sort(arr)
         self.assertEqual(arr, sorted(arr))
Exemplo n.º 11
0
def get_time(A, compF):
    t_0 = process_time()
    sort(A, 0, len(A) - 1, compF)
    t_1 = process_time()
    return t_1 - t_0
Exemplo n.º 12
0
import transposition_cipher
""" SORTING """

bubble_sort.sort(array=[3, 2, 11, -1, 0])

array = [0.48, 0.27, 0.12, 0.21, 0.43, 0.25]
bucket_sort.sort(array, max_value=max(array))

insertion_sort.sort(array=[3, 2, 11, -1, 0])

merge_sort.sort(array=[3, 2, 11, -1, 0])

array = [3, 2, 11, -1, 0]
quick_sort.sort(array, left=0, right=len(array) - 1)

selection_sort.sort(array=[3, 2, 11, -1, 0])

lexicographic_order.order(words=['aab', 'aaa', 'aa', 'aaa'])
""" SEARCHING """

pattern_search.search(text=list('karykatura'), pattern=list('ka'))

bisection_root_finding.bisect(a=-4, b=4, error=0.001)

bisection_search.search(array=[-1, 0, 2, 3, 11], target=3)
""" STRING OPS """

anagram.anagram(word1=list('arbuz'), word2=list('burza'))

palindrome.palindrome(word=list('kajak'))
Exemplo n.º 13
0
 def test_case_2(self):
     self.assertEqual(selection_sort.sort([1, 2]), [1, 2])
Exemplo n.º 14
0
 def test_case_5(self):
     self.assertEqual(selection_sort.sort([3, 1, 2]), [1, 2, 3])
Exemplo n.º 15
0
 def test_case_10(self):
     self.assertEqual(
         selection_sort.sort([5, -2, 2, -8, 3, -10, -6, -1, 2, -2, 9, 1,
                              1]),
         [-10, -8, -6, -2, -2, -1, 1, 1, 2, 2, 3, 5, 9],
     )
Exemplo n.º 16
0
 def test_selection(self):
     for array in self.test_array:
         self.assertEqual(selection_sort.sort(array), sorted(array))
Exemplo n.º 17
0
 def test_selection_sort(self):
     self.assertListEqual(selection_sort.sort([4, 3, 2, 1]), [1, 2, 3, 4])
     self.assertListEqual(
         selection_sort.sort(
             [-47, -168, 111, 4, 3, 10, 2, 1, 18, 1000, 8, 0]),
         [-168, -47, 0, 1, 2, 3, 4, 8, 10, 18, 111, 1000])
    def test_numbers_are_sorted_correctly(self):
        numbers_to_sort = [11, 2, 7, 3, 8, 4, 5, 6, 10, 9, 1]
        expected_sorted_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
        actual_sorted_numbers = selection_sort.sort(numbers_to_sort)

        self.assertEquals(expected_sorted_numbers, actual_sorted_numbers)
Exemplo n.º 19
0
	def test_selectionsort_should_sort_lists_correctly(self):
		for k,v in self.i_o:
			self.assertEqual(selection_sort.sort(k), v)
Exemplo n.º 20
0
 def test_sort(self):
     array = [5, 3, 2, 54, 6, 5, 3, 6, 8, 5, 3, 1, 4]
     expected = [1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 8, 54]
     self.assertEqual(expected, sort(array))