feat: enroute groups
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package controller_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/iliadenisov/galaxy/internal/controller"
|
||||
"github.com/iliadenisov/galaxy/internal/model/game"
|
||||
"github.com/iliadenisov/galaxy/internal/repo"
|
||||
"github.com/iliadenisov/galaxy/internal/util"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewGame(t *testing.T) {
|
||||
root, cleanup := util.CreateWorkDir(t)
|
||||
defer cleanup()
|
||||
|
||||
r, err := repo.NewFileRepo(root)
|
||||
assert.NoError(t, err)
|
||||
|
||||
players := 20
|
||||
races := make([]string, players)
|
||||
for i := range players {
|
||||
races[i] = fmt.Sprintf("race_%02d", i)
|
||||
}
|
||||
assert.NoError(t, r.Lock())
|
||||
gameID, err := controller.NewGame(r, races)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.FileExists(t, filepath.Join(root, "state.json"))
|
||||
assert.FileExists(t, filepath.Join(root, "0000/state.json"))
|
||||
|
||||
g, err := r.LoadState()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, gameID, g.ID)
|
||||
assert.Equal(t, uint(0), g.Age)
|
||||
assert.Equal(t, players, len(g.Race))
|
||||
|
||||
for r := range g.Race {
|
||||
assert.NotEqual(t, uuid.Nil, g.Race[r].ID)
|
||||
assert.Equal(t, players-1, len(g.Race[r].Relations))
|
||||
for i := range g.Race[r].Relations {
|
||||
assert.NotEqual(t, uuid.Nil, g.Race[r].Relations[i].RaceID)
|
||||
if g.Race[r].Relations[i].RaceID == g.Race[r].ID {
|
||||
assert.Fail(t, "race relation with itself")
|
||||
}
|
||||
assert.Equal(t, game.RelationWar, g.Race[r].Relations[i].Relation)
|
||||
}
|
||||
}
|
||||
|
||||
numShuffled := false
|
||||
for i := range g.Map.Planet {
|
||||
numShuffled = numShuffled || g.Map.Planet[i].Number != uint(i)
|
||||
}
|
||||
assert.True(t, numShuffled)
|
||||
|
||||
assert.NoError(t, r.Release())
|
||||
}
|
||||
Reference in New Issue
Block a user