def test_plurality_alternate_ballot_format(self): # Generate data input = [{ "count": 26, "ballot": ["c1"] }, { "count": 22, "ballot": ["c2"] }, { "count": 23, "ballot": ["c3"] }] output = Plurality(input).as_dict() # Run tests self.assertEqual( output, { 'candidates': set(['c1', 'c2', 'c3']), 'tallies': { 'c3': 23, 'c2': 22, 'c1': 26 }, 'winner': 'c1' })
def test_irrelevant_ties(self): # Generate data input = [{ "count": 26, "ballot": "c1" }, { "count": 23, "ballot": "c2" }, { "count": 23, "ballot": "c3" }] output = Plurality(input).as_dict() # Run tests self.assertEqual( output, { 'candidates': set(['c1', 'c2', 'c3']), 'tallies': { 'c3': 23, 'c2': 23, 'c1': 26 }, 'winner': 'c1' })
def test_plurality_alternate_ballot_format(self): # Generate data input = [ { "count": 26, "ballot": ["c1"] }, { "count": 22, "ballot": ["c2"] }, { "count": 23, "ballot": ["c3"] }, ] output = Plurality(input).as_dict() # Run tests self.assertEqual( output, { "candidates": {"c1", "c2", "c3"}, "tallies": { "c3": 23, "c2": 22, "c1": 26 }, "winner": "c1", 'placements': [{ 'candidates': {'c1'}, 'points': 26 }, { 'candidates': {'c3'}, 'points': 23 }, { 'candidates': {'c2'}, 'points': 22 }], }, )
def test_relevant_ties(self): # Generate data input = [{ "count": 26, "ballot": "c1" }, { "count": 26, "ballot": "c2" }, { "count": 23, "ballot": "c3" }] output = Plurality(input).as_dict() # Run tests self.assertEqual(output["tallies"], {'c1': 26, 'c2': 26, 'c3': 23}) self.assertEqual(output["tied_winners"], set(['c1', 'c2'])) self.assertTrue(output["winner"] in output["tied_winners"]) self.assertEqual(len(output["tie_breaker"]), 3)
def test_irrelevant_ties(self): # Generate data input = [ { "count": 26, "ballot": "c1" }, { "count": 23, "ballot": "c2" }, { "count": 23, "ballot": "c3" }, ] output = Plurality(input, random_seed=0).as_dict() # Run tests self.assertEqual( output, { "candidates": {"c1", "c2", "c3"}, "tallies": { "c3": 23, "c2": 23, "c1": 26 }, "winner": "c1", 'placements': [{ 'candidates': {'c1'}, 'points': 26 }, { 'candidates': {'c2', 'c3'}, 'points': 23 }], }, )