diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..159c41d --- /dev/null +++ b/setup.py @@ -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"}, +) diff --git a/Allocated_Score.py b/starpy/Allocated_Score.py similarity index 100% rename from Allocated_Score.py rename to starpy/Allocated_Score.py diff --git a/STAR.py b/starpy/STAR.py similarity index 100% rename from STAR.py rename to starpy/STAR.py diff --git a/starpy/__init__.py b/starpy/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..99a4a50 --- /dev/null +++ b/tests/conftest.py @@ -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'] + diff --git a/test_STAR_edge_cases.py b/tests/test_STAR_edge_cases.py similarity index 95% rename from test_STAR_edge_cases.py rename to tests/test_STAR_edge_cases.py index 28877bf..a2133ec 100644 --- a/test_STAR_edge_cases.py +++ b/tests/test_STAR_edge_cases.py @@ -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): diff --git a/test_STAR_multi_winner_allocated_score.py b/tests/test_STAR_multi_winner_allocated_score.py similarity index 98% rename from test_STAR_multi_winner_allocated_score.py rename to tests/test_STAR_multi_winner_allocated_score.py index 93fa8eb..284d15c 100644 --- a/test_STAR_multi_winner_allocated_score.py +++ b/tests/test_STAR_multi_winner_allocated_score.py @@ -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'] diff --git a/test_STAR_single_winner.py b/tests/test_STAR_single_winner.py similarity index 92% rename from test_STAR_single_winner.py rename to tests/test_STAR_single_winner.py index 87767ea..e12c8a2 100644 --- a/test_STAR_single_winner.py +++ b/tests/test_STAR_single_winner.py @@ -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