Ejemplo n.º 1
0
class TestFirstDart(unittest.TestCase):
    def setUp(self):
        self.round = Round()

    @data(('S10', 10), # test single
          ('D10', 20), # test double
          ('T10', 30), # test triple
          ('s10', 10)  # test lower case
          )
    @unpack
    def test_hit(self, throw, total):
        # 1st dart hit => set the marker,
        #                 add the score to total,
        #                 missed_first remains unchanged
        dart_throw = DartThrow(throw)
        self.round.dart1(dart_throw)
        self.assertEqual(total, self.round.total)
        self.assertFalse(self.round.missed_first)
        self.assertEqual(int(throw[1:]), self.round.marker)

    def test_miss(self):
        # 1st dart missed => don't set the marker,
        #                    don't add the score to total,
        #                    missed_first is set to true
        dart_throw = DartThrow('M')
        self.round.dart1(dart_throw)
        self.assertEqual(-50, self.round.total)
        self.assertTrue(self.round.missed_first)
        self.assertEqual(-1, self.round.marker)
Ejemplo n.º 2
0
    def play(self):
        for _ in xrange(1, self.rounds + 1):
            self.current_round += 1
            self.print_score()
            for pKey, pVal in self.players.iteritems():
                start_msg = "Player {p}'s turn. Starting score = {s}"
                print start_msg.format(p=pKey, s=pVal.score)
                rnd = Round()
                dart = get_throw(1)
                rnd.dart1(DartThrow(dart))
                dart = get_throw(2)
                rnd.dart2_and_3(DartThrow(dart))
                dart = get_throw(3)
                rnd.dart2_and_3(DartThrow(dart))

                pVal.score += rnd.total
        self.game_in_progress = False