Skip to content
Snippets Groups Projects
Commit 76d247a0 authored by Michael Maier's avatar Michael Maier
Browse files

tests maxzerosumset

parent a224a1e3
No related branches found
No related tags found
No related merge requests found
......@@ -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"
......@@ -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
......
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