danbarry-poker 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/card.rb +42 -0
- data/lib/deck.rb +25 -0
- data/lib/hand.rb +162 -0
- data/lib/poker.rb +3 -0
- data/spec/card_spec.rb +94 -0
- data/spec/deck_spec.rb +50 -0
- data/spec/hand_spec.rb +1049 -0
- data/spec/helper.rb +3 -0
- metadata +59 -0
data/lib/card.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Poker
|
2
|
+
class Card
|
3
|
+
include Comparable
|
4
|
+
|
5
|
+
SUITS = ['Spades', 'Diamonds', 'Clubs', 'Hearts']
|
6
|
+
VALUES = {
|
7
|
+
'Ace' => 14,
|
8
|
+
'King' => 13,
|
9
|
+
'Queen' => 12,
|
10
|
+
'Jack' => 11,
|
11
|
+
'10' => 10,
|
12
|
+
'9' => 9,
|
13
|
+
'8' => 8,
|
14
|
+
'7' => 7,
|
15
|
+
'6' => 6,
|
16
|
+
'5' => 5,
|
17
|
+
'4' => 4,
|
18
|
+
'3' => 3,
|
19
|
+
'2' => 2,
|
20
|
+
}
|
21
|
+
FACES = VALUES.keys
|
22
|
+
|
23
|
+
attr_reader :value, :suit
|
24
|
+
|
25
|
+
def initialize(suit, face_or_value)
|
26
|
+
self.suit = suit
|
27
|
+
self.value = VALUES[face_or_value] || face_or_value
|
28
|
+
raise ArgumentError unless SUITS.include?(suit) && VALUES.has_value?(value)
|
29
|
+
end
|
30
|
+
|
31
|
+
def face
|
32
|
+
VALUES.index(value)
|
33
|
+
end
|
34
|
+
|
35
|
+
def <=> other_card
|
36
|
+
value <=> other_card.value
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
attr_writer :value, :suit
|
41
|
+
end
|
42
|
+
end
|
data/lib/deck.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Poker
|
2
|
+
class Deck
|
3
|
+
attr_accessor :cards
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@cards = Card::SUITS.map do |suit|
|
7
|
+
Card::FACES.map do |value|
|
8
|
+
Card.new(suit, value)
|
9
|
+
end
|
10
|
+
end.flatten
|
11
|
+
@card_index = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def shuffle
|
15
|
+
@cards = @cards.sort_by {rand}
|
16
|
+
@card_index = 0
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def next(quantity = 1)
|
21
|
+
raise IndexError if @card_index + quantity > 52
|
22
|
+
@cards[@card_index...(@card_index += quantity)]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/hand.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
module Poker
|
2
|
+
class Hand
|
3
|
+
include Comparable
|
4
|
+
attr_reader :cards
|
5
|
+
|
6
|
+
def initialize(*hands_or_cards)
|
7
|
+
@cards = hands_or_cards.map do |hand_or_card|
|
8
|
+
if hand_or_card.is_a?(Hand)
|
9
|
+
hand_or_card.cards
|
10
|
+
else
|
11
|
+
hand_or_card
|
12
|
+
end
|
13
|
+
end.flatten.uniq.sort.reverse
|
14
|
+
end
|
15
|
+
|
16
|
+
def straight_flush?
|
17
|
+
@straight_flush ||= suited_cards.any? do |cards|
|
18
|
+
Hand.new(*cards).straight?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def quads?
|
23
|
+
@quads ||= matched_cards.any? do |cards|
|
24
|
+
cards.length >= 4
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def full_house?
|
29
|
+
@full_house ||= set? && two_pair?
|
30
|
+
end
|
31
|
+
|
32
|
+
def flush?
|
33
|
+
@flush ||= suited_cards.any? do |cards|
|
34
|
+
cards.length >= 5
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def straight?
|
39
|
+
@straight ||= !straight_cards.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def set?
|
43
|
+
@set ||= matched_cards.any? do |cards|
|
44
|
+
cards.length >= 3
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def two_pair?
|
49
|
+
@two_pair ||= matched_cards.length >= 2
|
50
|
+
end
|
51
|
+
|
52
|
+
def pair?
|
53
|
+
@pair ||= matched_cards.length >= 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def four_to_flush?
|
57
|
+
@four_to_flush ||= suited_cards.any? do |cards|
|
58
|
+
cards.length >= 4
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def open_ended?
|
63
|
+
@open_ended ||= straight_cards(4).any? do |cards|
|
64
|
+
cards.first.face != 'Ace' && cards.last.face != 'Ace'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def gutshot?
|
69
|
+
@gutshot ||= !gutshot_cards.empty?
|
70
|
+
end
|
71
|
+
|
72
|
+
def double_gutshot?
|
73
|
+
@double_gutshot ||= gutshot_cards.length >= 2
|
74
|
+
end
|
75
|
+
|
76
|
+
def <=> other_hand
|
77
|
+
return rank <=> other_hand.rank unless rank == other_hand.rank
|
78
|
+
return 0 if tie_breaker == other_hand.tie_breaker
|
79
|
+
tie_breaker.each_with_index do |card, i|
|
80
|
+
compared = card.value <=> other_hand.tie_breaker[i].value
|
81
|
+
return compared unless compared == 0
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
def rank
|
87
|
+
@rank ||= if straight_flush?: 8
|
88
|
+
elsif quads?: 7
|
89
|
+
elsif full_house?: 6
|
90
|
+
elsif flush?: 5
|
91
|
+
elsif straight?: 4
|
92
|
+
elsif set?: 3
|
93
|
+
elsif two_pair?: 2
|
94
|
+
elsif pair?: 1
|
95
|
+
else; 0
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def tie_breaker
|
100
|
+
@tie_breaker ||= if flush?
|
101
|
+
Hand.new(*suited_cards.find{|cards| cards.length >= 5}).unsuited!.tie_breaker
|
102
|
+
elsif quads?
|
103
|
+
quads = matched_cards.find{|cards| cards.length == 4}
|
104
|
+
quads + [(@cards - quads).first]
|
105
|
+
elsif full_house?
|
106
|
+
set = matched_cards.find{|cards| cards.length == 3}
|
107
|
+
set + (matched_cards - [set]).first.first(2)
|
108
|
+
elsif straight?
|
109
|
+
[straight_cards.last.last]
|
110
|
+
elsif set?
|
111
|
+
set = matched_cards.first
|
112
|
+
set + (@cards - set).first(2)
|
113
|
+
elsif two_pair?
|
114
|
+
two_pair = matched_cards.first(2).flatten
|
115
|
+
two_pair + [(@cards - two_pair).first]
|
116
|
+
elsif pair?
|
117
|
+
pair = matched_cards.first
|
118
|
+
pair + (@cards - pair).first(3)
|
119
|
+
else
|
120
|
+
@cards.first(5)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def unsuited!
|
125
|
+
@suited_cards = []
|
126
|
+
self
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
def matched_cards
|
131
|
+
@matched_cards ||= @cards.map{|card| card.value}.uniq.map do |value|
|
132
|
+
cards = @cards.select{|card| card.value == value}
|
133
|
+
cards.length > 1 ? cards : nil
|
134
|
+
end.compact
|
135
|
+
end
|
136
|
+
|
137
|
+
def suited_cards
|
138
|
+
@suited_cards ||= @cards.map{|card| card.suit}.uniq.map do |suit|
|
139
|
+
@cards.select{|card| card.suit == suit}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def straight_cards(length = 5)
|
144
|
+
@straight_cards ||= {}
|
145
|
+
@straight_cards[length] ||= (1..14-(length-1)).map do |low| # straight can start at a low ace up to a 10
|
146
|
+
high = low + (length - 1)
|
147
|
+
cards = (low..high).map do |value|
|
148
|
+
@cards.find{|card| card.value % 13 == value % 13} # %13 allows an ace to be high or low
|
149
|
+
end.compact
|
150
|
+
end.select{|cards| cards.length == length}
|
151
|
+
end
|
152
|
+
|
153
|
+
def gutshot_cards
|
154
|
+
@gutshot_cards ||= (1..10).map do |low|
|
155
|
+
high = low + 4
|
156
|
+
(low..high).reject do |value|
|
157
|
+
@cards.find{|card| card.value % 13 == value % 13}
|
158
|
+
end
|
159
|
+
end.reject{|cards| cards.length != 1}.uniq.flatten
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
data/lib/poker.rb
ADDED
data/spec/card_spec.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
module Poker
|
4
|
+
describe Card, '#new' do
|
5
|
+
it 'should accept the four suits' do
|
6
|
+
lambda {
|
7
|
+
['Spades', 'Diamonds', 'Clubs', 'Hearts'].each do |suit|
|
8
|
+
Card.new(suit, 'Ace')
|
9
|
+
end
|
10
|
+
}.should_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should reject unknown suits' do
|
14
|
+
lambda { Card.new('Rubies', 'Ace') }.should raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should accept a string of a card name' do
|
18
|
+
lambda {
|
19
|
+
Card.new('Spades', 'Ace')
|
20
|
+
Card.new('Spades', 'King')
|
21
|
+
Card.new('Spades', 'Queen')
|
22
|
+
Card.new('Spades', 'Jack')
|
23
|
+
(2..10).each do |value|
|
24
|
+
Card.new('Spades', value.to_s)
|
25
|
+
end
|
26
|
+
}.should_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should reject unknown card names' do
|
30
|
+
lambda { Card.new('Spades', '1') }.should raise_error(ArgumentError)
|
31
|
+
lambda { Card.new('Spades', '11') }.should raise_error(ArgumentError)
|
32
|
+
lambda { Card.new('Spades', 'Joker') }.should raise_error(ArgumentError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should accept card values' do
|
36
|
+
lambda {
|
37
|
+
(2..14).each do |value|
|
38
|
+
Card.new('Spades', value)
|
39
|
+
end
|
40
|
+
}.should_not raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should consider cards made by face and value the same' do
|
44
|
+
Card.new('Spades', 'Ace').should == Card.new('Spades', 14)
|
45
|
+
Card.new('Spades', 'King').should == Card.new('Spades', 13)
|
46
|
+
Card.new('Spades', 'Queen').should == Card.new('Spades', 12)
|
47
|
+
Card.new('Spades', 'Jack').should == Card.new('Spades', 11)
|
48
|
+
(2..10).each do |value|
|
49
|
+
Card.new('Spades', value.to_s).should == Card.new('Spades', value)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should reject values outside the range' do
|
54
|
+
lambda { Card.new('Spades', 1) }.should raise_error(ArgumentError)
|
55
|
+
lambda { Card.new('Spades', 15) }.should raise_error(ArgumentError)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe Card, '#face' do
|
60
|
+
it 'should return the face for that card' do
|
61
|
+
Card.new('Spades', 'Ace').face.should == 'Ace'
|
62
|
+
Card.new('Spades', 'King').face.should == 'King'
|
63
|
+
Card.new('Spades', 'Queen').face.should == 'Queen'
|
64
|
+
Card.new('Spades', 'Jack').face.should == 'Jack'
|
65
|
+
(2..10).each do |value|
|
66
|
+
Card.new('Spades', value).face.should == value.to_s
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe Card, '#value' do
|
72
|
+
it 'should return the value for that card' do
|
73
|
+
Card.new('Spades', 'Ace').value.should == 14
|
74
|
+
Card.new('Spades', 'King').value.should == 13
|
75
|
+
Card.new('Spades', 'Queen').value.should == 12
|
76
|
+
Card.new('Spades', 'Jack').value.should == 11
|
77
|
+
(2..10).each do |value|
|
78
|
+
Card.new('Spades', value).value.should == value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe Card, '#<=>' do
|
84
|
+
it 'should order the cards by value' do
|
85
|
+
Card.new('Spades', 'Ace').should > Card.new('Spades', 'King')
|
86
|
+
Card.new('Spades', 'King').should > Card.new('Spades', 'Queen')
|
87
|
+
Card.new('Spades', 'Queen').should > Card.new('Spades', 'Jack')
|
88
|
+
Card.new('Spades', 'Jack').should > Card.new('Spades', '10')
|
89
|
+
(2..9).each do |value|
|
90
|
+
Card.new('Spades', value+1).should > Card.new('Spades', value)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/spec/deck_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
module Poker
|
4
|
+
describe Deck, '#next' do
|
5
|
+
it 'should give you the number of cards you ask for' do
|
6
|
+
count = rand 10
|
7
|
+
Deck.new.next(count).length.should == count
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should give 1 card by default' do
|
11
|
+
Deck.new.next.length.should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should not give out the same card twice' do
|
15
|
+
Deck.new.next(52).uniq.length.should == 52
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not give out the same card(s) on subsequent calls' do
|
19
|
+
deck = Deck.new
|
20
|
+
count = rand(10)+1
|
21
|
+
deck.next(count).should_not == deck.next(count)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should eventually run out of cards' do
|
25
|
+
lambda {
|
26
|
+
Deck.new.next(53)
|
27
|
+
}.should raise_error(IndexError)
|
28
|
+
lambda {
|
29
|
+
deck = Deck.new
|
30
|
+
deck.next 40
|
31
|
+
deck.next 13
|
32
|
+
}.should raise_error(IndexError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Deck, '#shuffle' do
|
37
|
+
it 'should allow you to take out more cards' do
|
38
|
+
deck = Deck.new
|
39
|
+
deck.next 52
|
40
|
+
lambda {
|
41
|
+
deck.shuffle.next 52
|
42
|
+
}.should_not raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should change the order of the cards' do
|
46
|
+
deck = Deck.new
|
47
|
+
deck.next(52).should_not == deck.shuffle.next(52)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/hand_spec.rb
ADDED
@@ -0,0 +1,1049 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
module Poker
|
4
|
+
describe Hand, '#new' do
|
5
|
+
before do
|
6
|
+
@cards = [
|
7
|
+
Card.new('Hearts', '6'),
|
8
|
+
Card.new('Spades', 'Queen'),
|
9
|
+
Card.new('Diamonds', '4'),
|
10
|
+
Card.new('Clubs', '7'),
|
11
|
+
Card.new('Diamonds', 'Jack'),
|
12
|
+
Card.new('Spades', '8')
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should contain the given cards' do
|
17
|
+
Hand.new(*@cards).cards.sort.should == @cards.sort
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should contain the cards in any given hands' do
|
21
|
+
Hand.new(Hand.new(*@cards[0..2]), Hand.new(*@cards[3..5])).cards.sort.should == @cards.sort
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should accept a combination of hands and cards' do
|
25
|
+
Hand.new(Hand.new(*@cards[0..2]), *@cards[3..5]).cards.sort.should == @cards.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should ignore the same card if given twice' do
|
29
|
+
Hand.new(@cards[3], *@cards).cards.sort.should == @cards.sort
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should ignore the same card if given in two hands' do
|
33
|
+
Hand.new(Hand.new(*@cards[0..3]), Hand.new(*@cards[2..5])).cards.sort.should == @cards.sort
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should ignore the same card if given in a combo of cards and hands' do
|
37
|
+
Hand.new(Hand.new(*@cards[0..3]), *@cards[2..5]).cards.sort.should == @cards.sort
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe Hand do
|
42
|
+
before do
|
43
|
+
@straight_flush = Hand.new(
|
44
|
+
Card.new('Spades', '6'),
|
45
|
+
Card.new('Spades', '5'),
|
46
|
+
Card.new('Spades', '9'),
|
47
|
+
Card.new('Spades', '7'),
|
48
|
+
Card.new('Spades', '8')
|
49
|
+
)
|
50
|
+
@quads = Hand.new(
|
51
|
+
Card.new('Hearts', '6'),
|
52
|
+
Card.new('Spades', '6'),
|
53
|
+
Card.new('Clubs', '6'),
|
54
|
+
Card.new('Spades', '7'),
|
55
|
+
Card.new('Diamonds', '6')
|
56
|
+
)
|
57
|
+
@full_house = Hand.new(
|
58
|
+
Card.new('Spades', '6'),
|
59
|
+
Card.new('Hearts', '6'),
|
60
|
+
Card.new('Diamonds', '6'),
|
61
|
+
Card.new('Spades', '7'),
|
62
|
+
Card.new('Clubs', '7')
|
63
|
+
)
|
64
|
+
@flush = Hand.new(
|
65
|
+
Card.new('Spades', '6'),
|
66
|
+
Card.new('Spades', 'Queen'),
|
67
|
+
Card.new('Spades', '3'),
|
68
|
+
Card.new('Spades', '7'),
|
69
|
+
Card.new('Spades', '8')
|
70
|
+
)
|
71
|
+
@straight = Hand.new(
|
72
|
+
Card.new('Spades', '6'),
|
73
|
+
Card.new('Clubs', '5'),
|
74
|
+
Card.new('Spades', '9'),
|
75
|
+
Card.new('Diamonds', '7'),
|
76
|
+
Card.new('Hearts', '8')
|
77
|
+
)
|
78
|
+
@set = Hand.new(
|
79
|
+
Card.new('Spades', '6'),
|
80
|
+
Card.new('Hearts', '6'),
|
81
|
+
Card.new('Spades', '9'),
|
82
|
+
Card.new('Clubs', '6'),
|
83
|
+
Card.new('Diamonds', '8')
|
84
|
+
)
|
85
|
+
@two_pair = Hand.new(
|
86
|
+
Card.new('Spades', '6'),
|
87
|
+
Card.new('Hearts', '5'),
|
88
|
+
Card.new('Clubs', '6'),
|
89
|
+
Card.new('Diamonds', '5'),
|
90
|
+
Card.new('Spades', '8')
|
91
|
+
)
|
92
|
+
@pair = Hand.new(
|
93
|
+
Card.new('Hearts', '6'),
|
94
|
+
Card.new('Spades', '5'),
|
95
|
+
Card.new('Clubs', '8'),
|
96
|
+
Card.new('Diamonds', '7'),
|
97
|
+
Card.new('Spades', '8')
|
98
|
+
)
|
99
|
+
@high_card = Hand.new(
|
100
|
+
Card.new('Hearts', '6'),
|
101
|
+
Card.new('Spades', 'Queen'),
|
102
|
+
Card.new('Diamonds', '4'),
|
103
|
+
Card.new('Clubs', '7'),
|
104
|
+
Card.new('Diamonds', 'Jack')
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'straight flush' do
|
109
|
+
it 'should be a straight flush' do
|
110
|
+
@straight_flush.should be_straight_flush
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should be a flush' do
|
114
|
+
@straight_flush.should be_flush
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should be a straight' do
|
118
|
+
@straight_flush.should be_straight
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should not be anything else' do
|
122
|
+
@straight_flush.should_not be_pair
|
123
|
+
@straight_flush.should_not be_two_pair
|
124
|
+
@straight_flush.should_not be_set
|
125
|
+
@straight_flush.should_not be_full_house
|
126
|
+
@straight_flush.should_not be_quads
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'wheel' do
|
130
|
+
it 'should be a straight flush' do
|
131
|
+
Hand.new(
|
132
|
+
Card.new('Spades', 'Ace'),
|
133
|
+
Card.new('Spades', '2'),
|
134
|
+
Card.new('Spades', '3'),
|
135
|
+
Card.new('Spades', '4'),
|
136
|
+
Card.new('Spades', '5')
|
137
|
+
).should be_straight_flush
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'quads' do
|
143
|
+
it 'should be quads' do
|
144
|
+
@quads.should be_quads
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should be a set' do
|
148
|
+
@quads.should be_set
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should be a pair' do
|
152
|
+
@quads.should be_set
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should not be anything else' do
|
156
|
+
@quads.should_not be_two_pair
|
157
|
+
@quads.should_not be_straight
|
158
|
+
@quads.should_not be_flush
|
159
|
+
@quads.should_not be_full_house
|
160
|
+
@quads.should_not be_straight_flush
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe 'full house' do
|
165
|
+
it 'should be a full house' do
|
166
|
+
@full_house.should be_full_house
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should be a set' do
|
170
|
+
@full_house.should be_set
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should be two pair' do
|
174
|
+
@full_house.should be_two_pair
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should be a pair' do
|
178
|
+
@full_house.should be_pair
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should not be anything else' do
|
182
|
+
@full_house.should_not be_straight
|
183
|
+
@full_house.should_not be_flush
|
184
|
+
@full_house.should_not be_quads
|
185
|
+
@full_house.should_not be_straight_flush
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe 'flush' do
|
190
|
+
it 'should be a flush' do
|
191
|
+
@flush.should be_flush
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should not be anything else' do
|
195
|
+
@flush.should_not be_pair
|
196
|
+
@flush.should_not be_two_pair
|
197
|
+
@flush.should_not be_set
|
198
|
+
@flush.should_not be_straight
|
199
|
+
@flush.should_not be_full_house
|
200
|
+
@flush.should_not be_quads
|
201
|
+
@flush.should_not be_straight_flush
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe 'straight' do
|
206
|
+
it 'should be a straight' do
|
207
|
+
@straight.should be_straight
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should not be anything else' do
|
211
|
+
@straight.should_not be_pair
|
212
|
+
@straight.should_not be_two_pair
|
213
|
+
@straight.should_not be_set
|
214
|
+
@straight.should_not be_flush
|
215
|
+
@straight.should_not be_full_house
|
216
|
+
@straight.should_not be_quads
|
217
|
+
@straight.should_not be_straight_flush
|
218
|
+
end
|
219
|
+
|
220
|
+
describe 'wheel' do
|
221
|
+
it 'should be a straight' do
|
222
|
+
Hand.new(
|
223
|
+
Card.new('Spades', 'Ace'),
|
224
|
+
Card.new('Clubs', '2'),
|
225
|
+
Card.new('Spades', '3'),
|
226
|
+
Card.new('Hearts', '4'),
|
227
|
+
Card.new('Diamonds', '5')
|
228
|
+
).should be_straight
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe 'set' do
|
234
|
+
it 'should be a set' do
|
235
|
+
@set.should be_set
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'should be a pair' do
|
239
|
+
@set.should be_pair
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should not be anything else' do
|
243
|
+
@set.should_not be_two_pair
|
244
|
+
@set.should_not be_straight
|
245
|
+
@set.should_not be_flush
|
246
|
+
@set.should_not be_full_house
|
247
|
+
@set.should_not be_quads
|
248
|
+
@set.should_not be_straight_flush
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe 'two pair' do
|
253
|
+
it 'should be two pair' do
|
254
|
+
@two_pair.should be_two_pair
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'should be a pair' do
|
258
|
+
@two_pair.should be_pair
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should not be anything else' do
|
262
|
+
@two_pair.should_not be_set
|
263
|
+
@two_pair.should_not be_straight
|
264
|
+
@two_pair.should_not be_flush
|
265
|
+
@two_pair.should_not be_full_house
|
266
|
+
@two_pair.should_not be_quads
|
267
|
+
@two_pair.should_not be_straight_flush
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe 'pair' do
|
272
|
+
it 'should be a pair' do
|
273
|
+
@pair.should be_pair
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'should not be anything else' do
|
277
|
+
@pair.should_not be_two_pair
|
278
|
+
@pair.should_not be_set
|
279
|
+
@pair.should_not be_straight
|
280
|
+
@pair.should_not be_flush
|
281
|
+
@pair.should_not be_full_house
|
282
|
+
@pair.should_not be_quads
|
283
|
+
@pair.should_not be_full_house
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
describe 'high card' do
|
288
|
+
it 'should not be anything else' do
|
289
|
+
@high_card.should_not be_pair
|
290
|
+
@high_card.should_not be_two_pair
|
291
|
+
@high_card.should_not be_set
|
292
|
+
@high_card.should_not be_straight
|
293
|
+
@high_card.should_not be_flush
|
294
|
+
@high_card.should_not be_full_house
|
295
|
+
@high_card.should_not be_quads
|
296
|
+
@high_card.should_not be_straight_flush
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe 'straight and flush' do
|
301
|
+
before do
|
302
|
+
@straight_and_flush = Hand.new(
|
303
|
+
Card.new('Spades', 'Ace'),
|
304
|
+
Card.new('Spades', '10'),
|
305
|
+
Card.new('Spades', '9'),
|
306
|
+
Card.new('Clubs', '8'),
|
307
|
+
Card.new('Spades', '7'),
|
308
|
+
Card.new('Spades', '6')
|
309
|
+
)
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'should be a straight' do
|
313
|
+
@straight_and_flush.should be_straight
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should be a flush' do
|
317
|
+
@straight_and_flush.should be_flush
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'should not be a straight flush' do
|
321
|
+
@straight_and_flush.should_not be_straight_flush
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
describe 'four to flush' do
|
326
|
+
before do
|
327
|
+
@four_to_flush = Hand.new(
|
328
|
+
Card.new('Spades', 'Ace'),
|
329
|
+
Card.new('Spades', '10'),
|
330
|
+
Card.new('Clubs', '8'),
|
331
|
+
Card.new('Spades', '7'),
|
332
|
+
Card.new('Spades', '6')
|
333
|
+
)
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'should be four to a flush' do
|
337
|
+
@four_to_flush.should be_four_to_flush
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'should not be a flush' do
|
341
|
+
@four_to_flush.should_not be_flush
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
describe 'open ended' do
|
346
|
+
before do
|
347
|
+
@open_ended = Hand.new(
|
348
|
+
Card.new('Spades', 'Ace'),
|
349
|
+
Card.new('Spades', '9'),
|
350
|
+
Card.new('Clubs', '8'),
|
351
|
+
Card.new('Spades', '7'),
|
352
|
+
Card.new('Spades', '6')
|
353
|
+
)
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'should be open ended' do
|
357
|
+
@open_ended.should be_open_ended
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'should not be a straight' do
|
361
|
+
@open_ended.should_not be_straight
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'should not include Ace through 4' do
|
365
|
+
Hand.new(
|
366
|
+
Card.new('Spades', 'Ace'),
|
367
|
+
Card.new('Clubs', '2'),
|
368
|
+
Card.new('Spades', '3'),
|
369
|
+
Card.new('Hearts', '4'),
|
370
|
+
Card.new('Diamonds', '8')
|
371
|
+
).should_not be_open_ended
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'should not include Jack through Ace' do
|
375
|
+
Hand.new(
|
376
|
+
Card.new('Spades', 'Ace'),
|
377
|
+
Card.new('Clubs', 'King'),
|
378
|
+
Card.new('Spades', 'Queen'),
|
379
|
+
Card.new('Hearts', 'Jack'),
|
380
|
+
Card.new('Diamonds', '8')
|
381
|
+
).should_not be_open_ended
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
describe 'gutshot' do
|
386
|
+
it 'should include 1-card gaps between 1 card and 3 others' do
|
387
|
+
Hand.new(
|
388
|
+
Card.new('Spades', 'Jack'),
|
389
|
+
Card.new('Clubs', '2'),
|
390
|
+
Card.new('Spades', '5'),
|
391
|
+
Card.new('Hearts', '4'),
|
392
|
+
Card.new('Diamonds', '6')
|
393
|
+
).should be_gutshot
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'should include 1-card gaps between 2 cards and 2 others' do
|
397
|
+
Hand.new(
|
398
|
+
Card.new('Spades', 'Jack'),
|
399
|
+
Card.new('Clubs', '2'),
|
400
|
+
Card.new('Spades', '5'),
|
401
|
+
Card.new('Hearts', '3'),
|
402
|
+
Card.new('Diamonds', '6')
|
403
|
+
).should be_gutshot
|
404
|
+
end
|
405
|
+
|
406
|
+
it 'should include 1-card gaps between 3 cards and 1 other' do
|
407
|
+
Hand.new(
|
408
|
+
Card.new('Spades', 'Jack'),
|
409
|
+
Card.new('Clubs', '2'),
|
410
|
+
Card.new('Spades', '3'),
|
411
|
+
Card.new('Hearts', '4'),
|
412
|
+
Card.new('Diamonds', '6')
|
413
|
+
).should be_gutshot
|
414
|
+
end
|
415
|
+
|
416
|
+
it 'should include Ace through 4' do
|
417
|
+
Hand.new(
|
418
|
+
Card.new('Spades', 'Ace'),
|
419
|
+
Card.new('Clubs', '2'),
|
420
|
+
Card.new('Spades', '3'),
|
421
|
+
Card.new('Hearts', '4'),
|
422
|
+
Card.new('Diamonds', '8')
|
423
|
+
).should be_gutshot
|
424
|
+
end
|
425
|
+
|
426
|
+
it 'should include Jack through Ace' do
|
427
|
+
Hand.new(
|
428
|
+
Card.new('Spades', 'Ace'),
|
429
|
+
Card.new('Clubs', 'King'),
|
430
|
+
Card.new('Spades', 'Queen'),
|
431
|
+
Card.new('Hearts', 'Jack'),
|
432
|
+
Card.new('Diamonds', '8')
|
433
|
+
).should be_gutshot
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
describe 'double gutshot' do
|
438
|
+
it 'should include 2 1-card gaps between 1, 3, and 1 cards' do
|
439
|
+
Hand.new(
|
440
|
+
Card.new('Spades', '4'),
|
441
|
+
Card.new('Clubs', '6'),
|
442
|
+
Card.new('Spades', '7'),
|
443
|
+
Card.new('Hearts', '8'),
|
444
|
+
Card.new('Diamonds', '10')
|
445
|
+
).should be_double_gutshot
|
446
|
+
end
|
447
|
+
|
448
|
+
it 'should include 2 1-card gaps between 2, 2, and 2 cards' do
|
449
|
+
Hand.new(
|
450
|
+
Card.new('Spades', '4'),
|
451
|
+
Card.new('Clubs', '5'),
|
452
|
+
Card.new('Spades', '7'),
|
453
|
+
Card.new('Hearts', '8'),
|
454
|
+
Card.new('Diamonds', '10'),
|
455
|
+
Card.new('Hearts', 'Jack')
|
456
|
+
).should be_double_gutshot
|
457
|
+
end
|
458
|
+
|
459
|
+
it 'should include 2 1-card gaps between 3, 1, and 3 cards' do
|
460
|
+
Hand.new(
|
461
|
+
Card.new('Spades', '4'),
|
462
|
+
Card.new('Clubs', '5'),
|
463
|
+
Card.new('Spades', '6'),
|
464
|
+
Card.new('Hearts', '8'),
|
465
|
+
Card.new('Diamonds', '10'),
|
466
|
+
Card.new('Hearts', 'Jack'),
|
467
|
+
Card.new('Clubs', 'Queen')
|
468
|
+
).should be_double_gutshot
|
469
|
+
end
|
470
|
+
|
471
|
+
it 'should not include 2-card gaps between 2 cards and 3 cards' do
|
472
|
+
Hand.new(
|
473
|
+
Card.new('Spades', '4'),
|
474
|
+
Card.new('Clubs', '5'),
|
475
|
+
Card.new('Spades', '8'),
|
476
|
+
Card.new('Hearts', '9'),
|
477
|
+
Card.new('Diamonds', '10')
|
478
|
+
).should_not be_double_gutshot
|
479
|
+
end
|
480
|
+
|
481
|
+
it 'should not include 2-card gaps between 3 cards and 2 cards' do
|
482
|
+
Hand.new(
|
483
|
+
Card.new('Spades', '4'),
|
484
|
+
Card.new('Clubs', '5'),
|
485
|
+
Card.new('Spades', '6'),
|
486
|
+
Card.new('Hearts', '9'),
|
487
|
+
Card.new('Diamonds', '10')
|
488
|
+
).should_not be_double_gutshot
|
489
|
+
end
|
490
|
+
|
491
|
+
it 'should not include 1-card gaps between 3 cards and 3 cards' do
|
492
|
+
Hand.new(
|
493
|
+
Card.new('Spades', '4'),
|
494
|
+
Card.new('Clubs', '5'),
|
495
|
+
Card.new('Spades', '6'),
|
496
|
+
Card.new('Clubs', '8'),
|
497
|
+
Card.new('Hearts', '9'),
|
498
|
+
Card.new('Diamonds', '10')
|
499
|
+
).should_not be_double_gutshot
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
describe 'rankings' do
|
504
|
+
before do
|
505
|
+
@highest_quads = Hand.new(
|
506
|
+
Card.new('Clubs', 'Ace'),
|
507
|
+
Card.new('Hearts', 'Ace'),
|
508
|
+
Card.new('Spades', 'Ace'),
|
509
|
+
Card.new('Diamonds', 'Ace'),
|
510
|
+
Card.new('Hearts', 'King')
|
511
|
+
)
|
512
|
+
@highest_full_house = Hand.new(
|
513
|
+
Card.new('Clubs', 'Ace'),
|
514
|
+
Card.new('Hearts', 'Ace'),
|
515
|
+
Card.new('Spades', 'Ace'),
|
516
|
+
Card.new('Diamonds', 'King'),
|
517
|
+
Card.new('Hearts', 'King')
|
518
|
+
)
|
519
|
+
@highest_flush = Hand.new(
|
520
|
+
Card.new('Clubs', 'Ace'),
|
521
|
+
Card.new('Clubs', 'King'),
|
522
|
+
Card.new('Clubs', 'Queen'),
|
523
|
+
Card.new('Clubs', 'Jack'),
|
524
|
+
Card.new('Clubs', '9')
|
525
|
+
)
|
526
|
+
@highest_straight = Hand.new(
|
527
|
+
Card.new('Clubs', 'Ace'),
|
528
|
+
Card.new('Hearts', 'King'),
|
529
|
+
Card.new('Spades', 'Queen'),
|
530
|
+
Card.new('Diamonds', 'Jack'),
|
531
|
+
Card.new('Hearts', '10')
|
532
|
+
)
|
533
|
+
@highest_set = Hand.new(
|
534
|
+
Card.new('Clubs', 'Ace'),
|
535
|
+
Card.new('Hearts', 'Ace'),
|
536
|
+
Card.new('Spades', 'Ace'),
|
537
|
+
Card.new('Diamonds', 'King'),
|
538
|
+
Card.new('Hearts', 'Queen')
|
539
|
+
)
|
540
|
+
@highest_two_pair = Hand.new(
|
541
|
+
Card.new('Clubs', 'Ace'),
|
542
|
+
Card.new('Hearts', 'Ace'),
|
543
|
+
Card.new('Spades', 'King'),
|
544
|
+
Card.new('Diamonds', 'King'),
|
545
|
+
Card.new('Hearts', 'Queen')
|
546
|
+
)
|
547
|
+
@highest_pair = Hand.new(
|
548
|
+
Card.new('Hearts', 'Ace'),
|
549
|
+
Card.new('Diamonds', 'Ace'),
|
550
|
+
Card.new('Spades', 'King'),
|
551
|
+
Card.new('Diamonds', 'Queen'),
|
552
|
+
Card.new('Clubs', 'Jack')
|
553
|
+
)
|
554
|
+
@highest_high_card = Hand.new(
|
555
|
+
Card.new('Hearts', 'Ace'),
|
556
|
+
Card.new('Spades', 'King'),
|
557
|
+
Card.new('Diamonds', 'Queen'),
|
558
|
+
Card.new('Clubs', 'Jack'),
|
559
|
+
Card.new('Diamonds', '9')
|
560
|
+
)
|
561
|
+
end
|
562
|
+
|
563
|
+
describe 'straight flush' do
|
564
|
+
before do
|
565
|
+
@highest_straight_flush = Hand.new(
|
566
|
+
Card.new('Clubs', 'Ace'),
|
567
|
+
Card.new('Clubs', 'King'),
|
568
|
+
Card.new('Clubs', 'Queen'),
|
569
|
+
Card.new('Clubs', 'Jack'),
|
570
|
+
Card.new('Clubs', '10')
|
571
|
+
)
|
572
|
+
@lowest_straight_flush = Hand.new(
|
573
|
+
Card.new('Clubs', 'Ace'),
|
574
|
+
Card.new('Clubs', '2'),
|
575
|
+
Card.new('Clubs', '3'),
|
576
|
+
Card.new('Clubs', '4'),
|
577
|
+
Card.new('Clubs', '5')
|
578
|
+
)
|
579
|
+
end
|
580
|
+
|
581
|
+
it 'should beat a smaller straight flush' do
|
582
|
+
@highest_straight_flush.should > @straight_flush
|
583
|
+
@straight_flush.should > @lowest_straight_flush
|
584
|
+
end
|
585
|
+
|
586
|
+
it 'should beat any quads' do
|
587
|
+
@lowest_straight_flush.should > @highest_quads
|
588
|
+
end
|
589
|
+
|
590
|
+
it 'should beat any full house' do
|
591
|
+
@lowest_straight_flush.should > @highest_full_house
|
592
|
+
end
|
593
|
+
|
594
|
+
it 'should beat any flush' do
|
595
|
+
@lowest_straight_flush.should > @highest_flush
|
596
|
+
end
|
597
|
+
|
598
|
+
it 'should beat any straight' do
|
599
|
+
@lowest_straight_flush.should > @highest_straight
|
600
|
+
end
|
601
|
+
|
602
|
+
it 'should beat any set' do
|
603
|
+
@lowest_straight_flush.should > @highest_set
|
604
|
+
end
|
605
|
+
|
606
|
+
it 'should beat any two pair' do
|
607
|
+
@lowest_straight_flush.should > @highest_two_pair
|
608
|
+
end
|
609
|
+
|
610
|
+
it 'should beat any pair' do
|
611
|
+
@lowest_straight_flush.should > @highest_pair
|
612
|
+
end
|
613
|
+
|
614
|
+
it 'should beat any high card' do
|
615
|
+
@lowest_straight_flush.should > @highest_high_card
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
619
|
+
describe 'quads' do
|
620
|
+
before do
|
621
|
+
@lowest_quads = Hand.new(
|
622
|
+
Card.new('Clubs', '2'),
|
623
|
+
Card.new('Hearts', '2'),
|
624
|
+
Card.new('Spades', '2'),
|
625
|
+
Card.new('Diamonds', '2'),
|
626
|
+
Card.new('Hearts', '3')
|
627
|
+
)
|
628
|
+
end
|
629
|
+
|
630
|
+
it 'should beat smaller quads' do
|
631
|
+
@highest_quads.should > @quads
|
632
|
+
@quads.should > @lowest_quads
|
633
|
+
end
|
634
|
+
|
635
|
+
it 'should beat any full house' do
|
636
|
+
@lowest_quads.should > @highest_full_house
|
637
|
+
end
|
638
|
+
|
639
|
+
it 'should beat any flush' do
|
640
|
+
@lowest_quads.should > @highest_flush
|
641
|
+
end
|
642
|
+
|
643
|
+
it 'should beat any straight' do
|
644
|
+
@lowest_quads.should > @highest_straight
|
645
|
+
end
|
646
|
+
|
647
|
+
it 'should beat any set' do
|
648
|
+
@lowest_quads.should > @highest_set
|
649
|
+
end
|
650
|
+
|
651
|
+
it 'should beat any two pair' do
|
652
|
+
@lowest_quads.should > @highest_two_pair
|
653
|
+
end
|
654
|
+
|
655
|
+
it 'should beat any pair' do
|
656
|
+
@lowest_quads.should > @highest_pair
|
657
|
+
end
|
658
|
+
|
659
|
+
it 'should beat any high card' do
|
660
|
+
@lowest_quads.should > @highest_high_card
|
661
|
+
end
|
662
|
+
|
663
|
+
it 'should consider the quads first' do
|
664
|
+
Hand.new(
|
665
|
+
Card.new('Clubs', 'Ace'),
|
666
|
+
Card.new('Hearts', 'Ace'),
|
667
|
+
Card.new('Spades', 'Ace'),
|
668
|
+
Card.new('Diamonds', 'Ace'),
|
669
|
+
Card.new('Hearts', '2')
|
670
|
+
).should > Hand.new(
|
671
|
+
Card.new('Clubs', 'King'),
|
672
|
+
Card.new('Hearts', 'King'),
|
673
|
+
Card.new('Spades', 'King'),
|
674
|
+
Card.new('Diamonds', 'King'),
|
675
|
+
Card.new('Hearts', 'Queen')
|
676
|
+
)
|
677
|
+
end
|
678
|
+
|
679
|
+
it 'should consider the kicker if the quads are the same' do
|
680
|
+
Hand.new(
|
681
|
+
Card.new('Clubs', 'Ace'),
|
682
|
+
Card.new('Hearts', 'Ace'),
|
683
|
+
Card.new('Spades', 'Ace'),
|
684
|
+
Card.new('Diamonds', 'Ace'),
|
685
|
+
Card.new('Hearts', 'Queen')
|
686
|
+
).should > Hand.new(
|
687
|
+
Card.new('Clubs', 'Ace'),
|
688
|
+
Card.new('Hearts', 'Ace'),
|
689
|
+
Card.new('Spades', 'Ace'),
|
690
|
+
Card.new('Diamonds', 'Ace'),
|
691
|
+
Card.new('Hearts', 'Jack')
|
692
|
+
)
|
693
|
+
end
|
694
|
+
end
|
695
|
+
|
696
|
+
describe 'full house' do
|
697
|
+
before do
|
698
|
+
@lowest_full_house = Hand.new(
|
699
|
+
Card.new('Clubs', '2'),
|
700
|
+
Card.new('Hearts', '2'),
|
701
|
+
Card.new('Spades', '2'),
|
702
|
+
Card.new('Diamonds', '3'),
|
703
|
+
Card.new('Hearts', '3')
|
704
|
+
)
|
705
|
+
end
|
706
|
+
|
707
|
+
it 'should beat a smaller full house' do
|
708
|
+
@highest_full_house.should > @full_house
|
709
|
+
@full_house.should > @lowest_full_house
|
710
|
+
end
|
711
|
+
|
712
|
+
it 'should beat any flush' do
|
713
|
+
@lowest_full_house.should > @highest_flush
|
714
|
+
end
|
715
|
+
|
716
|
+
it 'should beat any straight' do
|
717
|
+
@lowest_full_house.should > @highest_straight
|
718
|
+
end
|
719
|
+
|
720
|
+
it 'should beat any set' do
|
721
|
+
@lowest_full_house.should > @highest_set
|
722
|
+
end
|
723
|
+
|
724
|
+
it 'should beat any two pair' do
|
725
|
+
@lowest_full_house.should > @highest_two_pair
|
726
|
+
end
|
727
|
+
|
728
|
+
it 'should beat any pair' do
|
729
|
+
@lowest_full_house.should > @highest_pair
|
730
|
+
end
|
731
|
+
|
732
|
+
it 'should beat any high card' do
|
733
|
+
@lowest_full_house.should > @highest_high_card
|
734
|
+
end
|
735
|
+
|
736
|
+
it 'should consider the set first' do
|
737
|
+
Hand.new(
|
738
|
+
Card.new('Clubs', 'Ace'),
|
739
|
+
Card.new('Hearts', 'Ace'),
|
740
|
+
Card.new('Spades', 'Ace'),
|
741
|
+
Card.new('Diamonds', '2'),
|
742
|
+
Card.new('Hearts', '2')
|
743
|
+
).should > Hand.new(
|
744
|
+
Card.new('Clubs', 'King'),
|
745
|
+
Card.new('Hearts', 'King'),
|
746
|
+
Card.new('Spades', 'King'),
|
747
|
+
Card.new('Diamonds', 'Queen'),
|
748
|
+
Card.new('Hearts', 'Queen')
|
749
|
+
)
|
750
|
+
end
|
751
|
+
|
752
|
+
it 'should consider the pair if the set is the same' do
|
753
|
+
Hand.new(
|
754
|
+
Card.new('Clubs', 'Ace'),
|
755
|
+
Card.new('Hearts', 'Ace'),
|
756
|
+
Card.new('Spades', 'Ace'),
|
757
|
+
Card.new('Diamonds', 'Queen'),
|
758
|
+
Card.new('Hearts', 'Queen')
|
759
|
+
).should > Hand.new(
|
760
|
+
Card.new('Clubs', 'Ace'),
|
761
|
+
Card.new('Hearts', 'Ace'),
|
762
|
+
Card.new('Spades', 'Ace'),
|
763
|
+
Card.new('Diamonds', 'Jack'),
|
764
|
+
Card.new('Hearts', 'Jack')
|
765
|
+
)
|
766
|
+
end
|
767
|
+
end
|
768
|
+
|
769
|
+
describe 'flush' do
|
770
|
+
before do
|
771
|
+
@lowest_flush = Hand.new(
|
772
|
+
Card.new('Clubs', '2'),
|
773
|
+
Card.new('Clubs', '3'),
|
774
|
+
Card.new('Clubs', '4'),
|
775
|
+
Card.new('Clubs', '5'),
|
776
|
+
Card.new('Clubs', '7')
|
777
|
+
)
|
778
|
+
end
|
779
|
+
|
780
|
+
it 'should beat a smaller flush' do
|
781
|
+
@highest_flush.should > @flush
|
782
|
+
@flush.should > @lowest_flush
|
783
|
+
end
|
784
|
+
|
785
|
+
it 'should beat any straight' do
|
786
|
+
@lowest_flush.should > @highest_straight
|
787
|
+
end
|
788
|
+
|
789
|
+
it 'should beat any set' do
|
790
|
+
@lowest_flush.should > @highest_set
|
791
|
+
end
|
792
|
+
|
793
|
+
it 'should beat any two pair' do
|
794
|
+
@lowest_flush.should > @highest_two_pair
|
795
|
+
end
|
796
|
+
|
797
|
+
it 'should beat any pair' do
|
798
|
+
@lowest_flush.should > @highest_pair
|
799
|
+
end
|
800
|
+
|
801
|
+
it 'should beat any high card' do
|
802
|
+
@lowest_flush.should > @highest_high_card
|
803
|
+
end
|
804
|
+
|
805
|
+
it 'should compare the highest cards in the flush' do
|
806
|
+
Hand.new(
|
807
|
+
Card.new('Spades', 'Ace'),
|
808
|
+
Card.new('Spades', 'King'),
|
809
|
+
Card.new('Spades', '4'),
|
810
|
+
Card.new('Spades', '3'),
|
811
|
+
Card.new('Spades', '2')
|
812
|
+
).should > Hand.new(
|
813
|
+
Card.new('Spades', 'Ace'),
|
814
|
+
Card.new('Spades', 'Queen'),
|
815
|
+
Card.new('Spades', 'Jack'),
|
816
|
+
Card.new('Spades', '10'),
|
817
|
+
Card.new('Spades', '9')
|
818
|
+
)
|
819
|
+
end
|
820
|
+
end
|
821
|
+
|
822
|
+
describe 'straight' do
|
823
|
+
before do
|
824
|
+
@lowest_straight = Hand.new(
|
825
|
+
Card.new('Clubs', 'Ace'),
|
826
|
+
Card.new('Hearts', '2'),
|
827
|
+
Card.new('Spades', '3'),
|
828
|
+
Card.new('Diamonds', '4'),
|
829
|
+
Card.new('Hearts', '5')
|
830
|
+
)
|
831
|
+
end
|
832
|
+
|
833
|
+
it 'should beat a smaller straight' do
|
834
|
+
@highest_straight.should > @straight
|
835
|
+
@straight.should > @lowest_straight
|
836
|
+
end
|
837
|
+
|
838
|
+
it 'should beat any set' do
|
839
|
+
@lowest_straight.should > @highest_set
|
840
|
+
end
|
841
|
+
|
842
|
+
it 'should beat any two pair' do
|
843
|
+
@lowest_straight.should > @highest_two_pair
|
844
|
+
end
|
845
|
+
|
846
|
+
it 'should beat any pair' do
|
847
|
+
@lowest_straight.should > @highest_pair
|
848
|
+
end
|
849
|
+
|
850
|
+
it 'should beat any high card' do
|
851
|
+
@lowest_straight.should > @highest_high_card
|
852
|
+
end
|
853
|
+
end
|
854
|
+
|
855
|
+
describe 'set' do
|
856
|
+
before do
|
857
|
+
@lowest_set = Hand.new(
|
858
|
+
Card.new('Spades', '2'),
|
859
|
+
Card.new('Clubs', '2'),
|
860
|
+
Card.new('Hearts', '2'),
|
861
|
+
Card.new('Diamonds', '3'),
|
862
|
+
Card.new('Clubs', '4')
|
863
|
+
)
|
864
|
+
end
|
865
|
+
|
866
|
+
it 'should beat a smaller set' do
|
867
|
+
@highest_set.should > @set
|
868
|
+
@set.should > @lowest_set
|
869
|
+
end
|
870
|
+
|
871
|
+
it 'should beat any two pair' do
|
872
|
+
@lowest_set.should > @highest_two_pair
|
873
|
+
end
|
874
|
+
|
875
|
+
it 'should beat any pair' do
|
876
|
+
@lowest_set.should > @highest_pair
|
877
|
+
end
|
878
|
+
|
879
|
+
it 'should beat any high card' do
|
880
|
+
@lowest_set.should > @highest_high_card
|
881
|
+
end
|
882
|
+
|
883
|
+
it 'should beat smaller sets' do
|
884
|
+
Hand.new(
|
885
|
+
Card.new('Spades', '7'),
|
886
|
+
Card.new('Clubs', '7'),
|
887
|
+
Card.new('Diamonds', '7'),
|
888
|
+
Card.new('Hearts', '2'),
|
889
|
+
Card.new('Clubs', '3')
|
890
|
+
).should > Hand.new(
|
891
|
+
Card.new('Spades', '6'),
|
892
|
+
Card.new('Clubs', '6'),
|
893
|
+
Card.new('Diamonds', '6'),
|
894
|
+
Card.new('Hearts', 'King'),
|
895
|
+
Card.new('Clubs', 'Ace')
|
896
|
+
)
|
897
|
+
end
|
898
|
+
|
899
|
+
it 'should beat smaller kickers' do
|
900
|
+
Hand.new(
|
901
|
+
Card.new('Spades', '7'),
|
902
|
+
Card.new('Clubs', '7'),
|
903
|
+
Card.new('Diamonds', '7'),
|
904
|
+
Card.new('Hearts', 'Ace'),
|
905
|
+
Card.new('Clubs', 'Jack')
|
906
|
+
).should > Hand.new(
|
907
|
+
Card.new('Spades', '7'),
|
908
|
+
Card.new('Clubs', '7'),
|
909
|
+
Card.new('Diamonds', '7'),
|
910
|
+
Card.new('Hearts', 'Ace'),
|
911
|
+
Card.new('Clubs', '10')
|
912
|
+
)
|
913
|
+
end
|
914
|
+
end
|
915
|
+
|
916
|
+
describe 'two pair' do
|
917
|
+
before do
|
918
|
+
@lowest_two_pair = Hand.new(
|
919
|
+
Card.new('Spades', '2'),
|
920
|
+
Card.new('Clubs', '2'),
|
921
|
+
Card.new('Hearts', '3'),
|
922
|
+
Card.new('Diamonds', '3'),
|
923
|
+
Card.new('Clubs', '4')
|
924
|
+
)
|
925
|
+
end
|
926
|
+
|
927
|
+
it 'should beat a smaller two pair' do
|
928
|
+
@highest_two_pair.should > @two_pair
|
929
|
+
@two_pair.should > @lowest_two_pair
|
930
|
+
end
|
931
|
+
|
932
|
+
it 'should beat any pair' do
|
933
|
+
@lowest_two_pair.should > @highest_pair
|
934
|
+
end
|
935
|
+
|
936
|
+
it 'should beat any high card' do
|
937
|
+
@lowest_two_pair.should > @highest_high_card
|
938
|
+
end
|
939
|
+
|
940
|
+
it 'should beat smaller first pairs' do
|
941
|
+
Hand.new(
|
942
|
+
Card.new('Spades', 'Ace'),
|
943
|
+
Card.new('Clubs', 'Ace'),
|
944
|
+
Card.new('Diamonds', '2'),
|
945
|
+
Card.new('Hearts', '2'),
|
946
|
+
Card.new('Clubs', '3')
|
947
|
+
).should > Hand.new(
|
948
|
+
Card.new('Spades', 'King'),
|
949
|
+
Card.new('Clubs', 'King'),
|
950
|
+
Card.new('Diamonds', 'Queen'),
|
951
|
+
Card.new('Hearts', 'Queen'),
|
952
|
+
Card.new('Clubs', 'Ace')
|
953
|
+
)
|
954
|
+
end
|
955
|
+
|
956
|
+
it 'should beat smaller second pairs' do
|
957
|
+
Hand.new(
|
958
|
+
Card.new('Spades', 'King'),
|
959
|
+
Card.new('Clubs', 'King'),
|
960
|
+
Card.new('Diamonds', 'Queen'),
|
961
|
+
Card.new('Hearts', 'Queen'),
|
962
|
+
Card.new('Clubs', '2')
|
963
|
+
).should > Hand.new(
|
964
|
+
Card.new('Spades', 'King'),
|
965
|
+
Card.new('Clubs', 'King'),
|
966
|
+
Card.new('Diamonds', 'Jack'),
|
967
|
+
Card.new('Hearts', 'Jack'),
|
968
|
+
Card.new('Clubs', 'Ace')
|
969
|
+
)
|
970
|
+
end
|
971
|
+
|
972
|
+
it 'should beat smaller kickers' do
|
973
|
+
Hand.new(
|
974
|
+
Card.new('Spades', 'King'),
|
975
|
+
Card.new('Clubs', 'King'),
|
976
|
+
Card.new('Diamonds', 'Queen'),
|
977
|
+
Card.new('Hearts', 'Queen'),
|
978
|
+
Card.new('Clubs', 'Ace')
|
979
|
+
).should > Hand.new(
|
980
|
+
Card.new('Spades', 'King'),
|
981
|
+
Card.new('Clubs', 'King'),
|
982
|
+
Card.new('Diamonds', 'Queen'),
|
983
|
+
Card.new('Hearts', 'Queen'),
|
984
|
+
Card.new('Clubs', 'Jack')
|
985
|
+
)
|
986
|
+
end
|
987
|
+
end
|
988
|
+
|
989
|
+
describe 'pair' do
|
990
|
+
before do
|
991
|
+
@lowest_pair = Hand.new(
|
992
|
+
Card.new('Spades', '2'),
|
993
|
+
Card.new('Clubs', '2'),
|
994
|
+
Card.new('Hearts', '3'),
|
995
|
+
Card.new('Diamonds', '4'),
|
996
|
+
Card.new('Diamonds', '5')
|
997
|
+
)
|
998
|
+
end
|
999
|
+
|
1000
|
+
it 'should beat a smaller pair' do
|
1001
|
+
@highest_pair.should > @pair
|
1002
|
+
@pair.should > @lowest_pair
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
it 'should beat any high card' do
|
1006
|
+
@lowest_pair.should > @highest_high_card
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
it 'should beat smaller kickers' do
|
1010
|
+
Hand.new(
|
1011
|
+
Card.new('Spades', 'Ace'),
|
1012
|
+
Card.new('Clubs', 'Ace'),
|
1013
|
+
Card.new('Diamonds', 'King'),
|
1014
|
+
Card.new('Hearts', 'Queen'),
|
1015
|
+
Card.new('Clubs', '2')
|
1016
|
+
).should > Hand.new(
|
1017
|
+
Card.new('Spades', 'Ace'),
|
1018
|
+
Card.new('Clubs', 'Ace'),
|
1019
|
+
Card.new('Diamonds', 'King'),
|
1020
|
+
Card.new('Hearts', 'Jack'),
|
1021
|
+
Card.new('Clubs', '10')
|
1022
|
+
)
|
1023
|
+
end
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
describe 'high card' do
|
1027
|
+
it 'should beat a smaller high card' do
|
1028
|
+
@highest_high_card.should > @high_card
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
it 'should beat a smaller subsequent card' do
|
1032
|
+
Hand.new(
|
1033
|
+
Card.new('Spades', 'Ace'),
|
1034
|
+
Card.new('Clubs', 'King'),
|
1035
|
+
Card.new('Diamonds', '4'),
|
1036
|
+
Card.new('Hearts', '3'),
|
1037
|
+
Card.new('Clubs', '2')
|
1038
|
+
).should > Hand.new(
|
1039
|
+
Card.new('Spades', 'Ace'),
|
1040
|
+
Card.new('Clubs', 'Queen'),
|
1041
|
+
Card.new('Diamonds', 'Jack'),
|
1042
|
+
Card.new('Hearts', '10'),
|
1043
|
+
Card.new('Clubs', '9')
|
1044
|
+
)
|
1045
|
+
end
|
1046
|
+
end
|
1047
|
+
end
|
1048
|
+
end
|
1049
|
+
end
|