def test_quorum_majority(self): """ Test that the quorum majority is correct """ ballots = Election('abcdef') self.assertEqual(ballots.n_majority, 4, 'Even quorum majority computation failed') ballots = Election('abcdefg') self.assertEqual(ballots.n_majority, 4, 'Odd quorum majority computation failed')
def test_election_quorum(self): """ Test that an election stays incomplete until a majority of votes """ votes = Election('abcdef') for idx, char in enumerate('abc'): votes.vote(char, idx % 2 == 0) self.assertFalse(votes.has_quorum()) for idx, char in enumerate('def'): votes.vote(char, idx % 2 == 0) self.assertTrue(votes.has_quorum())
def test_election_failed(self): """ Test that an election fails after quorum """ votes = Election('abcdef') for idx, char in enumerate('abc'): votes.vote(char, idx % 2 != 0) self.assertFalse(votes.has_failed()) for idx, char in enumerate('def'): votes.vote(char, idx % 2 != 0) self.assertTrue(votes.has_failed())