towards generation
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package game_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/iliadenisov/galaxy/pkg/game"
|
||||
)
|
||||
|
||||
func Test_ShipType(t *testing.T) {
|
||||
Gunship := game.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 := game.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 := 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)
|
||||
|
||||
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 := game.ShipType{
|
||||
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,
|
||||
}
|
||||
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 := game.ShipType{
|
||||
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()
|
||||
if result != expectedBombingPower {
|
||||
t.Errorf("expected BombingPower=%.3f but %.3f given", expectedBombingPower, result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user