예제 #1
0
def test_roll_one_dice():
    actual = len(GameLogic().roll_dice(1))
    result = GameLogic().roll_dice(1)
    expected = 1
    range =True
    for i in result:
        if i > 6 or i <1:
            range= False
    assert actual == expected
    assert (range == True),'The value of the dice is not between 1 to 6'
예제 #2
0
    def play(self):
        round = 1
        num_dice = 6
        score = 0
        x = Banker()

        print("Welcome to Game of Greed")
        response = input("Wanna play?")
        if response == 'n':
            print("OK. Maybe another time")
        elif response == 'y':
            print(f"Starting round {round}")
            print(f"Rolling {num_dice} dice...")
            roll = self.roller(num_dice)
            print(Game.print_roll(roll))
            self.print_roll(roll)

            while 0 < round <= 6:

                what_next = input(
                    "Enter dice to keep (no spaces), or (q)uit: ")
                if what_next == 'q' or what_next == 'quit':

                    break
                else:
                    generate_new_tupe = Game.convert_to_tup(what_next)
                    score += GameLogic.calculte_score(generate_new_tupe)
                    num_dice = 6 - len(generate_new_tupe)
                    print(
                        f"You have {score} unbanked points and {num_dice} dice remaining"
                    )
                    inpt = input("(r)oll again, (b)ank your points or (q)uit ")

                    if inpt == 'q' or inpt == 'quit':
                        break

                    if inpt == 'r' or inpt == 'roll':
                        # new_roll = GameLogic.role_dice(num_dice)
                        new_roll = self.roller(num_dice)
                        print(f"Rolling {num_dice} dice...")
                        rol3 = Game.print_roll(new_roll)
                        num_dice = 6 - len(generate_new_tupe)
                        print(rol3)

                    if inpt == 'b' or inpt == 'bank':
                        x.shelf(score)
                        x.bank()
                        print(f"You banked {score} points in round {round}")
                        print(f"Total score is {x.total} points")
                        round += 1
                        print(f"Starting round {round}")
                        print("Rolling 6 dice...")
                        # new_numbers = GameLogic.role_dice(6)
                        new_numbers = self.roller(6)
                        rol3 = Game.print_roll(new_numbers)
                        print(rol3)
                        score = 0

            print(f"Total score is {x.total} points")
            print(f"Thanks for playing. You earned {x.total} points")
def test_three_ones_and_a_five():
    actual = GameLogic.calculate_score((1, 1, 1, 5))
    expected = 1050
    assert actual == expected
def test_three_ones():
    actual = GameLogic.calculate_score((1, 1, 1, 2, 3, 4))
    expected = 1000
    assert actual == expected
def test_three_fives():
    actual = GameLogic.calculate_score((5, 5, 5, 2, 2, 3))
    expected = 500
    assert actual == expected
def test_zilch():
    actual = GameLogic.calculate_score((2,))
    expected = 0
    assert actual == expected
def test_one_and_five():
    actual = GameLogic.calculate_score((1, 5))
    expected = 150
    assert actual == expected
예제 #8
0
def test_return_one_thru_six():
    for _ in range(1000):
        actual = GameLogic.roll_dice(1)[0]
        assert 1 <= actual <= 6
def test_six_of_a_kind():
    actual = GameLogic.calculate_score((2, 2, 2, 2, 2, 2))
    expected = 800
    assert actual == expected
def test_all(test_input, expected):
    actual = GameLogic.calculate_score(test_input)
    assert actual == expected
def test_single_one():
    actual = GameLogic.calculate_score((1,))
    expected = 100
    assert actual == expected
예제 #12
0
def test_length():
    game_logic = GameLogic()
    actual = len(game_logic.roll_dice(5))
    expected = 5
    assert actual == expected
예제 #13
0
def test_value():
    game_logic = GameLogic()
    actual = game_logic.roll_dice(5)
    for i in actual:
        assert isinstance(i, int)
        assert 1 <= i <= 6
def test_single_five():
    actual = GameLogic.calculate_score((5,))
    expected = 50
    assert actual == expected
def test_two_fives():
    actual = GameLogic.calculate_score((5, 5))
    expected = 100
    assert actual == expected
def test_straight():
    actual = GameLogic.calculate_score((1, 6, 3, 2, 5, 4))
    expected = 1500
    assert actual == expected
def test_two_ones():
    actual = GameLogic.calculate_score((1, 1))
    expected = 200
    assert actual == expected
def test_six_ones():
    actual = GameLogic.calculate_score((1, 1, 1, 1, 1, 1))
    expected = 4000
    assert actual == expected
예제 #19
0
def test_return_six_dice():
    six = GameLogic.roll_dice(6)
    assert type(six) == tuple
    assert len(six) == 6