Ejemplo n.º 1
0
 def test_assign_ballots(self):
     test_tabulation = self.make_irv_01()
     test_tabulation.tabulate(stop_at_begin=1)
     self.assertEqual(test_tabulation.ballots_for['A'], [])
     test_tabulation.assign_ballots(test_tabulation.ballots)
     self.assertEqual(test_tabulation.ballots_for['A'],
                      [ballot.Ballot(15, ('A', 'B', 'C'))])
Ejemplo n.º 2
0
 def test_ballot_update_transfer_value_1(self):
     test_ballot = ballot.Ballot(5, str_tuple(' A B C'))
     self.assertEqual(test_ballot.update_transfer_value(Decimal(5) / 7),
                      Decimal(0.71428))
     self.assertEqual(test_ballot.update_transfer_value(Decimal(5) / 7),
                      Decimal(0.51019))
     self.assertEqual(test_ballot.update_transfer_value(Decimal(5) / 7),
                      Decimal(0.36441))
Ejemplo n.º 3
0
 def test_ballot_get_hrcc_dups_1(self):
     test_ballot = ballot.Ballot(5, str_tuple(' A A A'))
     self.assertEqual(test_ballot.get_hrcc(('A', 'C'), 3), 'A')
     self.assertEqual(test_ballot.get_hrcc(('A', 'C'), 3), 'A')
     self.assertEqual(test_ballot.get_hrcc(('B', 'C'), 3), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('B', 'C'), 3), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('C', ), 3), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('C', ), 3), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 3), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 3), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 5), ':Abstentions')
Ejemplo n.º 4
0
 def test_ballot_get_hrcc_skipped_2(self):
     test_ballot = ballot.Ballot(5, str_tuple(' A   C'))
     self.assertEqual(test_ballot.get_hrcc(('A', ), 4), 'A')
     self.assertEqual(test_ballot.get_hrcc(('A', ), 4), 'A')
     self.assertEqual(test_ballot.get_hrcc(('B', 'C'), 4), 'C')
     self.assertEqual(test_ballot.get_hrcc(('B', 'C'), 4), 'C')
     self.assertEqual(test_ballot.get_hrcc(('C', ), 4), 'C')
     self.assertEqual(test_ballot.get_hrcc(('C', ), 4), 'C')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 4), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 4), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 5), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 5), ':Abstentions')
Ejemplo n.º 5
0
 def test_ballot_get_hrcc_ov(self):
     test_ballot = ballot.Ballot(5, str_tuple(' A # C'))
     self.assertEqual(test_ballot.get_hrcc(('A', ), 3), 'A')
     self.assertEqual(test_ballot.get_hrcc(('A', ), 3), 'A')
     self.assertEqual(test_ballot.get_hrcc(('B', ), 3), ':Overvotes')
     self.assertEqual(test_ballot.get_hrcc(('B', ), 3), ':Overvotes')
     self.assertEqual(test_ballot.get_hrcc(('C', ), 3), ':Overvotes')
     self.assertEqual(test_ballot.get_hrcc(('C', ), 3), ':Overvotes')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 3), ':Overvotes')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 3), ':Overvotes')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 4), ':Overvotes')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 4), ':Overvotes')
Ejemplo n.º 6
0
 def test_ballot_get_hrcc_1(self):
     test_ballot = ballot.Ballot(5, str_tuple(' A B C'))
     self.assertEqual(test_ballot.get_hrcc(('A', ), 3), 'A')
     self.assertEqual(test_ballot.get_hrcc(('A', ), 3), 'A')
     self.assertEqual(test_ballot.get_hrcc(('B', ), 3), 'B')
     self.assertEqual(test_ballot.get_hrcc(('B', ), 3), 'B')
     self.assertEqual(test_ballot.get_hrcc(('C', ), 3), 'C')
     self.assertEqual(test_ballot.get_hrcc(('C', ), 3), 'C')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 3), ':Other exhausted')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 3), ':Other exhausted')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 4), ':Abstentions')
     self.assertEqual(test_ballot.get_hrcc(('D', ), 4), ':Abstentions')
Ejemplo n.º 7
0
 def test_as_irv_1(self):
     test_tabulation = self.make_irv_01()
     self.assertEqual(test_tabulation.is_irv(), True)
     self.assertEqual(test_tabulation.zero_votes(), 0)
     test_ballot = ballot.Ballot(7, ' C B A')
     self.assertEqual(test_tabulation.ballot_votes(test_ballot), 7)
     self.assertEqual(test_tabulation.other_categories(), {
         ':Other exhausted': [],
         ':Abstentions': [],
         ':Overvotes': []
     })
     test_votes = test_tabulation.votes_for_previously_elected(12)
     self.assertEqual(test_votes, 12)
Ejemplo n.º 8
0
 def test_as_stv_1(self):
     test_tabulation = self.make_stv_01()
     self.assertEqual(test_tabulation.is_irv(), False)
     self.assertEqual(test_tabulation.zero_votes(), K.ZERO)
     test_ballot = ballot.Ballot(7, ' C B A')
     self.assertEqual(test_tabulation.ballot_votes(test_ballot), K.ONE * 7)
     self.assertEqual(
         test_tabulation.other_categories(), {
             ':Other exhausted': [],
             ':Abstentions': [],
             ':Overvotes': [],
             ':Residual surplus': []
         })
     test_tabulation.tabulate(stop_after_tally=1)
     test_votes = test_tabulation.votes_for_previously_elected(K.ONE * 19)
     self.assertEqual(test_votes, K.Decimal(9.5))
Ejemplo n.º 9
0
 def test_ballot_as_string(self):
     test_ballot = ballot.Ballot(7, ('C', 'B', 'A'))
     self.assertEqual(repr(test_ballot), "(7, 1.00000, ('C', 'B', 'A'))")
     self.assertEqual(str(test_ballot), "(7, ('C', 'B', 'A'))")
Ejemplo n.º 10
0
 def test_ballot_accessors(self):
     test_ballot = ballot.Ballot(7, ('C', 'B', 'A'))
     self.assertEqual(test_ballot.get_multiple(), 7)
     self.assertEqual(test_ballot.get_transfer_value(), Decimal(1))
Ejemplo n.º 11
0
 def test_ballot_create(self):
     test_ballot = ballot.Ballot(3, ('A', 'B', 'C'))
     self.assertEqual(test_ballot._multiple, 3)
     self.assertEqual(test_ballot._transfer_value, Decimal(1))
     self.assertEqual(test_ballot._rankings, ('A', 'B', 'C'))
     self.assertEqual(test_ballot._current_index, 0)