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
76d247a0
Commit
76d247a0
authored
3 years ago
by
Michael Maier
Browse files
Options
Downloads
Patches
Plain Diff
tests maxzerosumset
parent
a224a1e3
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
tests/tests_zerosumsets.py
+35
-4
35 additions, 4 deletions
tests/tests_zerosumsets.py
zerosumset/__init__.py
+1
-1
1 addition, 1 deletion
zerosumset/__init__.py
with
36 additions
and
5 deletions
tests/tests_zerosumsets.py
+
35
−
4
View file @
76d247a0
...
...
@@ -4,16 +4,47 @@ import pytest
from
zerosumset
import
zerosumset
from
zerosumset
import
maxzerosumset
from
itertools
import
groupby
#<<<<<<< HEAD
test_cases
=
[
-
7
,
-
3
,
-
2
,
9000
,
5
,
8
]
#=======
test_cases_identical
=
[[],
[
1
,
2
,
-
3
],
[
0
]]
#>>>>>>> ad8c4fea4f155d605826abb67c63582e973f4605
@pytest.mark.parametrize
(
"
elems
"
,
test_cases_identical
)
@pytest.mark.parametrize
(
"
elems
"
,
test_cases
)
def
test_zerosumset
(
elems
):
output
=
zerosumset
(
elems
)
assert
output
==
elems
,
f
"
Failed: expected
{
elems
}
"
@pytest.mark.parametrize
(
"
elems
"
,
test_cases
)
def
test_maxzerosumset_len
(
elems
):
output
=
maxzerosumset
(
elems
)
normal_output
=
zerosumset
(
elems
)
assert
output
>=
normal_output
,
f
"
Something is wrong
"
@pytest.mark.parametrize
(
"
elems
"
,
test_cases
)
def
test_maxzerosumset_zeros
(
elems
):
a
=
0
;
output
=
maxzerosumset
(
elems
)
for
i
in
range
(
elems
):
if
elems
[
i
]
==
0
:
a
=
a
+
1
for
i
in
range
(
output
):
if
output
[
i
]
==
0
:
a
=
a
-
1
assert
a
==
0
,
f
"
Something is wrong
"
@pytest.mark.parametrize
(
"
elems
"
,
test_cases
)
def
test_maxzerosumset_same_number
(
elems
):
a
=
0
;
output
=
maxzerosumset
(
elems
)
sort_elems
=
sorted
(
elems
)
new
=
[
len
(
list
(
group
))
for
key
,
group
in
groupby
(
sort_elems
)]
for
i
in
range
(
new
):
if
new
[
i
]
>
1
:
a
=
a
+
i
-
i
%
2
assert
a
<=
len
(
output
),
f
"
Something is wrong
"
This diff is collapsed.
Click to expand it.
zerosumset/__init__.py
+
1
−
1
View file @
76d247a0
...
...
@@ -16,7 +16,7 @@ def zerosumset(elems):
[
3
,
1
,
-
4
]
'''
# elems = [-7, -3, -2, 9000, 5, 8]
n
=
len
(
elems
)
# Symbolic variables: is_in[i] is 1, if element i is in the zero sum subset, 0 otherwise
...
...
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