test no players/users and shuffle
parent
bc3f0271e7
commit
5ef0dde50d
|
|
@ -205,6 +205,7 @@ func (v01 *V01) serveGMShuffle(w http.ResponseWriter, r *http.Request) {
|
||||||
poolSize = altSize
|
poolSize = altSize
|
||||||
}
|
}
|
||||||
pool := make([]int, poolSize)
|
pool := make([]int, poolSize)
|
||||||
|
if poolSize > 0 {
|
||||||
for i := range v01.cfg.Players {
|
for i := range v01.cfg.Players {
|
||||||
pool[i] = i + 1
|
pool[i] = i + 1
|
||||||
}
|
}
|
||||||
|
|
@ -213,6 +214,7 @@ func (v01 *V01) serveGMShuffle(w http.ResponseWriter, r *http.Request) {
|
||||||
r := rand.Int() % poolSize
|
r := rand.Int() % poolSize
|
||||||
pool[l], pool[r] = pool[r], pool[l]
|
pool[l], pool[r] = pool[r], pool[l]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
i := 0
|
i := 0
|
||||||
msg := []string{}
|
msg := []string{}
|
||||||
for k, v := range v01.cfg.Users {
|
for k, v := range v01.cfg.Users {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -205,7 +206,7 @@ func TestServeGM(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("shuffle", func(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)
|
v01 := NewV01(ctx, nil)
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
v01.cfg.Quiet = true
|
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) {
|
t.Run("swap", func(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue