acpc_poker_basic_proxy 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +0,0 @@
1
-
2
- # Information about a dealer instance.
3
- module AcpcPokerBasicProxy
4
- module CommunicationLogic
5
- class AcpcDealerInformation
6
- # @return [String] The host name of the dealer associated with this table.
7
- attr_reader :host_name
8
-
9
- # @return [Integer] The port number of the dealer associated with this table.
10
- attr_reader :port_number
11
-
12
- # @return [Integer] The dealer's response timeout.
13
- attr_reader :millisecond_response_timeout
14
-
15
- def initialize(host_name, port_number, millisecond_response_timeout=nil)
16
- @host_name = host_name
17
- @port_number = port_number
18
- @millisecond_response_timeout = millisecond_response_timeout
19
- end
20
- end
21
- end
22
- end
@@ -1,32 +0,0 @@
1
-
2
- # Mixin to add methods to IO so that they will also be inherited by TCPSocket.
3
- class IO
4
- # Checks if the socket is ready to be read from.
5
- # @param [Integer] timeout_in_seconds Amount of time to wait for the sever to respond, in seconds. Must be positive or +nil+.
6
- # @return [Boolean] +true+ if the socket is ready to be read from, +false+ otherwise.
7
- def ready_to_read?(timeout_in_seconds=nil)
8
- read_array = [self]
9
- write_array = nil
10
- error_array = nil
11
-
12
- select(read_array, write_array, error_array, timeout_in_seconds)
13
- end
14
-
15
- # Checks if the socket is ready to be written to.
16
- # @param [Integer] timeout_in_seconds Amount of time to wait for the sever to respond, in seconds. Must be positive or +nil+.
17
- # @return [Boolean] +true+ if the socket is ready to be written to, +false+ otherwise.
18
- def ready_to_write?(timeout_in_seconds=nil)
19
- read_array = nil
20
- write_array = [self]
21
- error_array = nil
22
-
23
- select(read_array, write_array, error_array, timeout_in_seconds)
24
- end
25
-
26
- private
27
-
28
- # @see IO#select
29
- def select(read_array, write_array=[], error_array=[], timeout_in_seconds=nil)
30
- IO.select(read_array, write_array, error_array, timeout_in_seconds) != nil
31
- end
32
- end
@@ -1,67 +0,0 @@
1
-
2
- require_relative 'support/spec_helper'
3
-
4
- require 'socket'
5
-
6
- require 'acpc_poker_basic_proxy/communication_logic/acpc_dealer_communicator'
7
-
8
- describe AcpcPokerBasicProxy::CommunicationLogic::AcpcDealerCommunicator do
9
-
10
- before do
11
- start_test_connection 0
12
- @client_connection.gets.chomp.must_equal(
13
- "#{AcpcPokerBasicProxy::CommunicationLogic::AcpcDealerCommunicator::VERSION_LABEL}:#{AcpcPokerBasicProxy::CommunicationLogic::AcpcDealerCommunicator::VERSION_NUMBERS[:major]}.#{AcpcPokerBasicProxy::CommunicationLogic::AcpcDealerCommunicator::VERSION_NUMBERS[:minor]}.#{AcpcPokerBasicProxy::CommunicationLogic::AcpcDealerCommunicator::VERSION_NUMBERS[:revision]}"
14
- )
15
-
16
- @match_state = 'MATCHSTATE:0:0::5d5c'
17
- end
18
-
19
- after do
20
- @patient.close
21
- @client_connection.close
22
- end
23
-
24
- describe "#ready_to_read?" do
25
- it 'lets the caller know that there is not new input from the dealer' do
26
- @patient.ready_to_read?.must_equal false
27
- end
28
-
29
- it 'lets the caller know that there is new input from the dealer' do
30
- @client_connection.puts "New input"
31
- @patient.ready_to_read?.must_equal true
32
- end
33
- end
34
-
35
- describe "#ready_to_write?" do
36
- it 'lets the caller know if the dealer is ready to receive data' do
37
- @patient.ready_to_write?.must_equal true
38
- end
39
- end
40
-
41
- describe "#write" do
42
- it "properly sends actions to the dealer" do
43
- action = @match_state + ':c'
44
- @patient.write action
45
-
46
- @client_connection.gets.chomp.must_equal(action)
47
- end
48
- end
49
-
50
- describe "#gets" do
51
- it "properly receives matchstate strings from the dealer" do
52
- @client_connection.puts @match_state
53
- @patient.gets.must_equal(@match_state)
54
- end
55
- end
56
-
57
- def start_test_connection(port)
58
- fake_dealer = TCPServer.open(port)
59
- @patient = AcpcPokerBasicProxy::CommunicationLogic::AcpcDealerCommunicator.new(
60
- fake_dealer.addr[1],
61
- 'localhost',
62
- 0
63
- )
64
-
65
- @client_connection = fake_dealer.accept
66
- end
67
- end
@@ -1,10 +0,0 @@
1
-
2
- require_relative 'support/spec_helper'
3
-
4
- require 'acpc_poker_basic_proxy/communication_logic/acpc_dealer_information'
5
-
6
- describe AcpcPokerBasicProxy::CommunicationLogic::AcpcDealerInformation do
7
- it '' do
8
- skip "Since this class only holds data right now, there's no need for tests"
9
- end
10
- end