bridge 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -0
- data/VERSION +1 -1
- data/bridge.gemspec +7 -7
- data/lib/bridge/score.rb +9 -0
- data/test/test_score.rb +59 -1
- metadata +7 -7
data/README.rdoc
CHANGED
@@ -29,6 +29,11 @@ You can also ask for all possible contracts finished with given points:
|
|
29
29
|
Bridge::Score.with_points(980)
|
30
30
|
#=> ["1NTX-11-vulnerable", "2C/DX-12-vulnerable", "6H/S-12"]
|
31
31
|
|
32
|
+
You can use regexp to check if contract with result is valid:
|
33
|
+
Bridge::Score::REGEXP
|
34
|
+
will match i.e.
|
35
|
+
"1NT=", "2SX+1", "6NTXX-2"
|
36
|
+
|
32
37
|
== Note on Patches/Pull Requests
|
33
38
|
|
34
39
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.21
|
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.
|
8
|
+
s.version = "0.0.21"
|
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-03-
|
12
|
+
s.date = %q{2010-03-22}
|
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 = [
|
@@ -44,13 +44,13 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.rubygems_version = %q{1.3.6}
|
45
45
|
s.summary = %q{Contract bridge utilities}
|
46
46
|
s.test_files = [
|
47
|
-
"test/
|
48
|
-
"test/test_bid.rb",
|
49
|
-
"test/test_card.rb",
|
47
|
+
"test/test_bridge.rb",
|
50
48
|
"test/test_trick.rb",
|
51
49
|
"test/test_deal.rb",
|
52
|
-
"test/
|
53
|
-
"test/test_score.rb"
|
50
|
+
"test/helper.rb",
|
51
|
+
"test/test_score.rb",
|
52
|
+
"test/test_bid.rb",
|
53
|
+
"test/test_card.rb"
|
54
54
|
]
|
55
55
|
|
56
56
|
if s.respond_to? :specification_version then
|
data/lib/bridge/score.rb
CHANGED
@@ -2,6 +2,15 @@ module Bridge
|
|
2
2
|
class Score
|
3
3
|
attr_reader :tricks, :contract, :vulnerable
|
4
4
|
|
5
|
+
# Checks contract with result, i.e. "1NTX-1", "2S=", "6SXX+1"
|
6
|
+
# on Ruby >= 1.9 there are named groups :contract and :result
|
7
|
+
# on Ruby < 1.9 there are: contract on $1 and result on $5
|
8
|
+
if RUBY_VERSION >= "1.9"
|
9
|
+
REGEXP = Regexp.new %q{\A(?<contract>([1-7])([CDHS]|NT)(X{1,2})?)(?<result>=|\+[1-6]|-([1-9]|1[0-3]))\Z}
|
10
|
+
else
|
11
|
+
REGEXP = Regexp.new %q{\A(([1-7])([CDHS]|NT)(X{1,2})?)(=|\+[1-6]|-([1-9]|1[0-3]))\Z}
|
12
|
+
end
|
13
|
+
|
5
14
|
# Creates new score object
|
6
15
|
#
|
7
16
|
# ==== Example
|
data/test/test_score.rb
CHANGED
@@ -261,4 +261,62 @@ class TestScoreContracts < Test::Unit::TestCase
|
|
261
261
|
test "return [] if not found" do
|
262
262
|
assert_equal [], Bridge::Score.with_points(100)
|
263
263
|
end
|
264
|
-
end
|
264
|
+
end
|
265
|
+
|
266
|
+
class TestRegexpScore < Test::Unit::TestCase
|
267
|
+
def setup
|
268
|
+
@regexp = Bridge::Score::REGEXP
|
269
|
+
end
|
270
|
+
|
271
|
+
test "match 1S+1" do
|
272
|
+
assert "1S+1" =~ @regexp
|
273
|
+
end
|
274
|
+
|
275
|
+
test "match 1NT=" do
|
276
|
+
assert "1NT=" =~ @regexp
|
277
|
+
end
|
278
|
+
|
279
|
+
test "not match 8S=" do
|
280
|
+
assert_nil "8S=" =~ @regexp
|
281
|
+
end
|
282
|
+
|
283
|
+
test "not match 1SXXX=" do
|
284
|
+
assert_nil "1SXXX=" =~ @regexp
|
285
|
+
end
|
286
|
+
|
287
|
+
test "not match 1S+7" do
|
288
|
+
assert_nil "1S+7" =~ @regexp
|
289
|
+
end
|
290
|
+
|
291
|
+
test "not match 1S-14" do
|
292
|
+
assert_nil "1S-14" =~ @regexp
|
293
|
+
end
|
294
|
+
|
295
|
+
test "not match 1S-21" do
|
296
|
+
assert_nil "1S-21" =~ @regexp
|
297
|
+
end
|
298
|
+
|
299
|
+
test "case sensitive" do
|
300
|
+
assert_nil "1s-1" =~ @regexp
|
301
|
+
end
|
302
|
+
|
303
|
+
test "return contract for 1NT=" do
|
304
|
+
result = "1NT=".match(@regexp)
|
305
|
+
assert_equal "1NT", RUBY_VERSION >= "1.9" ? result[:contract] : result[1]
|
306
|
+
end
|
307
|
+
|
308
|
+
test "return contract for 1NTXX=" do
|
309
|
+
result = "1NTXX=".match(@regexp)
|
310
|
+
assert_equal "1NTXX", RUBY_VERSION >= "1.9" ? result[:contract] : result[1]
|
311
|
+
end
|
312
|
+
|
313
|
+
test "return result for 1NT=" do
|
314
|
+
result = "1NT=".match(@regexp)
|
315
|
+
assert_equal "=", RUBY_VERSION >= "1.9" ? result[:result] : result[5]
|
316
|
+
end
|
317
|
+
|
318
|
+
test "return result for 1NT+2" do
|
319
|
+
result = "1NT+2".match(@regexp)
|
320
|
+
assert_equal "+2", RUBY_VERSION >= "1.9" ? result[:result] : result[5]
|
321
|
+
end
|
322
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 21
|
9
|
+
version: 0.0.21
|
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-03-
|
17
|
+
date: 2010-03-22 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -90,10 +90,10 @@ signing_key:
|
|
90
90
|
specification_version: 3
|
91
91
|
summary: Contract bridge utilities
|
92
92
|
test_files:
|
93
|
-
- test/
|
94
|
-
- test/test_bid.rb
|
95
|
-
- test/test_card.rb
|
93
|
+
- test/test_bridge.rb
|
96
94
|
- test/test_trick.rb
|
97
95
|
- test/test_deal.rb
|
98
|
-
- test/
|
96
|
+
- test/helper.rb
|
99
97
|
- test/test_score.rb
|
98
|
+
- test/test_bid.rb
|
99
|
+
- test/test_card.rb
|