示例#1
0
    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')
示例#2
0
    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())
示例#3
0
    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())
示例#4
0
    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())
示例#5
0
    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())