bridge 0.0.10 → 0.0.11

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
data/bridge.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bridge}
8
- s.version = "0.0.10"
8
+ s.version = "0.0.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jakub Kuźma"]
12
- s.date = %q{2010-02-24}
12
+ s.date = %q{2010-02-25}
13
13
  s.description = %q{Useful contract bridge utilities - deal generator, id to deal and deal to id conversion}
14
14
  s.email = %q{qoobaa+github@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -28,11 +28,13 @@ Gem::Specification.new do |s|
28
28
  "lib/bridge/bid.rb",
29
29
  "lib/bridge/card.rb",
30
30
  "lib/bridge/deal.rb",
31
+ "lib/bridge/trick.rb",
31
32
  "test/helper.rb",
32
33
  "test/test_bid.rb",
33
34
  "test/test_bridge.rb",
34
35
  "test/test_card.rb",
35
- "test/test_deal.rb"
36
+ "test/test_deal.rb",
37
+ "test/test_trick.rb"
36
38
  ]
37
39
  s.homepage = %q{http://github.com/qoobaa/bridge}
38
40
  s.rdoc_options = ["--charset=UTF-8"]
@@ -42,6 +44,7 @@ Gem::Specification.new do |s|
42
44
  s.test_files = [
43
45
  "test/test_bridge.rb",
44
46
  "test/test_bid.rb",
47
+ "test/test_trick.rb",
45
48
  "test/test_card.rb",
46
49
  "test/test_deal.rb",
47
50
  "test/helper.rb"
@@ -0,0 +1,22 @@
1
+ module Bridge
2
+ class Trick
3
+ attr_reader :cards, :trump, :suit
4
+
5
+ def initialize(*args)
6
+ options = args.pop if args.last.is_a?(Hash)
7
+ @cards = args.flatten.map { |s| Bridge::Card.new(s.to_s) }
8
+ @suit = @cards.first.suit
9
+ @trump = options && options[:trump]
10
+ end
11
+
12
+ def winner
13
+ winner_in_suit(@trump) || winner_in_suit(@suit)
14
+ end
15
+
16
+ private
17
+
18
+ def winner_in_suit(suit)
19
+ @cards.select { |c| c.suit == suit }.max
20
+ end
21
+ end
22
+ end
data/lib/bridge.rb CHANGED
@@ -1,6 +1,7 @@
1
+ require "bridge/bid"
1
2
  require "bridge/card"
2
3
  require "bridge/deal"
3
- require "bridge/bid"
4
+ require "bridge/trick"
4
5
 
5
6
  module Bridge
6
7
  # Number of possible deals in bridge
@@ -0,0 +1,38 @@
1
+ require "helper"
2
+
3
+ class TestTrick < Test::Unit::TestCase
4
+ test "the highest H card is the winner in NT game H trick and single suit" do
5
+ trick = Bridge::Trick.new("H2", "H3", "H4", "H5")
6
+ assert_equal Bridge::Card.new("H5"), trick.winner
7
+ end
8
+
9
+ test "the highest H card is the winner in NT game H trick and multiple suits" do
10
+ trick = Bridge::Trick.new("H2", "C3", "D4", "S5")
11
+ assert_equal Bridge::Card.new("H2"), trick.winner
12
+ end
13
+
14
+ test "the highest H card is the winner in S game H trick and single suit" do
15
+ trick = Bridge::Trick.new("H2", "H5", "H4", "H3", :trump => "S")
16
+ assert_equal Bridge::Card.new("H5"), trick.winner
17
+ end
18
+
19
+ test "the highest H card is the winner in S game H trick and multiple suits" do
20
+ trick = Bridge::Trick.new("H2", "D5", "C4", "H3", :trump => "S")
21
+ assert_equal Bridge::Card.new("H3"), trick.winner
22
+ end
23
+
24
+ test "the only trump is the winner in S game H trick and multiple suits" do
25
+ trick = Bridge::Trick.new("H2", "D5", "S2", "H3", :trump => "S")
26
+ assert_equal Bridge::Card.new("S2"), trick.winner
27
+ end
28
+
29
+ test "the highest trump is the winner in S game H trick and multiple suits" do
30
+ trick = Bridge::Trick.new("H2", "SA", "S2", "H3", :trump => "S")
31
+ assert_equal Bridge::Card.new("SA"), trick.winner
32
+ end
33
+
34
+ test "the highest trump is the winner in S game S trick and multiple suits" do
35
+ trick = Bridge::Trick.new("S2", "HA", "CA", "DA", :trump => "S")
36
+ assert_equal Bridge::Card.new("S2"), trick.winner
37
+ end
38
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 10
9
- version: 0.0.10
8
+ - 11
9
+ version: 0.0.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jakub Ku\xC5\xBAma"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-24 00:00:00 +01:00
17
+ date: 2010-02-25 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,11 +50,13 @@ files:
50
50
  - lib/bridge/bid.rb
51
51
  - lib/bridge/card.rb
52
52
  - lib/bridge/deal.rb
53
+ - lib/bridge/trick.rb
53
54
  - test/helper.rb
54
55
  - test/test_bid.rb
55
56
  - test/test_bridge.rb
56
57
  - test/test_card.rb
57
58
  - test/test_deal.rb
59
+ - test/test_trick.rb
58
60
  has_rdoc: true
59
61
  homepage: http://github.com/qoobaa/bridge
60
62
  licenses: []
@@ -88,6 +90,7 @@ summary: Contract bridge utilities
88
90
  test_files:
89
91
  - test/test_bridge.rb
90
92
  - test/test_bid.rb
93
+ - test/test_trick.rb
91
94
  - test/test_card.rb
92
95
  - test/test_deal.rb
93
96
  - test/helper.rb