diff --git a/examples/israel_examples.py b/examples/israel_examples.py new file mode 100644 index 0000000..a3c10fd --- /dev/null +++ b/examples/israel_examples.py @@ -0,0 +1,20 @@ +from __future__ import print_function +import sys +sys.path.insert(0, '..') +import apportionment + +with open("./knesset.txt", "r") as f: + + for line in f: + knesset_nr, partynames, votes, officialresult, threshold = \ + eval(line) + print("Knesset #" + str(knesset_nr) + ":") + result = apportionment.method("dhondt", votes, + sum(officialresult), + parties=partynames, + threshold=None, # is already excluded from input + verbose=True) + # actual results + print("Identical with official result: " + + (str(tuple(result) == tuple(officialresult))) + + "\n\n") diff --git a/examples/knesset.txt b/examples/knesset.txt new file mode 100644 index 0000000..67b5360 --- /dev/null +++ b/examples/knesset.txt @@ -0,0 +1,4 @@ +[19, ['Likud Yisrael Beitenu+Habayit Hayehudi', 'Yesh Atid+Israel Labor Party', 'Shas+United Torah Judaism', 'Hatenua+Meretz', 'United Arab List', 'Hadash+National Democratic Assembly - Balad', 'Kadima'], [885163+345985, 543458+432118, 331868+195892, 189167+172403, 138450, 113439+97030, 78974], [31+12, 19+15, 11+7, 6+6, 4, 4+3, 2], 0.02] +[20, ['Likud Chaired by Benjamin Netanyahu for Prime Minister+Habayit Hayehudi Chaired by Naftali Bennett', "Zionist Camp Chaired by Isaac Herzog and Tzipi Livni+Israel's Left", 'Joint List (Hadash, National Democratic Assembly, Arab Movement for Renewal, United Arab List)', 'Yesh Atid Chaired by Yair Lapid', 'Kulanu Chaired by Moshe Kahlon+Yisrael Beitenu Chaired by Avigdor Liberman', 'Shas+United Torah Judaism'], [985408+283910, 786313+165529, 446583, 371602, 315360+214906, 241613+210143], [30+8, 24+5, 13, 11, 10+6, 7+6], 0.0325] +[21, ['Likud Chaired by Benjamin Netanyahu for Prime Minister+United Right', 'Blue and White', 'Shas+United Torah Judaism', "Hadash-Ta'al+Ra'am-Balad", 'Israeli Labor Party+Meretz', 'Yisrael Beitenu', 'Kulanu Chaired by Moshe Kahlon'], [1140370+159468, 1125881, 258275+249049, 193442+143666, 190870+156473, 173004, 152756], [35+5, 35, 8+8, 6+4, 6+4, 5, 4], 0.0325] +[22, ['Blue and White+Yisrael Beitenu', 'Likud+Yemina', 'Joint List (Hadash, Ra\xe2\x80\x99am, Ta\xe2\x80\x99al, Balad)', 'Shas+United Torah Judaism', 'Labor-Gesher+Democratic Union'], [1151214+310154, 1113617+260655, 470211, 330199+268775, 212782+192495], [33+8, 32+7, 13, 9+7, 6+5], 0.0325] \ No newline at end of file diff --git a/unittests.py b/unittests.py index bfc81b6..c69ad79 100644 --- a/unittests.py +++ b/unittests.py @@ -144,5 +144,7 @@ class TestApprovalMultiwinner(unittest.TestCase): self.assertNotEqual(r1, r2, "Saintelague should produce different "+ "result than modified variant.") + + if __name__ == '__main__': unittest.main()