rora 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +17 -0
- data/README.md +258 -0
- data/Rakefile +12 -0
- data/lib/rora/hands.csv +7462 -0
- data/lib/rora/model/board.rb +95 -0
- data/lib/rora/model/card.rb +74 -0
- data/lib/rora/model/deck.rb +109 -0
- data/lib/rora/model/game.rb +8 -0
- data/lib/rora/model/hand.rb +126 -0
- data/lib/rora/model/hand_type.rb +53 -0
- data/lib/rora/model/player.rb +8 -0
- data/lib/rora/model/pot.rb +21 -0
- data/lib/rora/model/rank.rb +52 -0
- data/lib/rora/model/starting_hand.rb +102 -0
- data/lib/rora/model/suit.rb +43 -0
- data/lib/rora/model/table.rb +40 -0
- data/lib/rora/repository/hand_repository.rb +133 -0
- data/lib/rora/repository/starting_hand_repository.rb +23 -0
- data/lib/rora.rb +12 -0
- data/test/rora/model/board_test.rb +137 -0
- data/test/rora/model/card_test.rb +57 -0
- data/test/rora/model/deck_test.rb +114 -0
- data/test/rora/model/hand_test.rb +91 -0
- data/test/rora/model/hand_type_test.rb +39 -0
- data/test/rora/model/pot_test.rb +28 -0
- data/test/rora/model/rank_test.rb +45 -0
- data/test/rora/model/starting_hand_test.rb +71 -0
- data/test/rora/model/suit_test.rb +45 -0
- data/test/rora/repository/hand_repository_test.rb +83 -0
- data/test/rora/repository/starting_hand_repository_test.rb +17 -0
- data/test/rora_test.rb +5 -0
- metadata +119 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path("../../rora_test", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class RankTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "should return all ranks" do
|
6
|
+
assert_equal(13, Rank.values.size)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should return the correct rank for the given key" do
|
10
|
+
assert_equal(Rank::TWO, Rank.get("2"))
|
11
|
+
assert_equal(Rank::THREE, Rank.get("3"))
|
12
|
+
assert_equal(Rank::FOUR, Rank.get("4"))
|
13
|
+
assert_equal(Rank::FIVE, Rank.get("5"))
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should perform a case insensitive key lookup" do
|
17
|
+
assert_equal(Rank::JACK, Rank.get("j"))
|
18
|
+
assert_equal(Rank::QUEEN, Rank.get("q"))
|
19
|
+
assert_equal(Rank::KING, Rank.get("k"))
|
20
|
+
assert_equal(Rank::ACE, Rank.get("a"))
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should raise an error when performing a lookup with an invalid key" do
|
24
|
+
assert_raise ArgumentError do
|
25
|
+
Rank.get("L")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test "should raise an error when performing a lookup with an empty key" do
|
30
|
+
assert_raise ArgumentError do
|
31
|
+
Rank.get("")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test "should raise an error when performing a lookup with a nil key" do
|
36
|
+
assert_raise TypeError do
|
37
|
+
Rank.get(nil)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test "should generate a readable string representation" do
|
42
|
+
assert_equal "Rank: id=41, key='A', value='Ace'", Rank::ACE.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path("../../rora_test", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class StartingHandTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@hand = StartingHand.new "ASKS"
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should raise an error when a starting hand is not created with 2 cards" do
|
10
|
+
assert_raise ArgumentError do
|
11
|
+
StartingHand.new [Card.new("AS"), Card.new("KS"), Card.new("QS")]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should raise an error when a starting hand is not created with 4 characters" do
|
16
|
+
assert_raise ArgumentError do
|
17
|
+
StartingHand.new "ASKSQSJS"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should raise an error when creating a starting hand with duplicate cards" do
|
22
|
+
assert_raise ArgumentError do
|
23
|
+
StartingHand.new "ASAS"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "the starting hand should not be suited" do
|
28
|
+
assert_equal false, StartingHand.new("JHTS").suited?
|
29
|
+
end
|
30
|
+
|
31
|
+
test "the starting hand should be suited" do
|
32
|
+
assert_equal true, StartingHand.new("JHTH").suited?
|
33
|
+
end
|
34
|
+
|
35
|
+
test "the starting hand should have a value" do
|
36
|
+
assert_equal "AS,KS", StartingHand.new("ASKS").value
|
37
|
+
end
|
38
|
+
|
39
|
+
test "the starting hand should have a short value" do
|
40
|
+
assert_equal "AKs", StartingHand.new("ASKS").short_value
|
41
|
+
end
|
42
|
+
|
43
|
+
test "the hand should have a pocket pair" do
|
44
|
+
assert_equal true, StartingHand.new("ASAH").pocket_pair?
|
45
|
+
end
|
46
|
+
|
47
|
+
test "the hand should not have a pocket pair" do
|
48
|
+
assert_equal false, StartingHand.new("ASKH").pocket_pair?
|
49
|
+
end
|
50
|
+
|
51
|
+
test "the starting hand should have an id that is equal to the product of the card ids" do
|
52
|
+
assert_equal StartingHand.new("ASKH").id, (Card.new("AS").id * Card.new("KH").id)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "the starting hand should have a key that is equal to the product of the card rank ids when the starting hand is unsuited" do
|
56
|
+
assert_equal StartingHand.new("ASKH").key, (Card.new("AS").rank.id * Card.new("KH").rank.id)
|
57
|
+
end
|
58
|
+
|
59
|
+
test "the starting hand should have a key that is equal to 67 times the product of the card rank ids when the starting hand is suited" do
|
60
|
+
assert_equal StartingHand.new("ASKS").key, (Card.new("AS").rank.id * Card.new("KS").rank.id * 67)
|
61
|
+
end
|
62
|
+
|
63
|
+
test "should return all starting hands" do
|
64
|
+
assert_equal 1326, StartingHand.all_starting_hands.size
|
65
|
+
end
|
66
|
+
|
67
|
+
test "should return distinct starting hands" do
|
68
|
+
assert_equal 169, StartingHand.distinct_starting_hands.size
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path("../../rora_test", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class SuitTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "should return all suits" do
|
6
|
+
assert_equal(4, Suit.values.size)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should return the correct suit for the given key" do
|
10
|
+
assert_equal(Suit::SPADE, Suit.get("S"))
|
11
|
+
assert_equal(Suit::HEART, Suit.get("H"))
|
12
|
+
assert_equal(Suit::DIAMOND, Suit.get("D"))
|
13
|
+
assert_equal(Suit::CLUB, Suit.get("C"))
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should perform a case insensitive key lookup" do
|
17
|
+
assert_equal(Suit::SPADE, Suit.get("s"))
|
18
|
+
assert_equal(Suit::DIAMOND, Suit.get("d"))
|
19
|
+
assert_equal(Suit::CLUB, Suit.get("c"))
|
20
|
+
assert_equal(Suit::HEART, Suit.get("h"))
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should raise an error when performing a lookup with an invalid key" do
|
24
|
+
assert_raise ArgumentError do
|
25
|
+
Suit.get("L")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test "should raise an error when performing a lookup with an empty key" do
|
30
|
+
assert_raise ArgumentError do
|
31
|
+
Suit.get("")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test "should raise an error when performing a lookup with a nil key" do
|
36
|
+
assert_raise TypeError do
|
37
|
+
Suit.get(nil)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test "should generate a readable string representation" do
|
42
|
+
assert_equal "Suit: id=47, key='S', value='Spade'", Suit::SPADE.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path("../../rora_test", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class HandRepositoyTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@repository = HandRepository.instance
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should be able to find a poker hand by id" do
|
10
|
+
result = @repository.find 2101589603
|
11
|
+
assert_equal 1, result[0]
|
12
|
+
assert_equal "SF", result[1]
|
13
|
+
assert_equal "Royal Flush", result[2]
|
14
|
+
assert_equal 0.0015, result[3]
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should raise an error when attempting to find a poker hand with an invalid id" do
|
18
|
+
assert_raise KeyError do
|
19
|
+
@repository.find 210158960345
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should return every poker hand" do
|
24
|
+
assert_equal 2598960, @repository.list.size
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should return every poker hand that can be made with the given starting hand" do
|
28
|
+
assert_equal 19600, @repository.list(:starting_hand => StartingHand.new("AS,KS")).size
|
29
|
+
end
|
30
|
+
|
31
|
+
test "should return every poker hand that can be made with the given starting hand and deck" do
|
32
|
+
deck = Deck.new.remove "AH,KH,AD,KD"
|
33
|
+
assert_equal 15180, @repository.list(:starting_hand => StartingHand.new("AS,KS"), :deck => deck).size
|
34
|
+
end
|
35
|
+
|
36
|
+
test "should return every poker hand that can be made with the given starting hand, flop, turn and river" do
|
37
|
+
assert_equal 21, @repository.list(:starting_hand => StartingHand.new("AS,KS"), :board => Board.new("QS,JS,TS,4H,3H")).size
|
38
|
+
end
|
39
|
+
|
40
|
+
test "should return every poker hand that can be made with the given starting hand, flop and turn" do
|
41
|
+
assert_equal 966, @repository.list(:starting_hand => StartingHand.new("AS,KS"), :board => Board.new("QS,JS,TS,4H")).size
|
42
|
+
end
|
43
|
+
|
44
|
+
test "should return every poker hand that can be made with the given starting hand and flop" do
|
45
|
+
assert_equal 22701, @repository.list(:starting_hand => StartingHand.new("AS,KS"), :board => Board.new("QS,JS,TS")).size
|
46
|
+
end
|
47
|
+
|
48
|
+
test "should return every poker hand that can be made with the given starting hand, flop and deck" do
|
49
|
+
deck = Deck.new.remove "AH,KH,AD,KD"
|
50
|
+
assert_equal 18963, @repository.list(:starting_hand => StartingHand.new("AS,KS"), :board => Board.new("QS,JS,TS"), :deck => deck).size
|
51
|
+
end
|
52
|
+
|
53
|
+
test "should return every distinct poker hand" do
|
54
|
+
assert_equal 7462, @repository.list_unique.size
|
55
|
+
end
|
56
|
+
|
57
|
+
test "should return every distinct poker hand that can be made with the given starting hand" do
|
58
|
+
assert_equal 620, @repository.list_unique(:starting_hand => StartingHand.new("AS,KS")).size
|
59
|
+
end
|
60
|
+
|
61
|
+
test "should return every distinct poker hand that can be made with the given starting hand and deck" do
|
62
|
+
deck = Deck.new.remove "AH,KH,AD,KD"
|
63
|
+
assert_equal 594, @repository.list_unique(:starting_hand => StartingHand.new("AS,KS"), :deck => deck).size
|
64
|
+
end
|
65
|
+
|
66
|
+
test "should return every distinct poker hand that can be made with the given starting hand, flop, turn and river" do
|
67
|
+
assert_equal 21, @repository.list_unique(:starting_hand => StartingHand.new("AS,KS"), :board => Board.new("QS,JS,TS,4H,3H")).size
|
68
|
+
end
|
69
|
+
|
70
|
+
test "should return every distinct poker hand that can be made with the given starting hand, flop and turn" do
|
71
|
+
assert_equal 212, @repository.list_unique(:starting_hand => StartingHand.new("AS,KS"), :board => Board.new("QS,JS,TS,4H")).size
|
72
|
+
end
|
73
|
+
|
74
|
+
test "should return every distinct poker hand that can be made with the given starting hand and flop" do
|
75
|
+
assert_equal 1042, @repository.list_unique(:starting_hand => StartingHand.new("AS,KS"), :board => Board.new("QS,JS,TS")).size
|
76
|
+
end
|
77
|
+
|
78
|
+
test "should return every distinct poker hand that can be made with the given starting hand, flop and deck" do
|
79
|
+
deck = Deck.new.remove "AH,KH,AD,KD"
|
80
|
+
assert_equal 1030, @repository.list_unique(:starting_hand => StartingHand.new("AS,KS"), :board => Board.new("QS,JS,TS"), :deck => deck).size
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path("../../rora_test", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class StartingHandRepositoyTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@repository = StartingHandRepository.instance
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should return all starting hands" do
|
10
|
+
assert_equal 1326, @repository.all_starting_hands.size
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should return distinct starting hands" do
|
14
|
+
assert_equal 169, @repository.distinct_starting_hands.size
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/test/rora_test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rora
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brandon John Grenier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: active_support
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.0.0
|
46
|
+
description: A Ruby library for conducting poker experiments and simulations
|
47
|
+
email: brandon@moralesce.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/rora/hands.csv
|
53
|
+
- lib/rora/model/board.rb
|
54
|
+
- lib/rora/model/card.rb
|
55
|
+
- lib/rora/model/deck.rb
|
56
|
+
- lib/rora/model/game.rb
|
57
|
+
- lib/rora/model/hand.rb
|
58
|
+
- lib/rora/model/hand_type.rb
|
59
|
+
- lib/rora/model/player.rb
|
60
|
+
- lib/rora/model/pot.rb
|
61
|
+
- lib/rora/model/rank.rb
|
62
|
+
- lib/rora/model/starting_hand.rb
|
63
|
+
- lib/rora/model/suit.rb
|
64
|
+
- lib/rora/model/table.rb
|
65
|
+
- lib/rora/repository/hand_repository.rb
|
66
|
+
- lib/rora/repository/starting_hand_repository.rb
|
67
|
+
- lib/rora.rb
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- test/rora/model/board_test.rb
|
72
|
+
- test/rora/model/card_test.rb
|
73
|
+
- test/rora/model/deck_test.rb
|
74
|
+
- test/rora/model/hand_test.rb
|
75
|
+
- test/rora/model/hand_type_test.rb
|
76
|
+
- test/rora/model/pot_test.rb
|
77
|
+
- test/rora/model/rank_test.rb
|
78
|
+
- test/rora/model/starting_hand_test.rb
|
79
|
+
- test/rora/model/suit_test.rb
|
80
|
+
- test/rora/repository/hand_repository_test.rb
|
81
|
+
- test/rora/repository/starting_hand_repository_test.rb
|
82
|
+
- test/rora_test.rb
|
83
|
+
homepage: http://www.moralesce.com
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.21
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: A Ruby poker library
|
107
|
+
test_files:
|
108
|
+
- test/rora/model/board_test.rb
|
109
|
+
- test/rora/model/card_test.rb
|
110
|
+
- test/rora/model/deck_test.rb
|
111
|
+
- test/rora/model/hand_test.rb
|
112
|
+
- test/rora/model/hand_type_test.rb
|
113
|
+
- test/rora/model/pot_test.rb
|
114
|
+
- test/rora/model/rank_test.rb
|
115
|
+
- test/rora/model/starting_hand_test.rb
|
116
|
+
- test/rora/model/suit_test.rb
|
117
|
+
- test/rora/repository/hand_repository_test.rb
|
118
|
+
- test/rora/repository/starting_hand_repository_test.rb
|
119
|
+
- test/rora_test.rb
|