Skip to content

Commit

Permalink
Merge pull request #22 from masiarek/main
Browse files Browse the repository at this point in the history
Add test directory.
  • Loading branch information
masiarek authored Sep 14, 2022
2 parents 7a9cf7d + 0cc2b75 commit 98fa667
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from setuptools import setup, find_packages

setup(
name='starpy',
version="0.0.001",
extras_require=dict(tests=['pytest']),
packages=find_packages(where='starpy'),
package_dir={"": "starpy"},
)
File renamed without changes.
File renamed without changes.
Empty file added starpy/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import pandas as pd


@pytest.fixture()
def original_example() -> pd:
# load_configuration
# load_all_votes(test_file_1)
Candidates = ['A1', 'A2', 'A3', 'A4', 'B1', 'B2', 'B3', 'B4', 'C1', 'C2', 'C3', 'C4']
Red = 61 * [[5.0, 5.0, 5.0, 5.0, 3.0, 3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0]]
blue = 39 * [[0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0, 5.0, 5.0, 5.0, 5.0]]
tie_breaker = [[2.0, 3.0, 4.0, 5.0, 2.0, 3.0, 4.0, 5.0, 2.0, 3.0, 4.0, 5.0]]
all_parties = Red + blue + tie_breaker

s = pd.DataFrame(all_parties, columns=Candidates)

return s

@pytest.fixture()
def original_results() -> list:
return ['A4']

7 changes: 0 additions & 7 deletions test_STAR_edge_cases.py → tests/test_STAR_edge_cases.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import json
import pandas as pd
import numpy as np
from STAR import STAR, TrueTie
import pytest


class TestSTAR:
pass
# def test_election_with_one_record_only(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"""

import pandas as pd
import numpy as np
from Allocated_Score import Allocated_Score
import sys
sys.path.append('.')
from starpy.Allocated_Score import Allocated_Score

# #Centerist bias 3
# Candidates = ['A','B','C']
Expand Down
21 changes: 6 additions & 15 deletions test_STAR_single_winner.py → tests/test_STAR_single_winner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,15 @@

import json
import pandas as pd
import numpy as np
from STAR import STAR, TrueTie
import pytest
import sys
sys.path.append('.')
from starpy.STAR import STAR, TrueTie


class TestSTAR:
def test_original_example(self):
Candidates = ['A1','A2','A3','A4','B1','B2','B3','B4','C1','C2','C3','C4']
Red = 61 * [[5.0,5.0,5.0,5.0,3.0,3.0,3.0,3.0,0.0,0.0,0.0,0.0]]
blue = 39 * [[0.0,0.0,0.0,0.0,3.0,3.0,3.0,3.0,5.0,5.0,5.0,5.0]]
tie_breaker = [[2.0,3.0,4.0,5.0,2.0,3.0,4.0,5.0,2.0,3.0,4.0,5.0]]
all_parties = Red + blue + tie_breaker

S = pd.DataFrame(all_parties, columns= Candidates)

results = STAR(S)
print(json.dumps(results, indent = 2)) #TODO: write printing function to make this look good
assert results['elected'] == ['A4']
def test_original_example(self, original_example, original_results):
results = STAR(original_example)
assert results['elected'] == original_results

def test_tennessee(self):
# Standard Tennessee example
Expand Down

0 comments on commit 98fa667

Please sign in to comment.