Skip to content
Snippets Groups Projects
Commit 02d520b9 authored by Cezar Ionescu's avatar Cezar Ionescu
Browse files

Added property-based tests, please rename accordingly!

parent 7a83e70c
No related branches found
No related tags found
No related merge requests found
# pytest.ini
[pytest]
addopts = --doctest-modules --hypothesis-show-statistics
testpaths =
zerosumset
tests
markers =
timing_test
......@@ -13,3 +13,26 @@ def test_zerosumset(elems):
assert output == elems, f"Failed: expected {elems}"
from hypothesis import given, strategies as st, event, assume
from random import randint
@st.composite
def gen_solvable(draw, min_size=5, max_size=10):
xs = draw(st.lists(st.integers(), min_size=5, max_size=10))
n = draw(st.integers(min_value=1))
l = len(xs)
pos1 = randint(0, l-1)
xs.insert(pos1, n)
pos2 = randint(0, l)
xs.insert(pos2, -n)
return xs
@given(gen_solvable())
# @given(st.lists(st.integers(), min_size=5, max_size=10).filter(lambda xs: not all(x > 0 for x in xs)))
def test_sum_is_zero(xs):
# assume(not all(x > 0 for x in xs))
subxs = zerosumset(xs)
if not subxs: event("null result")
assert sum(subxs) == 0, f"Result doesn't have zero sum: {subxs}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment