def test_score_add(): new_player = Player() new_cpu = ComputerPlayer() new_player.add_points(20) new_cpu.add_points(25) assert new_player.score == 20 assert new_cpu.score == 25
def test_game_winner(): p1 = Player() p2 = Player() game = Game(rng, p1, p2) p1.score = 90 p2.score = 101 assert game.winner() == p2
def setUp(self): # create match with 3 players self.player_count = 3 self.match = Match(self.player_count) self.winner = Player(1) self.winner.score = 100 self.loser = Player(2) self.loser.score = 0
def test_current_player(): p1 = Player() p2 = Player() game = Game(rng, p1, p2) assert game.current_player == p1 game.switch_players() assert game.current_player == p2 game.switch_players() assert game.current_player == p1
def test_turn_score_is_zero_on_roll_of_one(): player = Player() turn = Turn(player) turn.score = 10 turn.record_roll(1) assert turn.score == 0
def test_turn_ends_on_a_roll_of_one(): player = Player() turn = Turn(player) assert not turn.over turn.record_roll(1) assert turn.over
def test_turn_collect_rolls(): player = Player() turn = Turn(player) assert turn.score == 0 turn.record_roll(3) assert turn.score == 3 turn.record_roll(5) assert turn.score == 8
class TestPlayer(unittest.TestCase): def setUp(self): self.p1 = Player(1) def test_init(self): assert self.p1.id assert type(self.p1.id) is int assert self.p1.score == 0 def test_bust(self): self.p1.score = 100 self.p1.bust_score() assert self.p1.score == 0 def test_tally(self): original_score = 35 self.p1.score = original_score dice = [3, 5] self.p1.tally_score(dice) supposed_score = original_score + sum(dice) assert self.p1.score == supposed_score
bill = Player() assert bill.total == 0 # def test_add_to_player_total(): # jeff = Player() # jeff.add_to_total(1) # assert jeff.total == 1 # def test_next_player_turn(): # sally = Player() # sally.next_turn() # assert sally.turn == 1 anne = Player() # def test_player_choice_roll(): # assert anne.choice(1) == 'roll' # # # def test_player_choice_hold(): # assert anne.choice(1) == 'hold' @mock.patch('random.randint') def test_roll(mock_random): mock_random.return_value = 6 assert roll_die() == 6
def test_player_roll(): player = Player('Human') player.roll(Die(6))
def test_create_player(): player = Player('Human') assert player.name == 'Human' assert player.score == 0 assert player.hold == 0 assert player.action == 'roll'
def test_player_has_initial_score_of_zero(): player = Player() assert player.score == 0
def setUp(self): self.p1 = Player(1)
def test_who_goes_first(): player = Player() assert player.first_player() == "human will go first."
def test_create_player_total_zero(): bill = Player() assert bill.total == 0
def test_game_loop(mock_random): mock_random.return_value = 2 jim = Player() assert game_loop(jim) == 14
def test_turn(mock_random): mock_random.return_value = 6 joe = Player() assert play(joe) == 6
def test_random_returns_num(): game = Game() player = Player(0, 0) computer = Player(0, 0, True) assert game.get_player() in [player, computer]
def test_player_exists(): new_player = Player() assert type(new_player) == Player assert new_player.score == 0
from pig import Dice, Player, Game, ComputerPlayer dice = Dice() player1 = Player() player2 = ComputerPlayer() def test_dice_exists(): new_dice = Dice() assert type(new_dice) == Dice def test_dice_equality(): dice1 = Dice() dice2 = Dice() assert dice1 == dice2 def test_dice_will_roll_within_params(): for _ in range(15): assert dice.roll() in range(1, 7) def test_player_exists(): new_player = Player() assert type(new_player) == Player assert new_player.score == 0 def test_score_add(): new_player = Player()