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
67c837dc
Commit
67c837dc
authored
3 years ago
by
Michael Maier
Browse files
Options
Downloads
Plain Diff
tests maxzerosumset 2
parents
76d247a0
cd556682
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
pytest.ini
+8
-0
8 additions, 0 deletions
pytest.ini
tests/tests_zerosumset.py
+85
-0
85 additions, 0 deletions
tests/tests_zerosumset.py
with
94 additions
and
1 deletion
README.md
+
1
−
1
View file @
67c837dc
...
...
@@ -11,7 +11,7 @@ Example
>>>
zerosumset
.
zerosumset
(
elems
)
[
-
3
,
-
2
,
5
]
>>>
zerosumset
.
zerosumset
(
3
,
1
,
10
,
-
4
)
>>>
zerosumset
.
zerosumset
(
[
3
,
1
,
10
,
-
4
]
)
[
3
,
1
,
-
4
]
```
...
...
This diff is collapsed.
Click to expand it.
pytest.ini
0 → 100644
+
8
−
0
View file @
67c837dc
# 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_zerosumset.py
0 → 100644
+
85
−
0
View file @
67c837dc
import
sys
sys
.
path
.
append
(
'
../zerosumset
'
)
import
pytest
from
zerosumset
import
*
test_cases_identical
=
[[],
[
1
,
2
,
-
3
],
[
0
]]
@pytest.mark.parametrize
(
"
elems
"
,
test_cases_identical
)
def
test_zerosumset
(
elems
):
output
=
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
}
"
@given
(
gen_solvable
())
def
test_zero_included
(
xs
):
subxs1
=
maxzerosumset
(
xs
)
pos
=
randint
(
0
,
len
(
xs
)
-
1
)
xs
.
insert
(
pos
,
0
)
subxs2
=
maxzerosumset
(
xs
)
assert
len
(
subxs2
)
>=
len
(
subxs1
)
@given
(
gen_solvable
())
def
test_has_same_amount_of_zeros
(
xs
):
subxs
=
maxzerosumset
(
xs
)
assert
len
(
list
(
filter
(
lambda
x
:
x
==
0
,
xs
)))
==
len
(
list
(
filter
(
lambda
x
:
x
==
0
,
subxs
))),
f
"
Result doesn
'
t have the same amount of zeros as in the given list
"
@st.composite
def
gen_solvable_pair
(
draw
,
min_size
=
5
,
max_size
=
10
):
# doesn't work
# xs = gen_solvable()
# xs2 = xs.copy()
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
)
xs2
=
xs
.
copy
()
n
=
draw
(
st
.
integers
(
min_value
=
1
))
l
=
len
(
xs
)
pos1
=
randint
(
0
,
l
-
1
)
xs2
.
insert
(
pos1
,
n
)
pos2
=
randint
(
0
,
l
)
xs2
.
insert
(
pos2
,
-
n
)
pair
=
[
xs
,
xs2
]
return
pair
# sometimes is not passed somehow
@given
(
gen_solvable_pair
())
def
test_insert_new_numbers
(
pair
):
subxs1
=
maxzerosumset
(
pair
[
0
])
subxs2
=
maxzerosumset
(
pair
[
1
])
assert
len
(
subxs2
)
>=
len
(
subxs1
)
+
2
,
f
"
The second list is not longer
"
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