-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rps.py
42 lines (33 loc) · 1.15 KB
/
test_rps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import rps
import pytest
def test_rock_is_a_valid_play():
assert rps.is_valid_play('rock') is True
def test_paper_is_a_valid_play():
assert rps.is_valid_play('paper') is True
def test_scissors_is_a_valid_play():
assert rps.is_valid_play('scissors') is True
def test_spock_is_a_valid_play():
assert rps.is_valid_play('spock') is False
def test_random_play_is_always_valid():
for _ in range(1000):
assert rps.is_valid_play(rps.random_play())
def test_random_play_is_fair():
plays = {
'rock': 0,
'paper': 0,
'scissors': 0
}
for _ in range(10000):
play = rps.random_play()
plays[play] += 1
for value in plays.values():
assert value > 3000
@pytest.mark.parametrize('play', ['rock', 'paper', 'scissors'])
def test_same_is_tie(play):
assert rps.determine_game_result(play, play) == 'tie'
@pytest.mark.parametrize('human, computer',
[('rock', 'scissors'),
('paper', 'rock'),
('scissors', 'paper')])
def test_human_wins(human, computer):
assert rps.determine_game_result(human, computer) == 'human'