106 lines
2.0 KiB
Go
106 lines
2.0 KiB
Go
package server_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/iliadenisov/galaxy/pkg/server"
|
|
)
|
|
|
|
func Test_ShipType(t *testing.T) {
|
|
Gunship := server.ShipType{
|
|
Drive: 4,
|
|
Armament: 2,
|
|
Weapons: 2,
|
|
Shields: 4,
|
|
Cargo: 0,
|
|
}
|
|
|
|
if Gunship.EmptyMass() != 11. {
|
|
t.Errorf("Cruiser mass expected %.3f but %.3f given", 11., Gunship.EmptyMass())
|
|
}
|
|
|
|
Cruiser := server.ShipType{
|
|
Drive: 15,
|
|
Armament: 1,
|
|
Weapons: 15,
|
|
Shields: 15,
|
|
Cargo: 0,
|
|
}
|
|
|
|
if Cruiser.EmptyMass() != 45. {
|
|
t.Errorf("Cruiser mass expected %.3f but %.3f given", 45., Cruiser.EmptyMass())
|
|
}
|
|
|
|
sg := server.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)
|
|
|
|
if upgradeCost != 225. {
|
|
t.Errorf("Cruiser upgrade cost expected %.3f but %.3f given", 225., upgradeCost)
|
|
}
|
|
}
|
|
|
|
func Test_CargoCapacity(t *testing.T) {
|
|
test := func(cargoSize float64, expectCapacity float64) {
|
|
ship := server.ShipType{
|
|
Drive: 1,
|
|
Armament: 1,
|
|
Weapons: 1,
|
|
Shields: 1,
|
|
Cargo: cargoSize,
|
|
}
|
|
sg := server.ShipGroup{
|
|
Type: ship,
|
|
Number: 1,
|
|
State: "In_Orbit",
|
|
Drive: 1.0,
|
|
Weapons: 1.0,
|
|
Shields: 1.0,
|
|
Cargo: 1.0,
|
|
}
|
|
if sg.CargoCapacity() != expectCapacity {
|
|
t.Errorf("expected CargoCapacity=%.3f but %.3f given", expectCapacity, sg.CargoCapacity())
|
|
}
|
|
}
|
|
test(1, 1.05)
|
|
test(5, 6.25)
|
|
test(10, 15)
|
|
test(50, 175)
|
|
test(100, 600)
|
|
}
|
|
|
|
func Test_BombingPower(t *testing.T) {
|
|
Gunship := server.ShipType{
|
|
Drive: 60.0,
|
|
Armament: 3,
|
|
Weapons: 30.0,
|
|
Shields: 100.0,
|
|
Cargo: 0.0,
|
|
}
|
|
sg := server.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()
|
|
if result != expectedBombingPower {
|
|
t.Errorf("expected BombingPower=%.3f but %.3f given", expectedBombingPower, result)
|
|
}
|
|
}
|