class TestSecondDart(unittest.TestCase): def setUp(self): self.round = Round() @data(('S10', 20), ('s10', 20), ('D10', 30), ('T10', 40), ('M', -40), ('S5', 5)) @unpack def test_first_dart_hit(self, throw, total): self.round.missed_first = False self.round.marker = 10 self.round.total = 10 self.round.dart2_and_3(DartThrow(throw)) self.assertEqual(total, self.round.total) @data(('S10', 20), ('M', -50)) @unpack def test_first_dart_miss(self, throw, total): self.round.missed_first = True self.round.total = 0 self.round.dart2_and_3(DartThrow('S10')) self.assertEqual(-10, self.round.total)
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