rora 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +210 -20
- data/lib/rora/model/board.rb +10 -0
- data/lib/rora/model/card.rb +1 -5
- data/lib/rora/model/game.rb +70 -2
- data/lib/rora/model/hand.rb +1 -2
- data/lib/rora/model/player.rb +70 -5
- data/lib/rora/model/pot.rb +7 -6
- data/lib/rora/model/rank.rb +2 -2
- data/lib/rora/model/seat.rb +31 -0
- data/lib/rora/model/starting_hand.rb +4 -0
- data/lib/rora/model/suit.rb +1 -1
- data/lib/rora/model/table.rb +107 -14
- data/lib/rora/utils/game_logger.rb +19 -0
- data/lib/rora.rb +7 -2
- data/test/rora/model/board_test.rb +14 -12
- data/test/rora/model/card_test.rb +16 -7
- data/test/rora/model/game_test.rb +23 -0
- data/test/rora/model/hand_type_test.rb +3 -3
- data/test/rora/model/player_test.rb +108 -0
- data/test/rora/model/pot_test.rb +15 -8
- data/test/rora/model/rank_test.rb +6 -6
- data/test/rora/model/seat_test.rb +41 -0
- data/test/rora/model/suit_test.rb +1 -1
- data/test/rora/model/table_test.rb +230 -0
- data/test/rora_test.rb +2 -1
- metadata +48 -6
@@ -0,0 +1,230 @@
|
|
1
|
+
require File.expand_path("../../rora_test", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class TableTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@table = Table.new
|
7
|
+
end
|
8
|
+
|
9
|
+
test "a table should have 9 seats by default" do
|
10
|
+
assert_equal 9, @table.size
|
11
|
+
end
|
12
|
+
|
13
|
+
test "a new table should have a deck of 52 cards" do
|
14
|
+
assert_equal 52, @table.deck.size
|
15
|
+
end
|
16
|
+
|
17
|
+
test "a new table should have an empty board" do
|
18
|
+
assert_equal 0, @table.board.size
|
19
|
+
end
|
20
|
+
|
21
|
+
test "a new table should have a pot with no money" do
|
22
|
+
assert_equal 0, @table.pot.value
|
23
|
+
end
|
24
|
+
|
25
|
+
test "should be able to reset a board" do
|
26
|
+
@table.with(Deck.new.remove("AS,KS,QS")).with(Board.new("AH,KH,QH")).with(Pot.new.add(50))
|
27
|
+
assert_equal 50, @table.pot.value
|
28
|
+
assert_equal 3, @table.board.cards.size
|
29
|
+
assert_equal 49, @table.deck.size
|
30
|
+
|
31
|
+
@table.reset
|
32
|
+
assert_equal 0, @table.pot.value
|
33
|
+
assert_equal 0, @table.board.cards.size
|
34
|
+
assert_equal 52, @table.deck.size
|
35
|
+
end
|
36
|
+
|
37
|
+
test "should be able to configure the number of seats at a table" do
|
38
|
+
assert_equal 6, Table.new(6).size
|
39
|
+
end
|
40
|
+
|
41
|
+
test "should raise an error when a table is created with less than two seats" do
|
42
|
+
assert_raise ArgumentError, "A table must have at least two seats" do
|
43
|
+
Table.new 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
test "should be able to seat a player at the table" do
|
48
|
+
@table.add "player"
|
49
|
+
assert_equal "player", @table.seat(1).player
|
50
|
+
end
|
51
|
+
|
52
|
+
test "should be able to seat a player at a specific seat at the table" do
|
53
|
+
@table.add "player", 4
|
54
|
+
assert_equal "player", @table.seat(4).player
|
55
|
+
end
|
56
|
+
|
57
|
+
test "should raise an error when attempting to seat a player at a seat that is already taken" do
|
58
|
+
@table.add "player1", 4
|
59
|
+
assert_raise ArgumentError, "Seat number 4 is already taken by another player" do
|
60
|
+
@table.add "player2", 4
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test "should raise an error when attempting to seat a player at a seat that does not exist" do
|
65
|
+
assert_raise ArgumentError, "Seat number 11 does not exist at this table" do
|
66
|
+
@table.add "player", 11
|
67
|
+
end
|
68
|
+
assert_raise ArgumentError, "Seat number 0 does not exist at this table" do
|
69
|
+
@table.add "player", 0
|
70
|
+
end
|
71
|
+
assert_raise ArgumentError, "Seat number -3 does not exist at this table" do
|
72
|
+
@table.add "player", -3
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
test "should find the first available seat when no seat number is specified" do
|
77
|
+
@table.add("Player 1", 1).add("Player 2", 2).add("Player 3", 3).add("Player 5", 5)
|
78
|
+
@table.add "Player 4"
|
79
|
+
assert_equal @table.seat(4).player, "Player 4"
|
80
|
+
end
|
81
|
+
|
82
|
+
test "full? should return true when the table is full" do
|
83
|
+
(1..9).each {|x| @table.add("player#{x}")}
|
84
|
+
assert_equal true, @table.full?
|
85
|
+
end
|
86
|
+
|
87
|
+
test "full? should return false when the table is not full" do
|
88
|
+
(1..8).each {|x| @table.add("player#{x}")}
|
89
|
+
assert_equal false, @table.full?
|
90
|
+
end
|
91
|
+
|
92
|
+
test "empty? should return true when the table is empty" do
|
93
|
+
assert_equal true, @table.empty?
|
94
|
+
end
|
95
|
+
|
96
|
+
test "empty? should return false when the table is not empty" do
|
97
|
+
@table.add "player"
|
98
|
+
assert_equal false, @table.empty?
|
99
|
+
end
|
100
|
+
|
101
|
+
test "should raise an error when attempting to seat a player at a full table" do
|
102
|
+
(1..9).each {|x| @table.add("player#{x}")}
|
103
|
+
assert_raise RuntimeError do
|
104
|
+
@table.add "player 10"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
test "should be able to remove a player" do
|
109
|
+
@table.add "player1"
|
110
|
+
assert_equal true, @table.seat(1).taken?
|
111
|
+
assert_equal 9, @table.size
|
112
|
+
|
113
|
+
@table.remove "player1"
|
114
|
+
assert_equal false, @table.seat(1).taken?
|
115
|
+
assert_equal 9, @table.size
|
116
|
+
end
|
117
|
+
|
118
|
+
test "should return the next player to act after the specified seat" do
|
119
|
+
@table.add("Player 1", 1).add("Player 5", 5)
|
120
|
+
seat = @table.the_seat_after @table.seat(1)
|
121
|
+
assert_equal "Player 5", seat.player
|
122
|
+
end
|
123
|
+
|
124
|
+
test "should return the next player to act even when the specified seat is empty" do
|
125
|
+
@table.add("Player 1", 1).add("Player 5", 5)
|
126
|
+
seat = @table.the_seat_after @table.seat(4)
|
127
|
+
assert_equal "Player 5", seat.player
|
128
|
+
end
|
129
|
+
|
130
|
+
test "should loop around the table to find the next player to act" do
|
131
|
+
@table.add("Player 1", 1).add("Player 5", 5)
|
132
|
+
seat = @table.the_seat_after @table.seat(8)
|
133
|
+
assert_equal "Player 1", seat.player
|
134
|
+
end
|
135
|
+
|
136
|
+
test "should raise an error when trying to find the next player to act when there are less than two players at the table" do
|
137
|
+
@table.add("Player 1", 1)
|
138
|
+
assert_raise RuntimeError, "Cannot find the next player when there are less than two players at the table" do
|
139
|
+
@table.the_seat_after @table.seat(8)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
test "should return the previous player to act before the specified seat" do
|
144
|
+
@table.add("Player 1", 1).add("Player 5", 5)
|
145
|
+
seat = @table.the_seat_before @table.seat(5)
|
146
|
+
assert_equal "Player 1", seat.player
|
147
|
+
end
|
148
|
+
|
149
|
+
test "should return the previous player to act even when the specified seat is empty" do
|
150
|
+
@table.add("Player 1", 1).add("Player 5", 5)
|
151
|
+
seat = @table.the_seat_before @table.seat(4)
|
152
|
+
assert_equal "Player 1", seat.player
|
153
|
+
end
|
154
|
+
|
155
|
+
test "should loop around the table to find the previous player to act" do
|
156
|
+
@table.add("Player 1", 3).add("Player 5", 5)
|
157
|
+
seat = @table.the_seat_before @table.seat(2)
|
158
|
+
assert_equal "Player 5", seat.player
|
159
|
+
end
|
160
|
+
|
161
|
+
test "should raise an error when trying to find the previous player to act when there are less than two players at the table" do
|
162
|
+
@table.add("Player 1", 1)
|
163
|
+
assert_raise RuntimeError, "Cannot find the previous player when there are less than two players at the table" do
|
164
|
+
@table.the_seat_before @table.seat(8)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
test "should return the seat holding the button" do
|
169
|
+
@table.add("Player 1", 1).add("Player 2", 2).add("Player 3", 3).add("Player 5", 5)
|
170
|
+
@table.seat(5).button = true
|
171
|
+
assert_equal "Player 5", @table.the_button.player
|
172
|
+
end
|
173
|
+
|
174
|
+
test "should return the first seat occupied by a player if no seat is holding the button" do
|
175
|
+
@table.add("Player 1", 1).add("Player 2", 2).add("Player 3", 3).add("Player 5", 5)
|
176
|
+
assert_equal "Player 1", @table.the_button.player
|
177
|
+
end
|
178
|
+
|
179
|
+
test "should pass the buck to players in clockwise order" do
|
180
|
+
@table.add("Player 1", 1).add("Player 2", 2).add("Player 3", 3).add("Player 5", 5).add("Player 7", 7)
|
181
|
+
assert_equal "Player 1", @table.the_button.player
|
182
|
+
|
183
|
+
@table.pass_the_buck
|
184
|
+
assert_equal "Player 2", @table.the_button.player
|
185
|
+
|
186
|
+
@table.pass_the_buck
|
187
|
+
assert_equal "Player 3", @table.the_button.player
|
188
|
+
|
189
|
+
@table.pass_the_buck
|
190
|
+
assert_equal "Player 5", @table.the_button.player
|
191
|
+
|
192
|
+
@table.pass_the_buck
|
193
|
+
assert_equal "Player 7", @table.the_button.player
|
194
|
+
|
195
|
+
@table.pass_the_buck
|
196
|
+
assert_equal "Player 1", @table.the_button.player
|
197
|
+
|
198
|
+
@table.pass_the_buck
|
199
|
+
assert_equal "Player 2", @table.the_button.player
|
200
|
+
end
|
201
|
+
|
202
|
+
test "should return the seat containing the small blind" do
|
203
|
+
@table.add("Player 1", 1).add("Player 2", 2).add("Player 3", 3).add("Player 5", 5).add("Player 7", 7)
|
204
|
+
assert_equal "Player 2", @table.the_small_blind.player
|
205
|
+
|
206
|
+
@table.pass_the_buck
|
207
|
+
assert_equal "Player 3", @table.the_small_blind.player
|
208
|
+
end
|
209
|
+
|
210
|
+
test "the small blind should also be the button when there are only two players" do
|
211
|
+
@table.add("Player 1", 1).add("Player 2", 2)
|
212
|
+
assert_equal "Player 1", @table.the_button.player
|
213
|
+
assert_equal "Player 1", @table.the_small_blind.player
|
214
|
+
end
|
215
|
+
|
216
|
+
test "the small blind should also be the first to act when there are only two players" do
|
217
|
+
@table.add("Player 1", 1).add("Player 2", 2)
|
218
|
+
assert_equal "Player 1", @table.the_button.player
|
219
|
+
assert_equal "Player 1", @table.under_the_gun.player
|
220
|
+
end
|
221
|
+
|
222
|
+
test "should return the seat containing the big blind" do
|
223
|
+
@table.add("Player 1", 1).add("Player 2", 2).add("Player 3", 3).add("Player 5", 5).add("Player 7", 7)
|
224
|
+
assert_equal "Player 3", @table.the_big_blind.player
|
225
|
+
|
226
|
+
@table.pass_the_buck
|
227
|
+
assert_equal "Player 5", @table.the_big_blind.player
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
data/test/rora_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -28,13 +28,13 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.9.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: activesupport
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 3.
|
37
|
+
version: 3.2.3
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,39 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 3.
|
45
|
+
version: 3.2.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec-mocks
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.10.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.10.1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: test-unit
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.4.8
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.4.8
|
46
78
|
description: A Ruby library for conducting poker experiments and simulations
|
47
79
|
email: brandon@moralesce.com
|
48
80
|
executables: []
|
@@ -59,11 +91,13 @@ files:
|
|
59
91
|
- lib/rora/model/player.rb
|
60
92
|
- lib/rora/model/pot.rb
|
61
93
|
- lib/rora/model/rank.rb
|
94
|
+
- lib/rora/model/seat.rb
|
62
95
|
- lib/rora/model/starting_hand.rb
|
63
96
|
- lib/rora/model/suit.rb
|
64
97
|
- lib/rora/model/table.rb
|
65
98
|
- lib/rora/repository/hand_repository.rb
|
66
99
|
- lib/rora/repository/starting_hand_repository.rb
|
100
|
+
- lib/rora/utils/game_logger.rb
|
67
101
|
- lib/rora.rb
|
68
102
|
- LICENSE
|
69
103
|
- README.md
|
@@ -71,12 +105,16 @@ files:
|
|
71
105
|
- test/rora/model/board_test.rb
|
72
106
|
- test/rora/model/card_test.rb
|
73
107
|
- test/rora/model/deck_test.rb
|
108
|
+
- test/rora/model/game_test.rb
|
74
109
|
- test/rora/model/hand_test.rb
|
75
110
|
- test/rora/model/hand_type_test.rb
|
111
|
+
- test/rora/model/player_test.rb
|
76
112
|
- test/rora/model/pot_test.rb
|
77
113
|
- test/rora/model/rank_test.rb
|
114
|
+
- test/rora/model/seat_test.rb
|
78
115
|
- test/rora/model/starting_hand_test.rb
|
79
116
|
- test/rora/model/suit_test.rb
|
117
|
+
- test/rora/model/table_test.rb
|
80
118
|
- test/rora/repository/hand_repository_test.rb
|
81
119
|
- test/rora/repository/starting_hand_repository_test.rb
|
82
120
|
- test/rora_test.rb
|
@@ -100,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
138
|
version: '0'
|
101
139
|
requirements: []
|
102
140
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.8.
|
141
|
+
rubygems_version: 1.8.24
|
104
142
|
signing_key:
|
105
143
|
specification_version: 3
|
106
144
|
summary: A Ruby poker library
|
@@ -108,12 +146,16 @@ test_files:
|
|
108
146
|
- test/rora/model/board_test.rb
|
109
147
|
- test/rora/model/card_test.rb
|
110
148
|
- test/rora/model/deck_test.rb
|
149
|
+
- test/rora/model/game_test.rb
|
111
150
|
- test/rora/model/hand_test.rb
|
112
151
|
- test/rora/model/hand_type_test.rb
|
152
|
+
- test/rora/model/player_test.rb
|
113
153
|
- test/rora/model/pot_test.rb
|
114
154
|
- test/rora/model/rank_test.rb
|
155
|
+
- test/rora/model/seat_test.rb
|
115
156
|
- test/rora/model/starting_hand_test.rb
|
116
157
|
- test/rora/model/suit_test.rb
|
158
|
+
- test/rora/model/table_test.rb
|
117
159
|
- test/rora/repository/hand_repository_test.rb
|
118
160
|
- test/rora/repository/starting_hand_repository_test.rb
|
119
161
|
- test/rora_test.rb
|