bitpoker 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,97 @@
1
+ require "test/unit"
2
+ require 'shoulda'
3
+ require "./lib/bitpoker"
4
+
5
+ class TestRound < Test::Unit::TestCase
6
+
7
+ include BitPoker
8
+
9
+ context "a round" do
10
+
11
+ setup do
12
+ @bot = BotProxy.new( BotInterface.new )
13
+ @round = Round.new( [@bot, @bot])
14
+ end
15
+
16
+ should "start with rules introduction" do
17
+ assert_equal Round::STATE_RULES_INTRODUCTION, @round.state
18
+ end
19
+
20
+ should "know a winner index" do
21
+ @round.cards = [2,4]
22
+ assert_equal 1, @round.winner_index
23
+ end
24
+
25
+ should "know a loser index" do
26
+ @round.cards = [2,4]
27
+ assert_equal 0, @round.loser_index
28
+ end
29
+
30
+ should "know when it is a draw" do
31
+ @round.cards = [2,2]
32
+ assert @round.draw?
33
+ end
34
+
35
+ should "know when it is not a draw" do
36
+ @round.cards = [4,0]
37
+ assert ! @round.draw?
38
+ end
39
+
40
+ should "not return winner index when it is a draw" do
41
+ @round.instance_variable_set( :@cards, [2,2] )
42
+ assert_equal nil, @round.winner_index
43
+ end
44
+
45
+ should "not return loser index when it is a draw" do
46
+ @round.cards = [0,0]
47
+ assert_equal nil, @round.loser_index
48
+ end
49
+
50
+ should "know when bets are even is a draw" do
51
+ @round.bets = [10,10]
52
+ assert_equal true, @round.bets_even?
53
+ end
54
+
55
+ should "know when bets are not even" do
56
+ @round.bets = [20,10]
57
+ assert_equal false, @round.bets_even?
58
+ end
59
+
60
+ should "know higher bid" do
61
+ @round.bets = [5,8]
62
+ assert_equal 8, @round.higher_bid
63
+ end
64
+
65
+ should "know lower bid" do
66
+ @round.bets = [5,8]
67
+ assert_equal 5, @round.lower_bid
68
+ end
69
+
70
+ should "know higher bidder index" do
71
+ @round.bets = [5,8]
72
+ assert_equal 1, @round.higher_bidder_index
73
+ end
74
+
75
+ should "know lower bidder index" do
76
+ @round.bets = [5,8]
77
+ assert_equal 0, @round.lower_bidder_index
78
+ end
79
+
80
+ should "know higher bidder" do
81
+ @round.bets = [5,8]
82
+ assert_equal @round.bots[1], @round.higher_bidder
83
+ end
84
+
85
+ should "know lower bidder" do
86
+ @round.bets = [5,8]
87
+ assert_equal @round.bots[0], @round.lower_bidder
88
+ end
89
+
90
+ should "know a stake" do
91
+ @round.bets = [5,10]
92
+ assert_equal 10, @round.stake
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,59 @@
1
+ require "test/unit"
2
+ require 'shoulda'
3
+ require "mocha/setup"
4
+
5
+ require "./lib/bitpoker"
6
+
7
+ class TestRules < Test::Unit::TestCase
8
+
9
+ include BitPoker::Rules
10
+
11
+ context "number of rounds" do
12
+ should "be a positive integer" do
13
+ assert ROUNDS >= 1
14
+ end
15
+ end
16
+
17
+ context "minimum stake" do
18
+ should "be a positive integer" do
19
+ assert MIN_STAKE >= 1
20
+ end
21
+ end
22
+
23
+ context "maximum stake" do
24
+ should "be a positive integer" do
25
+ assert MAX_STAKE >= 1
26
+ end
27
+
28
+ should "higher than minimum stake" do
29
+ assert MAX_STAKE > MIN_STAKE
30
+ end
31
+ end
32
+
33
+ context "timeout" do
34
+ should "be a positive float" do
35
+ assert TIMEOUT > 0
36
+ end
37
+ end
38
+
39
+ context "card range" do
40
+
41
+ should "be a range" do
42
+ assert_kind_of Range, CARD_RANGE
43
+ end
44
+
45
+ should "not consist of not negative number" do
46
+ assert CARD_RANGE.min >= 0
47
+ assert CARD_RANGE.max >= 0
48
+ end
49
+
50
+ should "be at least size of 2" do
51
+ assert CARD_RANGE.size >= 2
52
+ end
53
+
54
+
55
+ end
56
+
57
+
58
+
59
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitpoker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Maciej Komorowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parallel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.2
33
+ description: Ruby implementation of BitPoker game.
34
+ email: mckomo@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - bitpoker.gemspec
45
+ - bot/README.md
46
+ - bot/dummy_bot.rb
47
+ - lib/bitpoker.rb
48
+ - lib/bitpoker/bot_interface.rb
49
+ - lib/bitpoker/bot_proxy.rb
50
+ - lib/bitpoker/bot_proxy_interface.rb
51
+ - lib/bitpoker/croupier.rb
52
+ - lib/bitpoker/duel.rb
53
+ - lib/bitpoker/game_logic.rb
54
+ - lib/bitpoker/round.rb
55
+ - lib/bitpoker/rules.rb
56
+ - test.rb
57
+ - test/support/glass_bot.rb
58
+ - test/support/sleepy_bot.rb
59
+ - test/test_bitpoker.rb
60
+ - test/test_bot_interface.rb
61
+ - test/test_bot_proxy.rb
62
+ - test/test_croupier.rb
63
+ - test/test_duel.rb
64
+ - test/test_game_logic.rb
65
+ - test/test_round.rb
66
+ - test/test_rules.rb
67
+ homepage: https://github.com/mckomo/BitPoker
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.2.1
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Bots play poker!
91
+ test_files:
92
+ - test/test_bitpoker.rb
93
+ - test/test_bot_interface.rb
94
+ - test/test_bot_proxy.rb
95
+ - test/test_croupier.rb
96
+ - test/test_duel.rb
97
+ - test/test_game_logic.rb
98
+ - test/test_round.rb
99
+ - test/test_rules.rb
100
+ has_rdoc: