def test_roll_dice_2(): x = GameLogic.roll_dice(5) j = False for i in x: if 1 <= i <= 6 and type(i) is int: j = True expected = True actual = j assert actual == expected
def test_gl_roll_dice_pass_2(self): """Test if the method returns all values in specified range (1 - 6) """ results = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0} for _ in range(10000): roll = Counter(GameLogic.roll_dice((6))) for pips, times in roll.items(): results[pips] += times for times in results.values(): assert times > 0
def test_gl_roll_dice_pass_1(self): """Test if the method returns a tuple""" assert type(GameLogic.roll_dice(2)) is tuple
def test_gl_roll_dice_value_error_1(self): """Test if the method raises ValueError if the passed in integer is out of range""" with pytest.raises(ValueError) as err: assert GameLogic.roll_dice(0) assert str(err.value) == "The number of dice must be between 1 and 6"
def test_gl_roll_dice_type_error(self): """Test if the method raises TypeError if not an integer passed in""" with pytest.raises(TypeError) as err: assert GameLogic.roll_dice(1.5) assert str(err.value) == "The number of dice must be an integer"
def test_2_dice(): values = GameLogic.roll_dice(2) assert len(values) == 2 for value in values: assert 1 <= value <= 6
def test_roll_dice_six(): dice = 6 actual = list(GameLogic.roll_dice(dice)) assert len(actual) == 6
def test_return_six_dice(): six = GameLogic.roll_dice(6) assert type(six) == tuple assert len(six) == 6
def player_roll(self): print(f"Starting round {self.current_round}") print(f"Rolling {self.remaining_dice} dice...") if self.dice_values is None: dice_values = GameLogic.roll_dice(self.remaining_dice) else: dice_values = self.dice_values # print("the dice_values are ", dice_values) # REMOVE points_to_bank = GameLogic.calculate_score(dice_values) if points_to_bank == 0: print('Zilch!!! Round over') print(f'You banked 0 points in round {self.current_round}') self.banker.clear_shelf() self.next_round() cheat_check = True while cheat_check: roll_display = "" for x in range(len(dice_values)): roll_display += str(dice_values[x]) + "," print(roll_display[:-1]) select_dice = input("Enter dice to keep (no spaces), or (q)uit: ") print("Nellie's: ", select_dice) # REMOVE if select_dice == 'q': self.quit_game() # dice_to_shelf = list(select_dice) # ORIG # dice_selected = list(select_dice) dice_selected = select_dice # check to make sure these are all integers -> Only if MVP # dice_to_shelf = tuple(map(int, dice_to_shelf)) dice_selected = tuple(dice_selected) # dice_to_shelf = (map(int, dice_to_shelf)) cheat_check = False # cheat_check = Game.validation(dice_values, dice_to_shelf) # points_to_bank = GameLogic.calculate_score(dice_to_shelf) points_to_bank = GameLogic.calculate_score(dice_selected) print(str(points_to_bank)) self.banker.shelf(points_to_bank) # self.remaining_dice -= len(dice_to_shelf) self.remaining_dice -= len(dice_selected) print( f'You have {self.banker.shelf_points} unbanked points and {self.remaining_dice} dice remaining' ) user_choice = input( "(r)oll again, (b)ank your points or (q)uit ").lower() if user_choice == 'r': # this also handles hot dice according to the flow tests if self.remaining_dice == 0: self.remaining_dice = 6 self.player_roll() elif user_choice == 'b': self.banker.bank() print('Your Banked Points: ', self.banker.bank_points) self.next_round() elif user_choice == 'q': self.quit_game()
def roller(num): if rolls: return rolls.pop(0) return GameLogic.roll_dice(num)
def test_6_dice(): values = GameLogic.roll_dice(6) assert len(values) == 6 for value in values: assert 1 <= value <= 6
def test_5_dice(): values = GameLogic.roll_dice(5) assert len(values) == 5 for value in values: assert 1 <= value <= 6
def test_4_dice(): values = GameLogic.roll_dice(4) assert len(values) == 4 for value in values: assert 1 <= value <= 6
def test_3_dice(): values = GameLogic.roll_dice(3) assert len(values) == 3 for value in values: assert 1 <= value <= 6
def test_roll_five(): roll = GameLogic.roll_dice(5) assert len(roll) == 5 for value in roll: assert 1 <= value <= 6
def test_gl_roll_dice_pass_3(self, dice): """Test if the method returns tuple of the correct length""" assert len(GameLogic.roll_dice(dice)) == dice
def test_all_valid_dice_rolls(num_dice, expected_length): roll = GameLogic.roll_dice(num_dice) assert len(roll) == expected_length for value in roll: assert 1 <= value <= 6
def test_return_one_thru_six(): for _ in range(1000): actual = GameLogic.roll_dice(1)[0] assert 1 <= actual <= 6
def test_roll_six(): roll = GameLogic.roll_dice(6) assert len(roll) == 6 for value in roll: assert 1 <= value <= 6
def test_roll_dice_1(): actual = len(GameLogic.roll_dice(5)) expected = 5 assert actual == expected
def test_roll_dice(): actual = len(GameLogic.roll_dice(6)) expected = 6 assert actual == expected
def test_roll_dice_one_len(): dice = 1 actual = list(GameLogic.roll_dice(dice)) assert len(actual) == 1
def test_1_dice(): values = GameLogic.roll_dice(1) assert len(values) == 1 value = values[0] assert 1 <= value <= 6