Files
galaxy-game/pkg/model/game/ship_test.go
T
2025-10-02 02:05:00 +03:00

115 lines
2.1 KiB
Go

package game_test
import (
"testing"
"github.com/iliadenisov/galaxy/pkg/model/game"
"github.com/stretchr/testify/assert"
)
func TestShipType(t *testing.T) {
Freighter := game.ShipType{
ShipTypeReport: game.ShipTypeReport{
Name: "Freighter",
Drive: 8,
Armament: 0,
Weapons: 0,
Shields: 2,
Cargo: 10,
},
}
assert.Equal(t, 20., Freighter.EmptyMass())
Gunship := game.ShipType{
ShipTypeReport: game.ShipTypeReport{
Name: "Gunship",
Drive: 4,
Armament: 2,
Weapons: 2,
Shields: 4,
Cargo: 0,
},
}
assert.Equal(t, 11., Gunship.EmptyMass())
Cruiser := game.ShipType{
ShipTypeReport: game.ShipTypeReport{
Name: "Cruiser",
Drive: 15,
Armament: 1,
Weapons: 15,
Shields: 15,
Cargo: 0,
},
}
assert.Equal(t, 45., Cruiser.EmptyMass())
sg := game.ShipGroup{
Type: Cruiser,
Number: 1,
State: "In_Orbit",
Drive: 1.0,
Weapons: 1.0,
Shields: 1.0,
Cargo: 1.0,
}
upgradeCost := sg.UpgradeDriveCost(2.0) +
sg.UpgradeWeaponsCost(2.0) +
sg.UpgradeShieldsCost(2.0) +
sg.UpgradeCargoCost(2.0)
assert.Equal(t, 225., upgradeCost)
}
func TestCargoCapacity(t *testing.T) {
test := func(cargoSize float64, expectCapacity float64) {
ship := game.ShipType{
ShipTypeReport: game.ShipTypeReport{
Drive: 1,
Armament: 1,
Weapons: 1,
Shields: 1,
Cargo: cargoSize,
},
}
sg := game.ShipGroup{
Type: ship,
Number: 1,
State: "In_Orbit",
Drive: 1.0,
Weapons: 1.0,
Shields: 1.0,
Cargo: 1.0,
}
assert.Equal(t, expectCapacity, sg.CargoCapacity())
}
test(1, 1.05)
test(5, 6.25)
test(10, 15)
test(50, 175)
test(100, 600)
}
func TestBombingPower(t *testing.T) {
Gunship := game.ShipType{
ShipTypeReport: game.ShipTypeReport{
Drive: 60.0,
Armament: 3,
Weapons: 30.0,
Shields: 100.0,
Cargo: 0.0,
},
}
sg := game.ShipGroup{
Type: Gunship,
Number: 1,
State: "In_Orbit",
Drive: 1.0,
Weapons: 1.0,
Shields: 1.0,
Cargo: 1.0,
}
expectedBombingPower := 139.295
result := sg.BombingPower()
assert.Equal(t, expectedBombingPower, result)
}