Exemplo n.º 1
0
def main():
    '''Main program'''
    # get the WordData list
    data = get_data()

    # Sort the list of WordData objects by highest percent using your Bubble Sort
    # function. Sort the list in place (don't create a new list). Print the first 50
    # WordData objects in the list.
    print()
    print('BY PERCENT:')
    bubble_sort(data, 2, descending=True)
    for wd in data[:50]:
        print(wd)

    # Sort the list of WordData objects by highest count using your Insertion Sort
    # function. Sort the list in place (don't create a new list). Print the first 50
    # WordData objects in the list.
    print()
    print('BY COUNT:')
    insertion_sort(data, 1, descending=True)
    for wd in data[:50]:
        print(wd)

    # Sort the list of WordData objects by alpha order (a-z) using your Selection Sort
    # function. Sort the list in place (don't create a new list). Print the first 50
    # WordData objects in the list.
    print()
    print('BY WORD:')
    selection_sort(data, 0)
    for wd in data[:50]:
        print(wd)
Exemplo n.º 2
0
 def test_insertion_sort_descending(self):
     from sorters import insertion_sort
     idx = 1
     insertion_sort(self.data, idx,True)
     for a, b in self.iterPairs():
         self.assertGreaterEqual(a[idx], b[idx],
             msg='previous {} should be less than current {} at index {}'.format(a, b, idx))
Exemplo n.º 3
0
 def test_insertion_sort_descending(self):
     from sorters import insertion_sort
     idx = 1
     insertion_sort(self.data, idx)
     for b, a in self.iterPairs():
         self.assertLessEqual(
             b[idx],
             a[idx],
             msg='previous {} should be less than current {} at index {}'.
             format(b, a, idx))
Exemplo n.º 4
0
    def test_insertion_selection(self):
        from sorters import insertion_sort, selection_sort
        idxes = [0, 1, 2]

        for idx in idxes:
            data_copy1, data_copy2 = self.data[:], self.data[:]

            insertion_sort(data_copy1, idx)
            selection_sort(data_copy2, idx)

            for i in range(len(data_copy1)):
                self.assertEqual(data_copy1[i][idx], data_copy2[i][idx])
Exemplo n.º 5
0
    def test_insertion_sort_ascending(self):
        from sorters import insertion_sort
        idxes = [0, 1, 2]

        for idx in idxes:
            insertion_sort(self.data, idx)

            for a, b in self.iterPairs():
                self.assertLessEqual(
                    a[idx],
                    b[idx],
                    msg='previous {} should be less than current {} at index {}'
                    .format(a, b, idx))