-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgame_test.rb
executable file
·55 lines (44 loc) · 1.21 KB
/
game_test.rb
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
43
44
45
46
47
48
49
50
51
52
53
54
55
require "minitest/autorun"
require "minitest/pride"
require "./dice"
require "./game"
class GameTest < MiniTest::Test
def test_loaded_dice_are_predictable
dice = LoadedDice.new
assert_equal 6, dice.roll
end
def test_psychic_dice_know_the_future
future = [2,3,6,1]
dice = PsychicDice.new future
future.each do |predicted|
assert_equal predicted, dice.roll
end
end
def test_players_have_dice
dice = Dice.new
alice = Player.new "alice", dice
assert_equal dice, alice.dice
end
def test_somebody_eventually_wins
alice = Player.new "alice", Dice.new
bob = Player.new "bob", Dice.new
game = Game.new alice, bob
game.play!
assert [alice, bob].include? game.winner
end
def test_cheaters_always_win
su = Player.new "su", Dice.new
james = Player.new "james", LoadedDice.new
game = Game.new su, james
game.play!
assert_equal james, game.winner
end
def test_predictable_games_are_predictable
brit = Player.new "brit", PsychicDice.new([3,1,4])
sarah = Player.new "sarah", PsychicDice.new([3,1,2])
game = Game.new brit, sarah
game.play!
assert_equal brit, game.winner
assert_equal 3, game.turn
end
end