def test_containment(): u, v = find( st.tuples(intlist, st.n_byte_unsigned(8)), lambda uv: uv[1] in uv[0] and uv[1] >= 100 ) assert u == [100] assert v == 100
def test_minimize_sets_of_sets(): sos = st.lists(st.lists(st.n_byte_unsigned(8)).map(frozenset)).map(set) def union(ls): return reduce(operator.or_, ls, frozenset()) x = find(sos, lambda ls: len(union(ls)) >= 30) assert x == {frozenset(range(30))}
def tree(data, height=None): if height is None: height = st.integer_range(0, 100)(data) if height == 0: return st.n_byte_unsigned(8)(data) heights = st.integer_range(0, height - 1) l = heights(data) r = heights(data) return (tree.base(data, l), tree.base(data, r))
def test_find_middling_integer(): t = find(st.n_byte_unsigned(8), lambda x: x >= 2**62 and x <= 2**64 - 2**62) assert t == 2**62
def test_find_large_integer(): t = find(st.n_byte_unsigned(8), lambda x: x >= 2**64 - 100) assert t == 2**64 - 100
def test_small_integer(): t = find(st.n_byte_unsigned(8), lambda x: abs(x) <= 100 and abs(x) > 0) assert t == 1
def test_can_sort_lists(): x = find(st.lists(st.n_byte_unsigned(8)), lambda x: len(set(x)) >= 10) assert x == list(range(10))
def test_containment(): u, v = find(st.tuples(intlist, st.n_byte_unsigned(8)), lambda uv: uv[1] in uv[0] and uv[1] >= 100) assert u == [100] assert v == 100
from conjecture import find, Settings, NoSuchExample import conjecture.strategies as st import struct import math import pytest from functools import reduce import operator intlist = st.lists(st.n_byte_unsigned(8)) def draw_following(data): n = data.draw_bytes(1)[0] return data.draw_bytes(n) def test_a_block_of_bytes_simplifies_to_zeros(): d = find(lambda d: d.draw_bytes(100), lambda x: True) assert d == b'\0' * 100 @pytest.mark.parametrize('n', [0, 10, 100, 200, 501]) def test_a_block_of_bytes_simplifies_to_lexicographically_smallest(n): K = 1000 d = find(lambda d: d.draw_bytes(K), lambda x: len([c for c in x if c > 0]) >= n) assert d == b'\0' * (K - n) + b'\1' * n def test_variable_shrink(): assert find(draw_following, any) == bytes([1])
def test_can_sort_lists(): x = find( st.lists(st.n_byte_unsigned(8)), lambda x: len(set(x)) >= 10 ) assert x == list(range(10))
from conjecture import find, Settings, NoSuchExample import conjecture.strategies as st import math import pytest from functools import reduce import operator intlist = st.lists(st.n_byte_unsigned(8)) def draw_following(data): n = data.draw_bytes(1)[0] return data.draw_bytes(n) def test_a_block_of_bytes_simplifies_to_zeros(): d = find(lambda d: d.draw_bytes(100), lambda x: True) assert d == b'\0' * 100 @pytest.mark.parametrize('n', [0, 10, 100, 200, 501]) def test_a_block_of_bytes_simplifies_to_lexicographically_smallest(n): K = 1000 d = find( lambda d: d.draw_bytes(K), lambda x: len([c for c in x if c > 0]) >= n ) assert d == b'\0' * (K - n) + b'\1' * n
def test_find_middling_integer(): t = find(st.n_byte_unsigned(8), lambda x: x >= 2 ** 62 and x <= 2 ** 64 - 2 ** 62) assert t == 2 ** 62
def test_find_large_integer(): t = find(st.n_byte_unsigned(8), lambda x: x >= 2 ** 64 - 100) assert t == 2 ** 64 - 100