Files
galaxy-game/pkg/game/command_test.go
T
Ilia Denisov 04fc96dc8f commands A, W
2025-09-30 20:44:10 +03:00

71 lines
1.8 KiB
Go

package game_test
import (
"testing"
"github.com/iliadenisov/galaxy/pkg/game"
mg "github.com/iliadenisov/galaxy/pkg/model/game"
"github.com/stretchr/testify/assert"
)
func TestDeclarePeaceAndWarSingle(t *testing.T) {
g(t, func(f func(*game.Param), g func() mg.Game) {
hostRace := "race_05"
opponentRace := "race_01"
r, err := g().Relation(hostRace, opponentRace)
assert.NoError(t, err)
assert.Equal(t, mg.RelationWar, r.Relation)
assert.NoError(t, game.DeclarePeace(f, hostRace, opponentRace))
r, err = g().Relation(hostRace, opponentRace)
assert.NoError(t, err)
assert.Equal(t, mg.RelationPeace, r.Relation)
assert.NoError(t, game.DeclareWar(f, hostRace, opponentRace))
r, err = g().Relation(hostRace, opponentRace)
assert.NoError(t, err)
assert.Equal(t, mg.RelationWar, r.Relation)
})
}
func TestDeclarePeaceAndWarAll(t *testing.T) {
g(t, func(f func(*game.Param), g func() mg.Game) {
hostRace := "race_07"
for i := range testRaceCount {
opponentRace := raceNum(i)
if opponentRace == hostRace {
continue
}
r, err := g().Relation(hostRace, opponentRace)
assert.NoError(t, err)
assert.Equal(t, mg.RelationWar, r.Relation)
}
assert.NoError(t, game.DeclarePeace(f, hostRace, hostRace))
for i := range testRaceCount {
opponentRace := raceNum(i)
if opponentRace == hostRace {
continue
}
r, err := g().Relation(hostRace, opponentRace)
assert.NoError(t, err)
assert.Equal(t, mg.RelationPeace, r.Relation)
}
assert.NoError(t, game.DeclareWar(f, hostRace, hostRace))
for i := range testRaceCount {
opponentRace := raceNum(i)
if opponentRace == hostRace {
continue
}
r, err := g().Relation(hostRace, opponentRace)
assert.NoError(t, err)
assert.Equal(t, mg.RelationWar, r.Relation)
}
})
}