Files
galaxy-game/internal/controller/ship_group_upgrade_test.go
T
2026-01-15 14:42:04 +02:00

68 lines
2.6 KiB
Go

package controller_test
import (
"slices"
"testing"
e "github.com/iliadenisov/galaxy/internal/error"
"github.com/iliadenisov/galaxy/internal/model/game"
"github.com/stretchr/testify/assert"
)
func TestUpgradeGroup(t *testing.T) {
c, g := newCache()
// group #1 - in_orbit, free to upgrade
assert.NoError(t, c.CreateShips(Race_0_idx, ShipType_Cruiser, R0_Planet_0_num, 10))
// group #2 - in_space
assert.NoError(t, c.CreateShips(Race_0_idx, ShipType_Cruiser, R0_Planet_0_num, 1))
c.ShipGroup(1).StateInSpace = &game.InSpace{Origin: 2, Range: 1.23}
// group #3 - in_orbit, foreign planet
assert.NoError(t, c.CreateShips(Race_0_idx, ShipType_Cruiser, R0_Planet_0_num, 1))
c.ShipGroup(2).Destination = R1_Planet_1_num
assert.ErrorContains(t,
g.UpgradeGroup("UnknownRace", 1, "DRIVE", 0, 0),
e.GenericErrorText(e.ErrInputUnknownRace))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 555, "DRIVE", 0, 0),
e.GenericErrorText(e.ErrInputEntityNotExists))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 2, "DRIVE", 0, 0),
e.GenericErrorText(e.ErrShipsBusy))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 3, "DRIVE", 0, 0),
e.GenericErrorText(e.ErrInputEntityNotOwned))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 1, "GUN", 0, 0),
e.GenericErrorText(e.ErrInputTechUnknown))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 1, "CARGO", 0, 0),
e.GenericErrorText(e.ErrInputUpgradeShipTechNotUsed))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 1, "ALL", 0, 2.0),
e.GenericErrorText(e.ErrInputUpgradeParameterNotAllowed))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 1, "DRIVE", 0, 2.0),
e.GenericErrorText(e.ErrInputUpgradeTechLevelInsufficient))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 1, "DRIVE", 0, 1.1),
e.GenericErrorText(e.ErrInputUpgradeShipsAlreadyUpToDate))
c.RaceTechLevel(Race_0_idx, game.TechDrive, 10.0)
assert.Equal(t, 10.0, c.Race(Race_0_idx).TechLevel(game.TechDrive))
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 1, "DRIVE", 0, 10.0),
e.GenericErrorText(e.ErrUpgradeInsufficientResources))
assert.NoError(t, g.UpgradeGroup(Race_0.Name, 1, "DRIVE", 2, 1.2))
assert.Len(t, slices.Collect(c.RaceShipGroups(Race_0_idx)), 4)
assert.Equal(t, uint(8), c.ShipGroup(0).Number)
assert.Equal(t, uint(2), c.ShipGroup(3).Number)
assert.Equal(t, game.StateInOrbit, c.ShipGroup(0).State())
assert.Equal(t, game.StateUpgrade, c.ShipGroup(3).State())
assert.ErrorContains(t,
g.UpgradeGroup(Race_0.Name, 4, "DRIVE", 1, 1.3),
e.GenericErrorText(e.ErrInputUpgradeGroupBreakNotAllowed))
}