def test_verify_runoff_scenario_3c(): e = pirv.Election([1,2]) e.vote([1]) e.vote([]) e.vote([1]) e.vote([]) t = e._tally_votes() assert e.winner() == 1
def test_wiki_five_voters_three_candidates(): e = pirv.Election(['Bob', 'Sue', 'Bill']) e.vote(['Bob', 'Bill', 'Sue']) e.vote(['Sue', 'Bob', 'Bill']) e.vote(['Bill', 'Sue', 'Bob']) e.vote(['Bob', 'Bill', 'Sue']) e.vote(['Sue', 'Bob', 'Bill']) assert e.winner() == 'Sue'
def test_wiki_Tennessee_capital_election(): e = pirv.Election(['Memphis', 'Knoxville', 'Nashville', 'Chattanooga']) for i in range(42): e.vote(['Memphis', 'Nashville', 'Chattanooga', 'Knoxville']) for i in range(26): e.vote(['Nashville', 'Chattanooga', 'Knoxville', 'Memphis']) for i in range(15): e.vote(['Chattanooga', 'Knoxville', 'Nashville', 'Memphis']) for i in range(17): e.vote(['Knoxville', 'Chattanooga', 'Nashville', 'Memphis']) assert e.winner() == 'Knoxville'
def test_verify_runoff_scenario_3(): e = pirv.Election([1,2,3,4]) e.vote([1,3]) e.vote([2,3]) e.vote([1,3]) e.vote([3]) t = e._tally_votes() assert t[1] == 2 assert t[2] == 1 assert t[3] == 1 (winners, losers) = e._find_results(t) assert 1 in winners assert 4 in losers assert e.winner() is None
def test_verify_runoff_scenario_4(): e =pirv.Election([1,2,3,4]) e.vote([1,4]) e.vote([2,4]) e.vote([2,4]) e.vote([4,2]) e.vote([4,3]) e.vote([3,4]) assert e.votes_required_to_win() == 4 t = e._tally_votes() assert t[1] == 1 assert t[2] == 2 assert t[3] == 1 assert t[4] == 2 (winners, losers) = e._find_results(t) assert 1 in losers assert 3 in losers assert 2 in winners assert 4 in winners assert e.winner() == 4
def test_verify_runoff_scenario_2(): e = pirv.Election([1,2,3]) e.vote([1,3]) e.vote([2,3]) e.vote([1,3]) assert e.winner() == 1
def _ab_election(): return pirv.Election(['a','b'])
def test_empty_list_raises_exception(): with pytest.raises(pirv.EmptyBallotListException): e = pirv.Election([])