refactor: game funcs moved to controller
This commit is contained in:
@@ -9,108 +9,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBlockUpgradeCost(t *testing.T) {
|
||||
assert.Equal(t, 00.0, game.BlockUpgradeCost(1, 1.0, 1.0))
|
||||
assert.Equal(t, 25.0, game.BlockUpgradeCost(5, 1.0, 2.0))
|
||||
assert.Equal(t, 50.0, game.BlockUpgradeCost(10, 1.0, 2.0))
|
||||
}
|
||||
|
||||
func TestGroupUpgradeCost(t *testing.T) {
|
||||
sg := game.ShipGroup{
|
||||
Tech: map[game.Tech]float64{
|
||||
game.TechDrive: 1.0,
|
||||
game.TechWeapons: 1.0,
|
||||
game.TechShields: 1.0,
|
||||
game.TechCargo: 1.0,
|
||||
},
|
||||
Number: 1,
|
||||
}
|
||||
assert.Equal(t, 225.0, game.GroupUpgradeCost(sg, Cruiser, 2.0, 2.0, 2.0, 2.0).UpgradeCost(1))
|
||||
}
|
||||
|
||||
func TestUpgradeMaxShips(t *testing.T) {
|
||||
sg := game.ShipGroup{
|
||||
Tech: map[game.Tech]float64{
|
||||
game.TechDrive: 1.0,
|
||||
game.TechWeapons: 1.0,
|
||||
game.TechShields: 1.0,
|
||||
game.TechCargo: 1.0,
|
||||
},
|
||||
Number: 10,
|
||||
}
|
||||
uc := game.GroupUpgradeCost(sg, Cruiser, 2.0, 2.0, 2.0, 2.0)
|
||||
assert.Equal(t, uint(4), uc.UpgradeMaxShips(1000))
|
||||
}
|
||||
|
||||
func TestCurrentUpgradingLevel(t *testing.T) {
|
||||
sg := &game.ShipGroup{
|
||||
StateUpgrade: nil,
|
||||
}
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechDrive))
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechWeapons))
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechShields))
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechCargo))
|
||||
|
||||
sg.StateUpgrade = &game.InUpgrade{
|
||||
UpgradeTech: []game.UpgradePreference{
|
||||
{Tech: game.TechDrive, Level: 1.5, Cost: 100.1},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, 1.5, game.CurrentUpgradingLevel(*sg, game.TechDrive))
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechWeapons))
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechShields))
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechCargo))
|
||||
|
||||
sg.StateUpgrade.UpgradeTech = append(sg.StateUpgrade.UpgradeTech, game.UpgradePreference{Tech: game.TechCargo, Level: 2.2, Cost: 200.2})
|
||||
assert.Equal(t, 1.5, game.CurrentUpgradingLevel(*sg, game.TechDrive))
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechWeapons))
|
||||
assert.Equal(t, 0.0, game.CurrentUpgradingLevel(*sg, game.TechShields))
|
||||
assert.Equal(t, 2.2, game.CurrentUpgradingLevel(*sg, game.TechCargo))
|
||||
}
|
||||
|
||||
func TestFutureUpgradeLevel(t *testing.T) {
|
||||
assert.Equal(t, 0.0, game.FutureUpgradeLevel(2.0, 2.0, 2.0))
|
||||
assert.Equal(t, 0.0, game.FutureUpgradeLevel(2.0, 2.0, 3.0))
|
||||
assert.Equal(t, 1.5, game.FutureUpgradeLevel(1.5, 2.0, 3.0))
|
||||
assert.Equal(t, 2.0, game.FutureUpgradeLevel(2.5, 1.0, 2.0))
|
||||
assert.Equal(t, 2.5, game.FutureUpgradeLevel(2.5, 1.0, 0.0))
|
||||
}
|
||||
|
||||
// func TestUpgradeGroupPreference(t *testing.T) {
|
||||
// sg := game.ShipGroup{
|
||||
// Number: 4,
|
||||
// Tech: game.TechSet{
|
||||
// game.TechDrive: 1.0,
|
||||
// game.TechWeapons: 1.0,
|
||||
// game.TechShields: 1.0,
|
||||
// game.TechCargo: 1.0,
|
||||
// },
|
||||
// }
|
||||
// assert.Nil(t, sg.StateUpgrade)
|
||||
// sg = game.UpgradeGroupPreference(sg, Cruiser, game.TechDrive, 0)
|
||||
// assert.Nil(t, sg.StateUpgrade)
|
||||
|
||||
// sg = game.UpgradeGroupPreference(sg, Cruiser, game.TechDrive, 2.0)
|
||||
// assert.NotNil(t, sg.StateUpgrade)
|
||||
// assert.Equal(t, 300., sg.StateUpgrade.TechCost(game.TechDrive))
|
||||
// assert.Equal(t, 300., sg.StateUpgrade.Cost())
|
||||
|
||||
// sg = game.UpgradeGroupPreference(sg, Cruiser, game.TechWeapons, 2.0)
|
||||
// assert.NotNil(t, sg.StateUpgrade)
|
||||
// assert.Equal(t, 300., sg.StateUpgrade.TechCost(game.TechWeapons))
|
||||
// assert.Equal(t, 600., sg.StateUpgrade.Cost())
|
||||
|
||||
// sg = game.UpgradeGroupPreference(sg, Cruiser, game.TechShields, 2.0)
|
||||
// assert.NotNil(t, sg.StateUpgrade)
|
||||
// assert.Equal(t, 300., sg.StateUpgrade.TechCost(game.TechShields))
|
||||
// assert.Equal(t, 900., sg.StateUpgrade.Cost())
|
||||
|
||||
// sg = game.UpgradeGroupPreference(sg, Cruiser, game.TechCargo, 2.0)
|
||||
// assert.NotNil(t, sg.StateUpgrade)
|
||||
// assert.Equal(t, 0., sg.StateUpgrade.TechCost(game.TechCargo))
|
||||
// assert.Equal(t, 900., sg.StateUpgrade.Cost())
|
||||
// }
|
||||
|
||||
func TestUpgradeGroup(t *testing.T) {
|
||||
c, g := newCache()
|
||||
// group #1 - in_orbit, free to upgrade
|
||||
@@ -150,15 +48,14 @@ func TestUpgradeGroup(t *testing.T) {
|
||||
g.UpgradeGroup(Race_0.Name, 1, "DRIVE", 0, 1.1),
|
||||
e.GenericErrorText(e.ErrInputUpgradeShipsAlreadyUpToDate))
|
||||
|
||||
// g.Race[Race_0_idx].SetTechLevel(game.TechDrive, 10.0)
|
||||
c.RacetTechLevel(Race_0_idx, game.TechDrive, 10.0)
|
||||
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.ListShipGroups(Race_0_idx)), 4)
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user