Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zerosumset4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anna Postnikova
zerosumset4
Commits
02d520b9
Commit
02d520b9
authored
3 years ago
by
Cezar Ionescu
Browse files
Options
Downloads
Patches
Plain Diff
Added property-based tests, please rename accordingly!
parent
7a83e70c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pytest.ini
+8
-0
8 additions, 0 deletions
pytest.ini
tests/tests_zerosumsets.py
+23
-0
23 additions, 0 deletions
tests/tests_zerosumsets.py
with
31 additions
and
0 deletions
pytest.ini
0 → 100644
+
8
−
0
View file @
02d520b9
# pytest.ini
[pytest]
addopts
=
--doctest-modules --hypothesis-show-statistics
testpaths
=
zerosumset
tests
markers
=
timing_test
This diff is collapsed.
Click to expand it.
tests/tests_zerosumsets.py
+
23
−
0
View file @
02d520b9
...
...
@@ -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
}
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment