def test_randoms():
    x = range(100)
    randoms = x[:]
    shuffle(randoms)
    insertion_sort(randoms)
    y = randoms
    assert x == y
    def test_example(self):
        tmpl = [8, 2, 4, 9, 3, 6]
        a = tmpl[:]
        expected = [2, 3, 4, 6, 8, 9]

        sorting.insertion_sort(a)

        self.assertEqual(expected, a)
    def test_reversed_100_example(self):
        tmpl = list(range(0, 1000))
        a = list(reversed(tmpl[:]))
        expected = tmpl[:]

        sorting.insertion_sort(a)

        self.assertEqual(expected, a)
    def test_1000_example(self):
        tmpl = list(range(0, 1000))
        a = tmpl[:]
        random.shuffle(a)
        expected = tmpl[:]

        sorting.insertion_sort(a)

        self.assertEqual(expected, a)
    def test_static_sorts(self):
        # Note: None of these methods should affect the original lists!
        original = self.unordered

        sorting.selection_sort(self.unordered)
        self.assertEqual(original, self.unordered)

        sorting.insertion_sort(self.unordered)
        self.assertEqual(original, self.unordered)

        sorting.merge_sort(self.unordered)
        self.assertEqual(original, self.unordered)
Exemple #6
0
 def test_insertion_sort(self):
 	collection = utils.random_list(100, 1, 1000)
 	result = sorting.insertion_sort(collection)
 	is_sorted = sorting.isSorted(result)
 	self.assertEqual(True, is_sorted)
 	collection = utils.reversed_sorted_list(1, 100)
 	result = sorting.insertion_sort(collection)
 	is_sorted = sorting.isSorted(result)
 	self.assertEqual(True, is_sorted)
     collection = utils.sorted_list(1, 1000)
     result = sorting.insertion_sort(collection)
     is_sorted = sorting.isSorted(result)
     self.assertEqual(True, is_sorted)
Exemple #7
0
def sort_list(choice, lista):

    #classe Monitor gera objetos relatorio
    time1 = timeit.default_timer()
    if ((choice) == 0):
        relatorio = insertion_sort(lista)
    elif ((choice) == 1):
        relatorio = selection_sort(lista)
    elif ((choice) == 2):
        relatorio = merge_sort(lista)
    elif ((choice) == 3):
        relatorio = quick_sort(lista)
#    else:
#        CompMov = bubble_sort(lista)
    time2 = timeit.default_timer()  #(time2)-(time1)

    relatorio.time = (time2 - time1)
    relatorio.text = "Tempo para ordenar dados: "
    return (relatorio)
    def test_insertion_sort(self):
        test = sorting.insertion_sort(self.unordered)
        self.assertEqual(test, self.ordered)

        test = sorting.insertion_sort(self.unordered_with_dupes)
        self.assertEqual(test, self.ordered_with_dupes)
 def test_insertion_sort(self):
     insertion_sort(self.unsorted_array)
     self.assertEqual(self.unsorted_array, self.sorted_array)
Exemple #10
0
 def test_insertion_sort(self):
     for ls in self._ls:
         assert sorting.insertion_sort(list(ls)) == sorted(ls)
 def test_insertion_sort(self):
     sorting.insertion_sort(self.list_a)
     sorting.insertion_sort(self.list_b)
     sorting.insertion_sort(self.list_c)
     sorting.insertion_sort(self.list_d)
     sorting.insertion_sort(self.list_one)
     sorting.insertion_sort(self.list_two)
     self.assertEqual(self.list_a, self.list_sorted)
     self.assertEqual(self.list_b, self.list_sorted)
     self.assertEqual(self.list_c, self.list_sorted)
     self.assertEqual(self.list_d, self.list_sorted)
     self.assertEqual(self.list_one, [1])
     self.assertEqual(self.list_two, [-10, -5])
def test_string():
    with pytest.raises(TypeError):
        insertion_sort('cat')
 def test_insertion_sort(self):
     for arr in random_arrays:
         self.assertEquals(insertion_sort(arr[0]), arr[1])
Exemple #14
0
import sorting as fsort

input_list = [4, 9, 10, 5, 1, 2, 8, 3, 7, 6]

print("순차정렬 :", fsort.sequential_sort(input_list, reverse=False))
print("삽입정렬 :", fsort.insertion_sort(input_list, reverse=False))
print(
    "퀵정렬 :",
    fsort.quick_sort(input_list.copy(),
                     reverse=False,
                     front=0,
                     rear=len(input_list) - 1))
print("계수정렬 :", fsort.counting_sort(input_list.copy(), reverse=False))
print("병합정렬 :", fsort.merge_sort(input_list.copy()))
print("힙정렬 :\t")
Exemple #15
0
def test_insertion_sort():
	data = populate_random_data()
	sorting.insertion_sort(data)

	assert sorted(data) == data
 def test_insertion_sort(self):
     """Tests that test list is correctly sorted."""
     self.assertEqual(sorted(self.test_list), insertion_sort(self.test_list))