test no players/users and shuffle
parent
bc3f0271e7
commit
5ef0dde50d
|
|
@ -205,13 +205,15 @@ func (v01 *V01) serveGMShuffle(w http.ResponseWriter, r *http.Request) {
|
|||
poolSize = altSize
|
||||
}
|
||||
pool := make([]int, poolSize)
|
||||
for i := range v01.cfg.Players {
|
||||
pool[i] = i + 1
|
||||
}
|
||||
for i := 0; i < 30; i++ {
|
||||
l := rand.Int() % poolSize
|
||||
r := rand.Int() % poolSize
|
||||
pool[l], pool[r] = pool[r], pool[l]
|
||||
if poolSize > 0 {
|
||||
for i := range v01.cfg.Players {
|
||||
pool[i] = i + 1
|
||||
}
|
||||
for i := 0; i < 30; i++ {
|
||||
l := rand.Int() % poolSize
|
||||
r := rand.Int() % poolSize
|
||||
pool[l], pool[r] = pool[r], pool[l]
|
||||
}
|
||||
}
|
||||
i := 0
|
||||
msg := []string{}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
|
@ -205,7 +206,7 @@ func TestServeGM(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("shuffle", func(t *testing.T) {
|
||||
t.Run("2u 2p", func(t *testing.T) {
|
||||
t.Run("many 2u 2p", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
for i := 0; i < 100; i++ {
|
||||
v01.cfg.Quiet = true
|
||||
|
|
@ -231,6 +232,55 @@ func TestServeGM(t *testing.T) {
|
|||
}
|
||||
}
|
||||
})
|
||||
|
||||
cases := map[string]struct {
|
||||
users int
|
||||
usersAssigned int
|
||||
players int
|
||||
}{
|
||||
"empty": {},
|
||||
}
|
||||
|
||||
for name, d := range cases {
|
||||
c := d
|
||||
t.Run(name, func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
v01.cfg.Quiet = true
|
||||
v01.cfg.Users = map[string]configUser{}
|
||||
for i := 0; i < c.users; i++ {
|
||||
v01.cfg.Users[strconv.Itoa(i)] = configUser{}
|
||||
if i < c.usersAssigned {
|
||||
v01.cfg.Users[strconv.Itoa(i)] = configUser{Player: i}
|
||||
}
|
||||
}
|
||||
v01.cfg.Players = make([]configPlayer, c.players)
|
||||
|
||||
do(v01, "/gm/rpc/shuffle", "")
|
||||
if v01.cfg.Quiet {
|
||||
t.Error(v01.cfg.Quiet)
|
||||
}
|
||||
|
||||
if len(v01.cfg.Users) != c.users+1 {
|
||||
t.Error(v01.cfg.Users)
|
||||
} else if len(v01.cfg.Players) != c.players {
|
||||
t.Error(v01.cfg.Users)
|
||||
}
|
||||
for i := 0; i < c.users; i++ {
|
||||
if _, ok := v01.cfg.Users[strconv.Itoa(i)]; !ok {
|
||||
t.Error(i)
|
||||
}
|
||||
}
|
||||
assignments := map[int]struct{}{}
|
||||
for _, v := range v01.cfg.Users {
|
||||
if v.Player > 0 {
|
||||
assignments[v.Player] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(assignments) != c.usersAssigned {
|
||||
t.Error(assignments)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("swap", func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue