def test_shrink_single_element_list(): repeated = False l = [0] for x in qc_shrink(l): if x == l: repeated = True assert repeated == False, "Shrink must not repeat things already seen"
def test_shrink_floats(full_f): for f in qc_shrink(full_f): if abs(full_f) > 1: assert abs(f) <= abs(full_f)/2 + 1 else: assert abs(f) >= abs(full_f)/2 + 1 assert cmp(f,0) == cmp(full_f, 0) # shrink shall not change sign assert isinstance(f, float)
def test_shrink_floats(full_f): for f in qc_shrink(full_f): assert isinstance(f, float), "floats must be shrunk to floats" assert abs(full_f) > 1 # TODO, check if something is appropriate for smaller number assert abs(f) <= abs(full_f)/2 + 1, "shrunk fload must be smaller than parent" assert cmp(f,0) == cmp(full_f, 0), "shrink must not change sign of floats"
def test_shrink_integers(full_i): for i in qc_shrink(full_i): assert isinstance(i, int), "ints must be shrunk to ints" assert abs(i) <= abs(full_i)/2 + 1, "ints must be shrunk to smaller ints" assert cmp(i,0) == cmp(full_i, 0), "shrink must not change sign of ints"
def test_shrink_lists(full_l): for sub_l in qc_shrink(full_l): assert len(sub_l) <= len(full_l)/2 + 1, "list must be shrunk in half"
def test_shrink_empty_list(): qc_shrink([]).next() # there must be no next, an Exception must be raised
def shrink_bookcase(bookcase): if isinstance(bookcase, Bookcase): for shrinked_books in qc_shrink(bookcase.books): yield Bookcase(bookcase.num_shelves, shrinked_books)
def test_shrink_empty_list(): empty_list_has_been_shrunk = False for x in qc_shrink([]): empty_list_has_been_shrunk = True assert empty_list_has_been_shrunk == False, "Empty lists must not be shrunk"
def test_shrink_integers(full_i): for i in qc_shrink(full_i): assert abs(i) <= abs(full_i)/2 + 1 assert cmp(i,0) == cmp(full_i, 0) # shrink shall not change sign assert isinstance(i, int)
def test_shrink_lists(full_l): for sub_l in qc_shrink(full_l): assert len(sub_l) <= len(full_l)/2 + 1