All Files
(100.0%
covered at
498.28
hits/line)
4 files in total.
108 relevant lines.
108 lines covered and
0 lines missed
-
-
1
require_relative 'support/spec_helper'
-
-
1
require 'acpc_poker_basic_proxy/communication_logic/acpc_dealer_information'
-
-
1
describe AcpcPokerBasicProxy::CommunicationLogic::AcpcDealerInformation do
-
1
it '' do
-
1
skip "Since this class only holds data right now, there's no need for tests"
-
end
-
end
-
-
1
require_relative 'support/spec_helper'
-
-
1
require 'acpc_poker_types/poker_action'
-
1
require 'acpc_poker_types/match_state'
-
1
require 'acpc_poker_types/acpc_dealer_data/poker_match_data'
-
1
require 'acpc_dealer'
-
-
1
require 'acpc_poker_basic_proxy/communication_logic/action_sender'
-
-
1
include AcpcPokerBasicProxy::CommunicationLogic
-
1
include AcpcPokerTypes
-
-
1
describe ActionSender do
-
1
before(:each) do
-
6
@connection = MiniTest::Mock.new
-
6
@match_state = AcpcDealerData::PokerMatchData.parse_files(
-
match_logs[0].actions_file_path,
-
match_logs[0].results_file_path,
-
match_logs[0].player_names,
-
AcpcDealer::DEALER_DIRECTORY,
-
1
-
).data[0].data[0].action_message.state
-
end
-
-
1
describe "#send_action" do
-
1
it 'does not send an illegal action and raises an exception' do
-
-> do
-
1
ActionSender.send_action(@connection, @match_state, 'illegal action format')
-
1
end.must_raise ActionSender::IllegalActionFormat
-
end
-
1
it 'raises an exception if the given match state does not have the proper format' do
-
-> do
-
1
ActionSender.send_action(@connection, 'illegal match state format', PokerAction::CALL)
-
1
end.must_raise MatchState::IncompleteMatchState
-
end
-
1
it 'can send all legal actions through the provided connection without a modifier' do
-
1
PokerAction::ACTIONS.each do |action|
-
5
action_that_should_be_sent = @match_state.to_s + ":#{action}"
-
5
@connection.expect :write, nil, [action_that_should_be_sent]
-
-
5
ActionSender.send_action @connection, @match_state, action
-
end
-
end
-
1
it 'does not send legal unmodifiable actions that have a modifier and raises an exception' do
-
1
(PokerAction::ACTIONS - PokerAction::MODIFIABLE_ACTIONS).each do |unmodifiable_action|
-
-> do
-
3
ActionSender.send_action(@connection, @match_state, unmodifiable_action + 9001.to_s)
-
3
end.must_raise ActionSender::IllegalActionFormat
-
end
-
end
-
1
it 'can send all legal modifiable actions through the provided connection with a modifier' do
-
1
PokerAction::MODIFIABLE_ACTIONS.each do |action|
-
2
arbitrary_modifier = 9001
-
2
action_string = action + arbitrary_modifier.to_s
-
2
action_that_should_be_sent = @match_state.to_s + ":#{action_string}"
-
2
@connection.expect :write, nil, [action_that_should_be_sent]
-
-
2
ActionSender.send_action @connection, @match_state, action_string
-
end
-
end
-
1
it 'works for all test data examples' do
-
1
match_logs.each do |log_description|
-
4
match = AcpcDealerData::PokerMatchData.parse_files(
-
log_description.actions_file_path,
-
log_description.results_file_path,
-
log_description.player_names,
-
AcpcDealer::DEALER_DIRECTORY,
-
60
-
)
-
4
match.for_every_seat! do |seat|
-
10
match.for_every_hand! do
-
600
match.for_every_turn! do
-
6811
next unless match.current_hand.next_action
-
-
6211
from_player_message = match.current_hand.next_action.state
-
6211
seat_taking_action = match.current_hand.next_action.seat
-
6211
action = match.current_hand.next_action.action
-
-
6211
action_that_should_be_sent = "#{from_player_message.to_s}:#{action.to_acpc}"
-
-
6211
@connection.expect :write, nil, [action_that_should_be_sent]
-
-
6211
ActionSender.send_action @connection, from_player_message, action
-
end
-
end
-
end
-
end
-
end
-
end
-
end
-
-
1
require_relative 'support/spec_helper'
-
-
1
require 'acpc_poker_types/match_state'
-
1
require 'acpc_poker_types/poker_action'
-
1
require 'acpc_poker_types/acpc_dealer_data/poker_match_data'
-
1
require 'acpc_dealer'
-
-
1
require 'acpc_poker_basic_proxy/basic_proxy'
-
1
require 'acpc_poker_basic_proxy/communication_logic/action_sender'
-
-
1
include AcpcPokerBasicProxy
-
1
include AcpcPokerTypes
-
1
include CommunicationLogic
-
1
include AcpcDealerData
-
-
1
describe BasicProxy do
-
1
before(:each) do
-
2
port_number = 9001
-
2
host_name = 'localhost'
-
2
millisecond_response_timeout = 0
-
2
delaer_info = AcpcDealerInformation.new host_name, port_number, millisecond_response_timeout
-
2
@dealer_communicator = mock 'AcpcDealerCommunicator'
-
-
2
AcpcDealerCommunicator.expects(:new).once.with(port_number, host_name, millisecond_response_timeout).returns(@dealer_communicator)
-
-
2
@patient = BasicProxy.new delaer_info
-
end
-
-
1
it 'given a sequence of match states and actions, it properly sends and receives them' do
-
1
match_logs.each do |log_description|
-
4
match = PokerMatchData.parse_files(
-
log_description.actions_file_path,
-
log_description.results_file_path,
-
log_description.player_names,
-
AcpcDealer::DEALER_DIRECTORY,
-
10
-
)
-
4
match.for_every_seat! do |seat|
-
10
match.for_every_hand! do
-
100
match.for_every_turn! do
-
1232
action = if match.current_hand.next_action
-
1132
match.current_hand.next_action.action
-
else
-
100
nil
-
end
-
1232
match_state = match.current_hand.current_match_state
-
-
1232
@dealer_communicator.stubs(:gets).returns(match_state.to_s)
-
-
1232
@patient.receive_match_state!.must_equal match_state
-
-
1232
if action && match_state == match.current_hand.next_action.state && match.current_hand.next_action.seat == seat
-
-
431
ActionSender.expects(:send_action).once.with(@dealer_communicator, match_state.to_s, action)
-
-
431
@patient.send_action(action)
-
end
-
end
-
end
-
end
-
end
-
end
-
-
1
describe '#send_action' do
-
1
it 'raises an exception if a match state was not received before an action was sent' do
-
2
-> {@patient.send_action(mock('PokerAction'))}.must_raise BasicProxy::InitialMatchStateNotYetReceived
-
end
-
end
-
end
-
-
1
require_relative 'support/spec_helper'
-
-
1
require 'acpc_dealer'
-
1
require 'acpc_poker_types'
-
-
1
require 'acpc_poker_basic_proxy/communication_logic/match_state_receiver'
-
1
require 'acpc_poker_basic_proxy/communication_logic/acpc_dealer_communicator'
-
-
1
describe AcpcPokerBasicProxy::CommunicationLogic::MatchStateReceiver do
-
1
before(:each) do
-
1
@connection = MiniTest::Mock.new
-
end
-
-
1
describe "#receive_matchstate_string" do
-
1
it 'receives matchstate strings properly' do
-
1
match_logs.each do |log_description|
-
4
match = AcpcPokerTypes::AcpcDealerData::PokerMatchData.parse_files(
-
log_description.actions_file_path,
-
log_description.results_file_path,
-
log_description.player_names,
-
AcpcDealer::DEALER_DIRECTORY,
-
60
-
)
-
4
match.for_every_seat! do |seat|
-
10
match.for_every_hand! do
-
600
match.for_every_turn! do
-
6811
@connection.expect(:gets, match.current_hand.current_match_state.to_s)
-
-
AcpcPokerBasicProxy::CommunicationLogic::MatchStateReceiver
-
6811
.receive_match_state(@connection).must_equal match.current_hand.current_match_state
-
end
-
end
-
end
-
end
-
end
-
end
-
end