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
|
package casino
import "testing"
func TestCrapsTakenDownRollDoesNotCarryIntoNewBet(t *testing.T) {
tb := crapsFixture()
tb.join("alice")
w := &testWallet{chips: 100}
tb.bet("alice", "field", 10, w)
tb.action("alice", "roll")
tb.tick()
tb.action("alice", "unbet")
if tb.pendingRollTicks != 0 {
t.Fatal("taking down the last bet did not cancel the pending roll")
}
tb.bet("alice", "field", 10, w)
tb.advance(10)
if tb.dice != [2]int{} || !tb.hasLiveBets() {
t.Fatal("new wager inherited a canceled roll")
}
tb.action("alice", "roll")
tb.advance(crapsManualRollTicks)
if tb.dice == [2]int{} || tb.hasLiveBets() {
t.Fatal("fresh manual roll did not settle")
}
}
func TestSimplifiedCrapsDeparturePreservesCountdown(t *testing.T) {
for _, departing := range []string{"alice", "bob"} {
t.Run(departing, func(t *testing.T) {
tb := variantFixture("simplified")
tb.join("alice")
tb.join("bob")
tb.join("carol")
tb.bet("carol", "pass", 10, &testWallet{chips: 100})
tb.tick()
tb.leave(departing)
if tb.countdown != 1 || tb.view().ShootIn != 2 {
t.Fatal("departure reset the shared countdown")
}
events := tb.tick()
if len(events) != 1 || tb.countdown != 2 {
t.Fatal("countdown repeated after departure", events)
}
tb.tick()
if tb.dice == [2]int{} || tb.hasLiveBets() {
t.Fatal("shared roll did not settle on schedule")
}
})
}
}
|