def test_between_one_and_two(): t = find(st.floats(), lambda x: 1 < x < 2, settings=Settings( max_shrinks=10**6, generations=10000, )) for k in range(dtoi(1.0), dtoi(t)): assert itod(k) <= t assert not (1 < itod(k))
def test_find_infinity(): assert find(st.floats(), lambda x: not math.isfinite(x)) == float("inf")
def test_minimal_bigger_than_one_is_two(): assert find(st.floats(), lambda x: x > 1) == 2.0
def test_sphere(): t = find(st.lists(st.floats()), lambda x: len(x) >= 3 and sum(map(safesquare, x)) >= 1) assert t == [0.0, 0.0, 1.0]
def test_can_find_zero_and_it_is_positive(): t = find(st.floats(), lambda x: x == 0) assert math.copysign(1, t) > 0
def test_sum_float(): x = find(st.lists(st.floats()), lambda x: sum(x) >= 2**32) assert sum(x) == 2**32
def test_find_reasonable_range_float(): assert find(st.floats(), lambda x: 1 <= x <= 1000) == 1.0
def test_no_overflow_mean(): find( st.lists(st.floats()).filter(lambda x: x and math.isfinite(sum(x))), lambda xs: not (min(xs) <= mean(xs) <= max(xs)))
def test_can_find_negative_zero(): find(st.floats(), lambda x: x == 0 and math.copysign(1, x) < 0)
def test_integral_float(): find(st.floats(), lambda x: math.isfinite(x) and int(x) == x)
def test_sum_float(): x = find(st.lists(st.floats()), lambda x: sum(x) >= 2 ** 32) assert sum(x) == 2 ** 32
def test_imprecise_pow(): find(st.floats(), lambda x: math.isfinite(x) and (x * 3.0) / 3.0 != x)
def test_non_reversible_floats(): good_list = st.lists(st.floats().filter(math.isfinite)) find(good_list, lambda xs: sum(xs) != sum(reversed(xs)))
def test_non_associative_floats(): tup = st.tuples( st.floats(), st.floats(), st.floats()).filter(lambda t: all(math.isfinite(s) for s in t)) find(tup, lambda x: (x[0] + x[1]) + x[2] != x[0] + (x[1] + x[2]))
def test_low_variance(): t = find(st.lists(st.floats()).filter(lambda x: len(x) >= 10), lambda x: variance(x) >= 1) assert t == [0.0] * 9 + [4.0]
def test_find_infinity(): assert find(st.floats(), lambda x: not math.isfinite(x)) == float('inf')
def test_between_one_and_two(): t = find(st.floats(), lambda x: 1 < x < 2, settings=Settings(max_shrinks=10 ** 6, generations=10000)) for k in range(dtoi(1.0), dtoi(t)): assert itod(k) <= t assert not (1 < itod(k))
good_list = st.lists(st.floats().filter(math.isfinite)) find(good_list, lambda xs: sum(xs) != sum(reversed(xs))) def test_non_associative_floats(): tup = st.tuples( st.floats(), st.floats(), st.floats()).filter( lambda t: all(math.isfinite(s) for s in t)) find(tup, lambda x: (x[0] + x[1]) + x[2] != x[0] + (x[1] + x[2])) def mean(ls): return sum(ls) / len(ls) good_list = st.lists(st.floats().filter(math.isfinite)).filter(bool) def test_out_of_bounds_overflow_mean(): find( good_list, lambda xs: not (min(xs) <= mean(xs) <= max(xs))) def test_minimal_bool_lists(): t = find( st.lists(st.booleans()), lambda x: any(x) and not all(x) ) assert t == [False, True] def test_filtering_just_does_not_loop():
def test_low_variance(): t = find( st.lists(st.floats()).filter(lambda x: len(x) >= 10), lambda x: variance(x) >= 1) assert t == [0.0] * 9 + [4.0]
def test_non_associative_floats(): tup = st.tuples( st.floats(), st.floats(), st.floats()).filter( lambda t: all(math.isfinite(s) for s in t)) find(tup, lambda x: (x[0] + x[1]) + x[2] != x[0] + (x[1] + x[2]))
@pytest.mark.float def test_non_associative_floats(): tup = st.tuples( st.floats(), st.floats(), st.floats()).filter(lambda t: all(math.isfinite(s) for s in t)) find(tup, lambda x: (x[0] + x[1]) + x[2] != x[0] + (x[1] + x[2])) def mean(xs): xs = list(xs) if not xs: return float('nan') return sum(xs) / len(xs) good_list = st.lists(st.floats().filter(math.isfinite)).filter(bool) @pytest.mark.float def test_out_of_bounds_overflow_mean(): find(good_list, lambda xs: not (min(xs) <= mean(xs) <= max(xs))) @pytest.mark.float def test_no_overflow_mean(): find( st.lists(st.floats()).filter(lambda x: x and math.isfinite(sum(x))), lambda xs: not (min(xs) <= mean(xs) <= max(xs))) def test_minimal_bool_lists():
def test_no_overflow_mean(): find( st.lists(st.floats()).filter(lambda x: x and math.isfinite(sum(x))), lambda xs: not (min(xs) <= mean(xs) <= max(xs)), )