poker 0.0.1

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.
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ module Poker
4
+ class CardTest < Test::Unit::TestCase
5
+ context "A card" do
6
+ setup do
7
+ @card = Card.new("As") # Ace of Spades
8
+ end
9
+
10
+ should "have a rank" do
11
+ assert_equal "A", @card.rank
12
+ end
13
+
14
+ should "have a rank value" do
15
+ assert_equal 12, @card.rank_value
16
+ end
17
+
18
+ should "have a suit" do
19
+ assert_equal "s", @card.suit
20
+ end
21
+
22
+ should "have a suit value" do
23
+ assert_equal 3, @card.suit_value
24
+ end
25
+
26
+ should "have a value" do
27
+ assert_equal 268442665, @card.value
28
+ end
29
+
30
+ should "respond to #to_s" do
31
+ assert_equal "As", @card.to_s
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ module Poker
4
+ class DeckTest < Test::Unit::TestCase
5
+ context "A Deck" do
6
+ setup do
7
+ @deck = Deck.new
8
+ end
9
+
10
+ should "have 52 elements" do
11
+ assert_equal 52, @deck.size
12
+ end
13
+
14
+ should "have cards" do
15
+ assert_kind_of Card, @deck.first
16
+ end
17
+
18
+ should "have 13 ranks" do
19
+ assert_equal 13, @deck.map { |c| c.rank }.uniq.size
20
+ end
21
+
22
+ should "have 4 suits" do
23
+ assert_equal 4, @deck.map { |c| c.suit }.uniq.size
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,79 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ module Poker
4
+ class HandTest < Test::Unit::TestCase
5
+ def self.should_recognize_value(expected, cards)
6
+ should "recognize value of #{cards}" do
7
+ assert_equal expected, Hand.new(cards).value
8
+ end
9
+ end
10
+
11
+ def self.should_recognize_rank(expected, cards)
12
+ should "recognize rank of #{cards}" do
13
+ assert_equal expected, Hand.new(cards).rank
14
+ end
15
+ end
16
+
17
+ context "A hand" do
18
+ setup do
19
+ @hand = Hand.new("As Ks Qs Js Ts")
20
+ end
21
+
22
+ should "have a size" do
23
+ assert_equal 5, @hand.size
24
+ end
25
+
26
+ should "have cards" do
27
+ assert_kind_of Card, @hand[0]
28
+ end
29
+
30
+ should "be comparable" do
31
+ assert @hand > Hand.new("5s 4s 3s 2s As")
32
+ assert @hand == Hand.new("Ad Kd Qd Jd Td")
33
+ end
34
+
35
+ should "respond to #to_s" do
36
+ assert_equal "As Ks Qs Js Ts", @hand.to_s
37
+ end
38
+ end
39
+
40
+ should "initialize with array of cards" do
41
+ @hand = Hand.new(Card.new("As"), Card.new("Ks"))
42
+ assert "A", @hand[0].rank
43
+ assert "K", @hand[1].rank
44
+ end
45
+
46
+ should "initialize with array of strings" do
47
+ @hand = Hand.new(*%w{As Ks})
48
+ assert "A", @hand[0].rank
49
+ assert "K", @hand[1].rank
50
+ end
51
+
52
+ should_recognize_value(1, "As Ks Qs Js Ts")
53
+ should_recognize_value(2, "Ks Qs Js Ts 9s")
54
+
55
+ should_recognize_rank "Royal Flush", "As Ks Qs Js Ts"
56
+ should_recognize_rank "Straight Flush", "Ks Qs Js Ts 9s"
57
+ should_recognize_rank "Four of a Kind", "Ac Ad Ah As Ks"
58
+
59
+ should "get the best 5-card hand from 7 cards" do
60
+ cards = %w{ 2c 3c 4c Ac Ad Ah As }
61
+ assert_equal "Four of a Kind", Hand.best(cards).rank
62
+ end
63
+
64
+ should "display cards with order" do
65
+ assert_equal "Ac Ad Qc Qd Kc", Hand.new("Kc Qd Ac Qc Ad").to_s
66
+ assert_equal "Ac Ad Qc Qd Kc", Hand.new("Kc Qc Ad Qd Ac").to_s
67
+ assert_equal "Ac Ad Qc Qd Kc", Hand.new("Kc Ad Ac Qc Qd").to_s
68
+ assert_equal "Tc Td Ac Qd 2c", Hand.new("2c Qd Ac Td Tc").to_s
69
+ assert_equal "Tc Td Ac Kd Qc", Hand.new("Qc Kd Ac Td Tc").to_s
70
+ assert_equal "Tc Td Ts Ac Qc", Hand.new("Ts Qc Ac Td Tc").to_s
71
+ assert_equal "Tc Td Ts Ac Ad", Hand.new("Ts Ad Ac Td Tc").to_s
72
+ assert_equal "Ac Ad As Tc Td", Hand.new("As Td Tc Ad Ac").to_s
73
+ assert_equal "2c 2d 2h 2s Ad", Hand.new("2s Ad 2d 2c 2h").to_s
74
+ assert_equal "5c 4c 3c 2c Ad", Hand.new("2c 4c Ad 5c 3c").to_s
75
+ assert_equal "Ac Tc 4c 3c 2c", Hand.new("2c 4c Tc Ac 3c").to_s
76
+ assert_equal "2c 2d 2s 5c 5d", Hand.new("2s 2d 2c 5d 5c").to_s
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'shoulda'
4
+ require 'redgreen'
5
+
6
+ $: << File.dirname(__FILE__) + '/../lib'
7
+ require 'poker'
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Wojciech Mach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Poker hand evaluator
15
+ email:
16
+ - wojtekmach1@gmail.com
17
+ executables: []
18
+ extensions:
19
+ - ext/handeval/extconf.rb
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - README
25
+ - Rakefile
26
+ - example/aces_equity.rb
27
+ - example/random_hu.rb
28
+ - ext/handeval/Makefile
29
+ - ext/handeval/arrays.h
30
+ - ext/handeval/extconf.rb
31
+ - ext/handeval/handeval.c
32
+ - ext/handeval/poker.h
33
+ - ext/handeval/pokerlib.c
34
+ - lib/poker.rb
35
+ - lib/poker/card.rb
36
+ - lib/poker/deck.rb
37
+ - lib/poker/hand.rb
38
+ - lib/poker/version.rb
39
+ - poker.gemspec
40
+ - test/poker/card_test.rb
41
+ - test/poker/deck_test.rb
42
+ - test/poker/hand_test.rb
43
+ - test/test_helper.rb
44
+ homepage: http://rubygems.org/gems/poker
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ - ext
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project: poker
65
+ rubygems_version: 1.8.11
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Poker hand evaluator
69
+ test_files:
70
+ - test/poker/card_test.rb
71
+ - test/poker/deck_test.rb
72
+ - test/poker/hand_test.rb
73
+ - test/test_helper.rb
74
+ has_rdoc: