commands A, W

This commit is contained in:
Ilia Denisov
2025-09-30 20:44:10 +03:00
parent 128d6862a7
commit 04fc96dc8f
6 changed files with 179 additions and 51 deletions
+35 -9
View File
@@ -5,21 +5,47 @@ import (
"testing"
"github.com/iliadenisov/galaxy/pkg/game"
mg "github.com/iliadenisov/galaxy/pkg/model/game"
"github.com/iliadenisov/galaxy/pkg/util"
"github.com/stretchr/testify/assert"
)
const (
testRaceCount = 20
)
func raceNum(i int) string {
return fmt.Sprintf("race_%02d", i)
}
func TestComposeGame(t *testing.T) {
g(t, func(p func(*game.Param), g func() mg.Game) {
_, err := game.GenerateGame(p, []string{"r1", "r2"})
assert.Error(t, err)
assert.ErrorContains(t, err, "state for turn 0 already saved")
})
}
func g(t *testing.T, f func(func(*game.Param), func() mg.Game)) {
root, cleanup := util.CreateWorkDir(t)
defer cleanup()
players := 20
races := make([]string, players)
for i := range players {
races[i] = fmt.Sprintf("race_%02d", i)
races := make([]string, testRaceCount)
for i := range testRaceCount {
races[i] = raceNum(i)
}
_, err := game.ComposeGame(func(p *game.Param) { p.StoragePath = root }, races)
assert.NoError(t, err)
_, err = game.ComposeGame(func(p *game.Param) { p.StoragePath = root }, races)
assert.Error(t, err)
assert.ErrorContains(t, err, "state for turn 0 already saved")
p := func(p *game.Param) { p.StoragePath = root }
_, err := game.GenerateGame(p, races)
if err != nil {
assert.FailNow(t, "g: ComposeGame", err)
return
}
g := func() mg.Game {
g, err := game.LoadState(p)
if err != nil {
assert.FailNow(t, "g: LoadState", err)
return mg.Game{}
}
return g
}
f(p, g)
}