-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyahtzee_spec.rb
37 lines (32 loc) · 1.08 KB
/
yahtzee_spec.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
#command to run tests (from project directory): rspec yahtzee_spec.rb
#before tests are run you must comment out the final lines of yahtzee.rb
#where a Game instance is created and the start_game loop is invoked
require_relative 'yahtzee.rb'
describe Game do
before(:context) do
@game = Game.new([1,2,3,4,5], 1, {})
end
it 'should initialize class variables' do
expect(@game.dice).to eq([1,2,3,4,5])
expect(@game.roll_count).to eq(1)
expect(@game.multiples).to eq({})
end
it 'should sort dice numerically' do
@game.sort_dice(54321)
expect(@game.dice).to eq([1,2,3,4,5])
@game.sort_dice(13321)
expect(@game.dice).to eq([1,1,2,3,3])
@game.sort_dice(12345)
expect(@game.dice).to eq([1,2,3,4,5])
end
it 'should organize dice into a hash' do
@game.organize_dice
expect(@game.multiples).to eq({1=>1, 2=>1, 3=>1, 4=>1, 5=>1})
end
it 'should identify straights correctly' do
@game.organize_dice
expect(@game.three_in_a_row?).to be true
expect(@game.four_in_a_row?).to be true
expect(@game.five_in_a_row?).to be true
end
end