-
Notifications
You must be signed in to change notification settings - Fork 2
/
integration_spec.rb
75 lines (47 loc) · 2.35 KB
/
integration_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require_relative 'spec_helper'
module PokerEngine
describe 'Test in integration' do
let(:players) do
[
{ id: 0, balance: 1000 },
{ id: 1, balance: 400 },
{ id: 2, balance: 900 },
].freeze
end
it 'plays poker game with many stages' do
events_queue = []
handler = ->(action, _state) { events_queue << action }
state = Game.start players, small_blind: 10, big_blind: 20, deck_seed: 2, &handler
expect(state[:players][0][:cards].count).to eq 2
expect(events_queue.last).to eq(type: :move_request, player_id: 0)
state = Game.next state, type: :raise, bet: 60, player_id: 0, &handler
expect(events_queue.last).to eq(type: :move_request, player_id: 1)
state = Game.next state, type: :call, player_id: 1, &handler
expect(events_queue.last).to eq(type: :move_request, player_id: 2)
state = Game.next state, type: :raise, bet: 150, player_id: 2, &handler
expect(events_queue.last).to eq(type: :move_request, player_id: 0)
state = Game.next state, type: :call, player_id: 0, &handler
expect(events_queue.last).to eq(type: :move_request, player_id: 1)
expect(state[:board].count).to be_zero
state = Game.next state, type: :fold, player_id: 1, &handler
expect(state[:board].count).to eq 3
expect(state[:pot]).to eq(360)
expect(events_queue.last).to eq(type: :move_request, player_id: 2)
state = Game.next state, type: :raise, bet: 150, player_id: 2, &handler
expect(events_queue.last).to eq(type: :move_request, player_id: 0)
state = Game.next state, type: :call, player_id: 0, &handler
expect(state[:board].count).to eq 4
expect(state[:pot]).to eq 660
expect(events_queue.last).to eq(type: :move_request, player_id: 2)
state = Game.next state, type: :check, player_id: 2, &handler
expect(events_queue.last).to eq(type: :move_request, player_id: 0)
state = Game.next state, type: :check, player_id: 0, &handler
expect(state[:board].count).to eq 5
state = Game.next state, type: :check, player_id: 2, &handler
expect(events_queue.last).to eq(type: :move_request, player_id: 0)
state = Game.next state, type: :check, player_id: 0, &handler
expect(state[:winner_ids]).to contain_exactly 1
expect(state[:top_hands].count).to eq 3
end
end
end