bridge 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bridge.gemspec +1 -1
- data/lib/bridge/trick.rb +4 -6
- data/test/test_trick.rb +10 -10
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
data/bridge.gemspec
CHANGED
data/lib/bridge/trick.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
module Bridge
|
2
2
|
class Trick
|
3
|
-
attr_reader :cards, :
|
3
|
+
attr_reader :cards, :suit
|
4
4
|
|
5
5
|
def initialize(*args)
|
6
|
-
|
7
|
-
@cards = args.flatten.map { |s| Bridge::Card.new(s.to_s) }
|
6
|
+
@cards = args.flatten.map { |c| Bridge::Card.new(c.to_s) }
|
8
7
|
@suit = @cards.first.suit
|
9
|
-
@trump = options && options[:trump]
|
10
8
|
end
|
11
9
|
|
12
|
-
def winner
|
13
|
-
winner_in_suit(
|
10
|
+
def winner(trump = nil)
|
11
|
+
winner_in_suit(trump) || winner_in_suit(@suit)
|
14
12
|
end
|
15
13
|
|
16
14
|
private
|
data/test/test_trick.rb
CHANGED
@@ -12,27 +12,27 @@ class TestTrick < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
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"
|
16
|
-
assert_equal Bridge::Card.new("H5"), trick.winner
|
15
|
+
trick = Bridge::Trick.new("H2", "H5", "H4", "H3")
|
16
|
+
assert_equal Bridge::Card.new("H5"), trick.winner("S")
|
17
17
|
end
|
18
18
|
|
19
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"
|
21
|
-
assert_equal Bridge::Card.new("H3"), trick.winner
|
20
|
+
trick = Bridge::Trick.new("H2", "D5", "C4", "H3")
|
21
|
+
assert_equal Bridge::Card.new("H3"), trick.winner("S")
|
22
22
|
end
|
23
23
|
|
24
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"
|
26
|
-
assert_equal Bridge::Card.new("S2"), trick.winner
|
25
|
+
trick = Bridge::Trick.new("H2", "D5", "S2", "H3")
|
26
|
+
assert_equal Bridge::Card.new("S2"), trick.winner("S")
|
27
27
|
end
|
28
28
|
|
29
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"
|
31
|
-
assert_equal Bridge::Card.new("SA"), trick.winner
|
30
|
+
trick = Bridge::Trick.new("H2", "SA", "S2", "H3")
|
31
|
+
assert_equal Bridge::Card.new("SA"), trick.winner("S")
|
32
32
|
end
|
33
33
|
|
34
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"
|
36
|
-
assert_equal Bridge::Card.new("S2"), trick.winner
|
35
|
+
trick = Bridge::Trick.new("S2", "HA", "CA", "DA")
|
36
|
+
assert_equal Bridge::Card.new("S2"), trick.winner("S")
|
37
37
|
end
|
38
38
|
end
|