-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_condorcet.py
32 lines (26 loc) · 1008 Bytes
/
test_condorcet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Ranks candidates by the Condorcet method with also unvoted candidates.
For more information, please refer to https://en.wikipedia.org/wiki/Condorcet_method.
"""
__author__ = "Matteo Caorsi"
## I thank Michael G. Parker (http://omgitsmgp.com/) from whom I took the code skeleton
import numpy as np
import pandas as pd
import condorcet
def test_compute_ranks():
'''A simnple unit test
'''
# create dataframe
table = np.asarray([
["b","c","a"],
["c","a","b"],
["c","a","b"],
["b","a","c"],
["d","a","c"],
["d","a","c"]
])
df = pd.DataFrame(table, columns = ["first_preference","second_preference","third_preference"])
try:
# run the classification
assert condorcet.compute_ranks(df)==[['a', 'c'], ['b'], ['d']]
except:
raise ValueError("The method is not working as expected!")