commit c320f992377c35e23a02ed4861cdfc9c71d307d2
parent dfa5ecbdb7482f5c3ea5a6b1fe7c6382da1645a3
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 8 Dec 2023 16:12:25 -0500
cleanup
Diffstat:
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -258,13 +258,17 @@ func isRoundSettled(players []*PokerPlayer) bool {
func (g *PokerGame) incrDealerIdx() {
nbPlayers := len(g.Ongoing.Players)
dealerIdx := g.DealerIdx.Load()
- dealerIdx = (dealerIdx + 1) % int32(nbPlayers)
+ dealerIdx = incrDealerIdx(dealerIdx, nbPlayers)
g.DealerIdx.Store(dealerIdx)
g.smallBlindIdx = (int(dealerIdx) + 1) % nbPlayers
g.bigBlindIdx = (int(dealerIdx) + 2) % nbPlayers
g.underTheGunIdx = (int(dealerIdx) + 3) % nbPlayers
}
+func incrDealerIdx(dealerIdx int32, nbPlayers int) int32 {
+ return (dealerIdx + 1) % int32(nbPlayers)
+}
+
func (g *PokerGame) UnSitPlayer(authUser *database.User) error {
found := false
g.PlayersMtx.Lock()
diff --git a/pkg/web/handlers/poker/poker_test.go b/pkg/web/handlers/poker/poker_test.go
@@ -127,3 +127,25 @@ func Test_isRoundSettled(t *testing.T) {
})
}
}
+
+func Test_incrDealerIdx(t *testing.T) {
+ type args struct {
+ dealerIdx int32
+ nbPlayers int
+ }
+ tests := []struct {
+ name string
+ args args
+ want int32
+ }{
+ {"1", args{-1, 3}, 0},
+ {"1", args{0, 3}, 1},
+ {"1", args{1, 3}, 2},
+ {"1", args{2, 3}, 0},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assert.Equalf(t, tt.want, incrDealerIdx(tt.args.dealerIdx, tt.args.nbPlayers), "incrDealerIdx(%v, %v)", tt.args.dealerIdx, tt.args.nbPlayers)
+ })
+ }
+}