def test_can_sort_bytes_by_reordering_partially_not_cross_stationary_element(): start = hbytes([5, 3, 0, 2, 1, 4]) finish = Lexical.shrink( start, lambda x: set(x) == set(start) and x[3] == 2, random=Random(0), ) assert finish <= hbytes([0, 3, 5, 2, 1, 4])
def test_can_sort_bytes_by_reordering_partially(): start = hbytes([5, 4, 3, 2, 1, 0]) finish = Lexical.shrink( start, lambda x: set(x) == set(start) and x[0] > x[-1], random=Random(0), ) assert finish == hbytes([1, 2, 3, 4, 5, 0])
def test_can_sort_bytes_by_reordering_partially2(): start = hbytes([5, 4, 3, 2, 1, 0]) finish = Lexical.shrink( start, lambda x: Counter(x) == Counter(start) and x[0] > x[2], random=Random(0), full=True, ) assert finish <= hbytes([1, 2, 0, 3, 4, 5])
def test_can_sort_bytes_by_reordering_partially2(): start = hbytes([5, 4, 3, 2, 1, 0]) finish = Lexical.shrink( start, lambda x: Counter(x) == Counter(start) and x[0] > x[2], random=Random(0), ) assert finish <= hbytes([1, 2, 0, 3, 4, 5])
def minimal_from(start, condition): buf = int_to_bytes(flt.float_to_lex(start), 8) def parse_buf(b): return flt.lex_to_float(int_from_bytes(b)) shrunk = Lexical.shrink( buf, lambda b: condition(parse_buf(b)), full=True, random=Random(0) ) return parse_buf(shrunk)
def minimal_from(start, condition): buf = int_to_bytes(flt.float_to_lex(start), 8) def parse_buf(b): return flt.lex_to_float(int_from_bytes(b)) shrunk = Lexical.shrink(buf, lambda b: condition(parse_buf(b)), full=True, random=Random(0)) return parse_buf(shrunk)
def test_converts_floats_to_integer_form(f): assert flt.is_simple(f) buf = int_to_bytes(flt.base_float_to_lex(f), 8) def parse_buf(b): return flt.lex_to_float(int_from_bytes(b)) shrunk = Lexical.shrink(buf, lambda b: parse_buf(b) == f, full=True, random=Random(0)) assert shrunk < buf
def test_converts_floats_to_integer_form(f): assert flt.is_simple(f) buf = int_to_bytes(flt.base_float_to_lex(f), 8) def parse_buf(b): return flt.lex_to_float(int_from_bytes(b)) shrunk = Lexical.shrink( buf, lambda b: parse_buf(b) == f, full=True, random=Random(0) ) assert shrunk < buf
def test_shrink_to_smallest(): assert Lexical.shrink( hbytes([255] * 8), lambda x: sum(x) > 10, random=Random(0) ) == hbytes([0] * 7 + [11])
def test_can_sort_bytes_by_reordering(): start = hbytes([5, 4, 3, 2, 1, 0]) finish = Lexical.shrink(start, lambda x: set(x) == set(start), random=Random(0)) assert finish == hbytes([0, 1, 2, 3, 4, 5])
def test_float_hack_fails(): assert Lexical.shrink( hbytes([255] * 8), lambda x: x[0] >> 7, random=Random(0), ) == hbytes([128] + [0] * 7)
def test_shrink_to_smallest(): assert Lexical.shrink( hbytes([255] * 8), lambda x: sum(x) > 10, random=Random(0), ) == hbytes([0] * 7 + [11])
def test_shrink_to_zero(): assert Lexical.shrink(hbytes([255] * 8), lambda x: True, random=Random(0)) == hbytes(8)
def test_float_hack_fails(): assert Lexical.shrink( hbytes([255] * 8), lambda x: x[0] >> 7, random=Random(0) ) == hbytes([128] + [0] * 7)
def test_shrink_to_zero(): assert Lexical.shrink( hbytes([255] * 8), lambda x: True, random=Random(0) ) == hbytes(8)