Ejemplo n.º 1
0
 def testCandidates(self):
     "general test of Candidates API"
     C = Candidates()
     c1 = Candidate(None, 1, 1, 3, 'Able', None, False)
             # Election, cid, ballotOrder, tieOrder, cname, cnick, isWithdrawn
     c2 = Candidate(None, 2, 2, 2, 'Baker', None, False)
     c3 = Candidate(None, 3, 3, 1, 'Charlie', None, False)
     c1.vote = 1
     c2.vote = 3
     c3.vote = 2
     C.add(c1)
     C.add(c2)
     C.add(c3)
     c2.state = 'elected'
     c3.state = 'elected'
     c3.pending = True
     C2 = C.copy()
     self.assertEqual(C, C2, "copy Candidates")
     self.assertEqual(C.byTieOrder([c1, c2, c3]), [c3, c2, c1], "tie order")
     self.assertEqual(C.byTieOrder([c1, c2, c3], reverse=True), [c1, c2, c3], "reverse tie order")
     self.assertEqual(C.byBallotOrder([c1, c2, c3]), [c1, c2, c3], "ballot order")
     self.assertEqual(C.byBallotOrder([c1, c2, c3], reverse=True), [c3, c2, c1], "reverse ballot order")
     self.assertEqual(C.byVote([c1, c2, c3]), [c1, c3, c2], "vote order")
     self.assertEqual(C.select('all', 'ballot'), [c1, c2, c3], "all candidates, ballot order")
     self.assertEqual(C.select('eligible', 'ballot', reverse=True), [c3, c2, c1],
         "eligible candidates, reverse ballot order")
     self.assertEqual(C.select('eligible', 'tie'), [c3, c2, c1], "eligible candidates, tie order")
     self.assertEqual(C.select('elected', 'ballot'), [c2, c3], "elected candidates, ballot order")
     self.assertEqual(C.notpending(), [c2], "elected-not-pending candidate")
     self.assertRaises(ValueError, C.select, 'all', "bad-order")
Ejemplo n.º 2
0
 def testCandidates(self):
     "general test of Candidates API"
     C = Candidates()
     c1 = Candidate(None, 1, 1, 3, 'Able', None, False)
     # Election, cid, ballotOrder, tieOrder, cname, cnick, isWithdrawn
     c2 = Candidate(None, 2, 2, 2, 'Baker', None, False)
     c3 = Candidate(None, 3, 3, 1, 'Charlie', None, False)
     c1.vote = 1
     c2.vote = 3
     c3.vote = 2
     C.add(c1)
     C.add(c2)
     C.add(c3)
     c2.state = 'elected'
     c3.state = 'elected'
     c3.pending = True
     C2 = C.copy()
     self.assertEqual(C, C2, "copy Candidates")
     self.assertEqual(C.byTieOrder([c1, c2, c3]), [c3, c2, c1], "tie order")
     self.assertEqual(C.byTieOrder([c1, c2, c3], reverse=True),
                      [c1, c2, c3], "reverse tie order")
     self.assertEqual(C.byBallotOrder([c1, c2, c3]), [c1, c2, c3],
                      "ballot order")
     self.assertEqual(C.byBallotOrder([c1, c2, c3], reverse=True),
                      [c3, c2, c1], "reverse ballot order")
     self.assertEqual(C.byVote([c1, c2, c3]), [c1, c3, c2], "vote order")
     self.assertEqual(C.select('all', 'ballot'), [c1, c2, c3],
                      "all candidates, ballot order")
     self.assertEqual(C.select('eligible', 'ballot',
                               reverse=True), [c3, c2, c1],
                      "eligible candidates, reverse ballot order")
     self.assertEqual(C.select('eligible', 'tie'), [c3, c2, c1],
                      "eligible candidates, tie order")
     self.assertEqual(C.select('elected', 'ballot'), [c2, c3],
                      "elected candidates, ballot order")
     self.assertEqual(C.notpending(), [c2], "elected-not-pending candidate")
     self.assertRaises(ValueError, C.select, 'all', "bad-order")
Ejemplo n.º 3
0
 def testCandidateCompare(self):
     "compare candidates by ID"
     c1 = Candidate(None, 1, 2, 2, 'abc', None, False)
     c2 = Candidate(None, 1, 3, 3, 'def', None, False)
     self.assertEqual(c1, c2, 'candidates are compared by ID')
Ejemplo n.º 4
0
 def testCandidateHash(self):
     "candidate hash is its ID"
     c1 = Candidate(None, 1, 2, 2, 'abc', None, False)
     self.assertEqual(hash(c1), 1, 'candidate hash is its ID')
Ejemplo n.º 5
0
 def testCandidateString(self):
     "candidate string is its cname"
     c1 = Candidate(None, 1, 2, 2, 'abc', None, False)
     # Election, cid, ballotOrder, tieOrder, cname, cnick, isWithdrawn
     self.assertEqual(str(c1), 'abc', 'candidate string is its cname')