def setUp(self):
     self.tv = TackVoting(100, 75)
 def setUp(self):
     self.tv = TackVoting(100, 75)
class TackVotingTests(unittest.TestCase):
    def setUp(self):
        self.tv = TackVoting(100, 75)

    def test_subtract_one(self):
        self.tv.reset(1)
        self.tv.vote(0)
        self.assertEqual(self.tv.votes_sum, 99)

    def test_threshold_to_port(self):
        self.tv.reset(0)
        for a in range(75):
            self.tv.vote(1)
        assert not self.tv.tack_now(0)
        self.tv.vote(1)
        assert self.tv.tack_now(0)

    def test_threshold_to_starboard(self):
        self.tv.reset(1)
        for a in range(75):
            self.tv.vote(0)
        assert not self.tv.tack_now(1)
        self.tv.vote(0)
        assert self.tv.tack_now(1)

    def test_initial_state(self):
        self.assertEqual(self.tv.votes_sum, 50)
        for _ in range(2):
            self.tv.vote(0)
        # One 1 should have been pushed out the other end
        self.assertEqual(self.tv.votes_sum, 49)
        for _ in range(48):
            self.tv.vote(0)
        self.assertEqual(self.tv.votes_sum, 25)
class TackVotingTests(unittest.TestCase):
    def setUp(self):
        self.tv = TackVoting(100, 75)

    def test_subtract_one(self):
        self.tv.reset(1)
        self.tv.vote(0)
        self.assertEqual(self.tv.votes_sum, 99)

    def test_threshold_to_port(self):
        self.tv.reset(0)
        for a in range(75):
            self.tv.vote(1)
        assert not self.tv.tack_now(0)
        self.tv.vote(1)
        assert self.tv.tack_now(0)

    def test_threshold_to_starboard(self):
        self.tv.reset(1)
        for a in range(75):
            self.tv.vote(0)
        assert not self.tv.tack_now(1)
        self.tv.vote(0)
        assert self.tv.tack_now(1)

    def test_initial_state(self):
        self.assertEqual(self.tv.votes_sum, 50)
        for _ in range(2):
            self.tv.vote(0)
        # One 1 should have been pushed out the other end
        self.assertEqual(self.tv.votes_sum, 49)
        for _ in range(48):
            self.tv.vote(0)
        self.assertEqual(self.tv.votes_sum, 25)