Exemplo n.º 1
0
 def test_radix_sort_against_insertion_sort(self):
     """Sort 100 randomly generated lists of numbers with insertion
     sort and with radix sort and assert that their outputs match.
     """
     for i in range(100):
         radix = [randrange(0, 1000000) for x in range(100)]
         insertion = radix[:]
         radix = radix_sort_int(radix)
         insertion_sort(insertion)
         self.assertEqual(radix, insertion)
Exemplo n.º 2
0
 def test_insertion_sort_against_merge_sort(self):
     """Sort 100 randomly generated lists of numbers with insertion
     sort and with merge sort and assert that their outputs match.
     """
     for i in range(100):
         insertion = [randrange(0, 1000000) for x in range(100)]
         merge = insertion[:]
         insertion_sort(insertion)
         merge = merge_sort(merge)
         self.assertEqual(insertion, merge)
Exemplo n.º 3
0
 def test_insertion_sort_against_quicksort(self):
     """Sort 100 randomly generated lists of numbers with quicksort
     sort and with merge sort and assert that their outputs match.
     """
     for i in range(100):
         insertion = [randrange(0, 1000000) for x in range(100)]
         quick = insertion[:]
         insertion_sort(insertion)
         quick = quicksort(quick)
         self.assertEqual(insertion, quick)
Exemplo n.º 4
0
 def test_insertion_sort_against_native(self):
     """Sort 100 randomly generated lists of numbers with insertion
     sort and assert that their output matches that of Python's
     built-in sort.
     """
     for i in range(100):
         li = [randrange(0, 1000000) for x in range(100)]
         expected = sorted(li)
         insertion_sort(li)
         self.assertEqual(expected, li)
 def test_sort(self):
     input_l = [6, 4, 2, 1, 3, 5]
     expected = [1, 2, 3, 4, 5, 6]
     self.assertEquals(insertion_sort(input_l), expected)
 def test_ordered(self):
     input_l = [1, 2, 3, 4, 5, 6]
     self.assertEquals(insertion_sort(input_l), input_l)
 def test_single(self):
     input_l = [1]
     self.assertEquals(insertion_sort(input_l), input_l)
 def test_empty(self):
     input_l = []
     self.assertEquals(insertion_sort(input_l), input_l)