bare_gato 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/bare_gato/game.rb +2 -2
- data/lib/bare_gato/version.rb +1 -1
- data/spec/bare_gato/game_spec.rb +25 -19
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/bare_gato/game.rb
CHANGED
data/lib/bare_gato/version.rb
CHANGED
data/spec/bare_gato/game_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe BareGato::Game do
|
|
6
6
|
|
7
7
|
let(:o_player) { Player.new 'o' }
|
8
8
|
|
9
|
-
describe
|
9
|
+
describe 'a 3x3 game' do
|
10
10
|
subject do
|
11
11
|
bare_gato_game = BareGato::Game.new players: [
|
12
12
|
x_player, o_player
|
@@ -20,17 +20,23 @@ describe BareGato::Game do
|
|
20
20
|
bare_gato_game
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'should tell if a player belongs to a game' do
|
24
|
+
expect(subject.includes_player? x_player).to be_true
|
25
|
+
expect(subject.includes_player? o_player).to be_true
|
26
|
+
expect(subject.includes_player? Player.new 'pepino').to be_false
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should start with the last added player' do
|
24
30
|
expect(subject.next? o_player).to be_true
|
25
31
|
move = Move.new o_player, x: 0, y: 0
|
26
32
|
subject.play move
|
27
33
|
end
|
28
34
|
|
29
|
-
it
|
35
|
+
it 'should return the next move type' do
|
30
36
|
subject.next.should eq(o_player)
|
31
37
|
end
|
32
38
|
|
33
|
-
it
|
39
|
+
it 'should keep movements sequence' do
|
34
40
|
subject.play Move.new(o_player, x: 0, y: 0)
|
35
41
|
expect(subject.next? o_player).to be_false
|
36
42
|
expect(subject.next? x_player).to be_true
|
@@ -40,7 +46,7 @@ describe BareGato::Game do
|
|
40
46
|
expect(subject.next? o_player).to be_true
|
41
47
|
end
|
42
48
|
|
43
|
-
it
|
49
|
+
it 'should return the current game status' do
|
44
50
|
subject.status.should eq({
|
45
51
|
game: [[nil, nil, nil],
|
46
52
|
[nil, nil, nil],
|
@@ -49,16 +55,16 @@ describe BareGato::Game do
|
|
49
55
|
})
|
50
56
|
end
|
51
57
|
|
52
|
-
describe
|
58
|
+
describe 'playing a few moves' do
|
53
59
|
|
54
|
-
context
|
60
|
+
context 'providing correct moves order' do
|
55
61
|
before do
|
56
62
|
subject.play Move.new(o_player, x: 0, y: 0)
|
57
63
|
subject.play Move.new(x_player, x: 1, y: 0)
|
58
64
|
subject.play Move.new(o_player, x: 0, y: 2)
|
59
65
|
end
|
60
66
|
|
61
|
-
it
|
67
|
+
it 'should return the current game status' do
|
62
68
|
subject.status.should eq({
|
63
69
|
game: [[o_player, x_player, nil],
|
64
70
|
[nil, nil, nil],
|
@@ -68,8 +74,8 @@ describe BareGato::Game do
|
|
68
74
|
end
|
69
75
|
end
|
70
76
|
|
71
|
-
context
|
72
|
-
it
|
77
|
+
context 'providing incorrect moves order' do
|
78
|
+
it 'should raise error' do
|
73
79
|
expect { subject.play Move.new(x_player, x: 0, y: 0) }.to raise_error
|
74
80
|
subject.play Move.new(o_player, x: 0, y: 0)
|
75
81
|
subject.status.should eq({
|
@@ -82,9 +88,9 @@ describe BareGato::Game do
|
|
82
88
|
end
|
83
89
|
end
|
84
90
|
|
85
|
-
context
|
86
|
-
context
|
87
|
-
it
|
91
|
+
context 'a full game' do
|
92
|
+
context 'when winning by column' do
|
93
|
+
it 'should determine a winner' do
|
88
94
|
subject.play Move.new(o_player, x: 0, y: 0)
|
89
95
|
subject.got_a_winner?.should be_false
|
90
96
|
|
@@ -111,8 +117,8 @@ describe BareGato::Game do
|
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
114
|
-
context
|
115
|
-
it
|
120
|
+
context 'when winning by row' do
|
121
|
+
it 'should determine a winner' do
|
116
122
|
subject.play Move.new(o_player, x: 0, y: 0)
|
117
123
|
subject.got_a_winner?.should be_false
|
118
124
|
|
@@ -136,8 +142,8 @@ describe BareGato::Game do
|
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
|
-
context
|
140
|
-
it
|
145
|
+
context 'when winning by diagonal' do
|
146
|
+
it 'should determine a winner' do
|
141
147
|
subject.play Move.new(o_player, x: 0, y: 0)
|
142
148
|
subject.got_a_winner?.should be_false
|
143
149
|
|
@@ -161,8 +167,8 @@ describe BareGato::Game do
|
|
161
167
|
end
|
162
168
|
end
|
163
169
|
|
164
|
-
context
|
165
|
-
it
|
170
|
+
context 'when winning by inverse diagonal' do
|
171
|
+
it 'should determine a winner' do
|
166
172
|
subject.play Move.new(o_player, x: 2, y: 0)
|
167
173
|
subject.got_a_winner?.should be_false
|
168
174
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bare_gato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
segments:
|
108
108
|
- 0
|
109
|
-
hash:
|
109
|
+
hash: 85962428890766304
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
111
|
none: false
|
112
112
|
requirements:
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
segments:
|
117
117
|
- 0
|
118
|
-
hash:
|
118
|
+
hash: 85962428890766304
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
121
|
rubygems_version: 1.8.23
|