def build_list(size, condition, range=(0, 2e20)): """ Builds a list of `size` size and `condition` arrangement. @param size: a integer. @param condition: a `TEST_CODITIONS` item. @param range: a tuple with start and end range of the numbers generated. @return: a `SortingList` object. """ logging.debug('building a list with %d elements and %s' % (size, condition.lower())) list = [ random.randint(range[0], range[1]) for _ in __builtins__.range(size) ] if condition == 'CRESCENT' or condition == 'DECRESCENT': list.sort() elif condition == 'DECRESCENT': list = list[::-1] elif condition == 'RANDOM': random.shuffle(list) return SortingList(list)
def test_hybrid(self): list = SortingList(build_list(30)) list.hybrid_sort() self.assertTrue(is_sorted(list))
def test_quick(self): list = SortingList(build_list(30)) list.quick_sort() self.assertTrue(is_sorted(list))
def test_selection(self): list = SortingList(build_list(30)) list.selection_sort() self.assertTrue(is_sorted(list))
def test_bubble(self): list = SortingList(build_list(30)) list.bubble_sort() self.assertTrue(is_sorted(list))
def test_merge(self): list = SortingList(build_list(30)) list = list.merge_sort() self.assertTrue(is_sorted(list))