check all methods implemented

pull/2/head
Martin Lackner 2019-09-09 13:30:40 +02:00
rodzic 3761d4c7c4
commit 52794e0f68
1 zmienionych plików z 40 dodań i 0 usunięć

Wyświetl plik

@ -13,6 +13,22 @@ METHODS = ["quota", "largest_remainder", "dhondt",
class TestApprovalMultiwinner(unittest.TestCase):
def test_all_implemented(self):
ALLMETHODSSTRINGS = ["quota", "lrm", "hamilton", "largest_remainder",
"dhondt", "jefferson", "saintelague", "webster",
"huntington", "hill", "adams", "dean",
"smallestdivisor", "harmonicmean",
"equalproportions", "majorfractions",
"greatestdivisors"]
votes = [1]
seats = 1
for method in ALLMETHODSSTRINGS:
result = apportionment.method(method, votes,
seats, verbose=False)
self.assertEqual(result, [1],
msg=method + " does not exist")
def test_weak_proportionality(self):
self.longMessage = True
@ -46,6 +62,30 @@ class TestApprovalMultiwinner(unittest.TestCase):
self.assertEqual(result, [1, 0, 0, 0, 1, 1],
msg=method + " failed")
# example taken from
# Balinski, M. L., & Young, H. P. (1975).
# The quota method of apportionment.
# The American Mathematical Monthly, 82(7), 701-730.
def test_balinski_young_example(self):
self.longMessage = True
RESULTS = {"quota": [52, 44, 2, 1, 1],
"largest_remainder": [51, 44, 2, 2, 1],
"dhondt": [52, 45, 1, 1, 1],
"saintelague": [51, 43, 2, 2, 2],
"huntington": [51, 43, 2, 2, 2],
"adams": [51, 43, 2, 2, 2],
"dean": [51, 43, 2, 2, 2]
}
votes = [5117, 4400, 162, 161, 160]
seats = 100
for method in RESULTS.keys():
result = apportionment.method(method, votes,
seats, verbose=False)
self.assertEqual(result, RESULTS[method],
msg=method + " failed")
if __name__ == '__main__':
unittest.main()