rnd: ship production numbers
This commit is contained in:
committed by
Ilia Denisov
parent
fef1be577d
commit
9088cc77c9
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/iliadenisov/galaxy/internal/controller"
|
||||
e "github.com/iliadenisov/galaxy/internal/error"
|
||||
"github.com/iliadenisov/galaxy/internal/model/game"
|
||||
"github.com/iliadenisov/galaxy/internal/number"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -166,47 +165,114 @@ func TestProduceShips(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProduceShip(t *testing.T) {
|
||||
Drone := game.ShipType{
|
||||
Name: "Drone",
|
||||
Drive: 1,
|
||||
// Drone := game.ShipType{
|
||||
// Name: "Drone",
|
||||
// Drive: 1,
|
||||
// Armament: 0,
|
||||
// Weapons: 0,
|
||||
// Shields: 0,
|
||||
// Cargo: 0,
|
||||
// }
|
||||
// BattleShip := game.ShipType{
|
||||
// Name: "BattleShip",
|
||||
// Drive: 25,
|
||||
// Armament: 1,
|
||||
// Weapons: 30,
|
||||
// Shields: 35,
|
||||
// Cargo: 0,
|
||||
// }
|
||||
TestDWShip := game.ShipType{
|
||||
Name: "DROCOLZ",
|
||||
Drive: 11.32,
|
||||
Armament: 0,
|
||||
Weapons: 0,
|
||||
Shields: 0,
|
||||
Cargo: 0,
|
||||
}
|
||||
BattleShip := game.ShipType{
|
||||
Name: "BattleShip",
|
||||
Drive: 25,
|
||||
Armament: 1,
|
||||
Weapons: 30,
|
||||
Shields: 35,
|
||||
Cargo: 0,
|
||||
Cargo: 1,
|
||||
}
|
||||
id := uuid.New()
|
||||
p := controller.NewPlanet(0, "Planet_0", &id, 1, 1, 1000, 1000, 1000, 10, game.ProductionShip.AsType(uuid.Nil))
|
||||
// p := controller.NewPlanet(0, "Planet_0", &id, 1, 1, 1000, 1000, 1000, 10, game.ProductionShip.AsType(uuid.Nil))
|
||||
|
||||
r := controller.ProduceShip(&p, p.ProductionCapacity(), Drone.EmptyMass())
|
||||
assert.Equal(t, uint(99), r)
|
||||
assert.InDelta(t, 0.0099, (*p.Production.Progress).F(), 0.000001)
|
||||
// r := controller.ProduceShip(&p, p.ProductionCapacity(), Drone.EmptyMass())
|
||||
// assert.Equal(t, uint(99), r)
|
||||
// assert.InDelta(t, 0.0099, (*p.Production.Progress).F(), 0.000001)
|
||||
|
||||
(&p).Production = game.ProductionShip.AsType(uuid.Nil)
|
||||
(&p).Capital = 10.
|
||||
r = controller.ProduceShip(&p, p.ProductionCapacity(), Drone.EmptyMass())
|
||||
assert.Equal(t, uint(100), r)
|
||||
assert.Equal(t, 0., (*p.Production.Progress).F())
|
||||
assert.Equal(t, 0., number.Fixed3(p.Capital.F())) // TODO: zero CAP is not actual '0.0' after series of decrements
|
||||
// (&p).Production = game.ProductionShip.AsType(uuid.Nil)
|
||||
// (&p).Capital = 10.
|
||||
// r = controller.ProduceShip(&p, p.ProductionCapacity(), Drone.EmptyMass())
|
||||
// assert.Equal(t, uint(100), r)
|
||||
// assert.Equal(t, 0., (*p.Production.Progress).F())
|
||||
// assert.Equal(t, 0., number.Fixed3(p.Capital.F())) // TODO: zero CAP is not actual '0.0' after series of decrements
|
||||
|
||||
(&p).Production = game.ProductionShip.AsType(uuid.Nil)
|
||||
(&p).Capital = 0.
|
||||
r = controller.ProduceShip(&p, p.ProductionCapacity(), BattleShip.EmptyMass())
|
||||
assert.Equal(t, uint(1), r)
|
||||
assert.InDelta(t, 0.1, (*p.Production.Progress).F(), 0.001)
|
||||
// (&p).Production = game.ProductionShip.AsType(uuid.Nil)
|
||||
// (&p).Capital = 0.
|
||||
// r = controller.ProduceShip(&p, p.ProductionCapacity(), BattleShip.EmptyMass())
|
||||
// assert.Equal(t, uint(1), r)
|
||||
// assert.InDelta(t, 0.1, (*p.Production.Progress).F(), 0.001)
|
||||
|
||||
(&p).Production = game.ProductionShip.AsType(uuid.Nil)
|
||||
(&p).Capital = 20.
|
||||
r = controller.ProduceShip(&p, p.ProductionCapacity(), BattleShip.EmptyMass())
|
||||
assert.Equal(t, uint(1), r)
|
||||
assert.Equal(t, 1./9., (*p.Production.Progress).F())
|
||||
// (&p).Production = game.ProductionShip.AsType(uuid.Nil)
|
||||
// (&p).Capital = 20.
|
||||
// r = controller.ProduceShip(&p, p.ProductionCapacity(), BattleShip.EmptyMass())
|
||||
// assert.Equal(t, uint(1), r)
|
||||
// assert.Equal(t, number.Fixed12(1./9.), (*p.Production.Progress).F())
|
||||
|
||||
// test "P" for report
|
||||
dw := controller.NewPlanet(0, "DW_Planet", &id, 1, 1, 500, 500, 500, 10, game.ProductionShip.AsType(uuid.Nil))
|
||||
(&dw).Material = 0.32
|
||||
r := controller.ProduceShip(&dw, dw.ProductionCapacity(), TestDWShip.EmptyMass())
|
||||
assert.Equal(t, uint(4), r)
|
||||
assert.Equal(t, 2.30, (*dw.Production.Progress).F())
|
||||
// TODO: test with insufficient production capacity
|
||||
}
|
||||
|
||||
func TestProduceShip_Research(t *testing.T) {
|
||||
TestShipCargo1 := game.ShipType{
|
||||
Name: "Cargo1",
|
||||
Drive: 30.18,
|
||||
Armament: 0,
|
||||
Weapons: 0.,
|
||||
Shields: 0.,
|
||||
Cargo: 19.,
|
||||
}
|
||||
TestShipDROCOLZ := game.ShipType{
|
||||
Name: "DROCOLZ",
|
||||
Drive: 11.32,
|
||||
Armament: 0,
|
||||
Weapons: 0,
|
||||
Shields: 0,
|
||||
Cargo: 1,
|
||||
}
|
||||
_ = TestShipDROCOLZ
|
||||
_ = TestShipCargo1
|
||||
id := uuid.New()
|
||||
dw1 := controller.NewPlanet(0, "DW2", &id, 1, 1, 500, 500, 500, 10, game.ProductionShip.AsType(uuid.Nil))
|
||||
dw2 := controller.NewPlanet(0, "DW1", &id, 1, 1, 500, 500, 500, 10, game.ProductionShip.AsType(uuid.Nil))
|
||||
_ = dw1
|
||||
|
||||
// (&dw1).Material = 0.0
|
||||
// r := controller.ProduceShip(&dw1, dw1.ProductionCapacity(), TestShipDROCOLZ.EmptyMass())
|
||||
// assert.Equal(t, uint(4), r)
|
||||
// assert.Equal(t, 2.272, (*dw1.Production.FreeProd).F())
|
||||
|
||||
// --------
|
||||
|
||||
var r uint
|
||||
|
||||
// (&dw2).Material = 0.0
|
||||
// r = controller.ProduceShip(&dw2, dw2.ProductionCapacity(), TestShipCargo1.EmptyMass())
|
||||
// assert.Equal(t, uint(1), r)
|
||||
// assert.Equal(t, 3.282, (*dw2.Production.FreeProd).F())
|
||||
|
||||
// // production stopped and extra MAT released
|
||||
// matPerShip := controller.ShipMaterialCost(TestShipCargo1.EmptyMass(), float64(dw2.Resources))
|
||||
// assert.Equal(t, 4.918, matPerShip)
|
||||
// (&dw2).Material = game.F(controller.ShipProductionCost(matPerShip * float64(*dw2.Production.Progress)))
|
||||
// assert.Equal(t, 0.32495049505, (&dw2).Material.F()) // old repoert: 0.32
|
||||
|
||||
// building new ship with extra MAT
|
||||
(&dw2).Material = game.F(0.32495049505)
|
||||
r = controller.ProduceShip(&dw2, dw2.ProductionCapacity(), TestShipDROCOLZ.EmptyMass())
|
||||
assert.Equal(t, uint(4), r)
|
||||
assert.Equal(t, 2.3, (*dw2.Production.FreeProd).F())
|
||||
|
||||
// TODO: test with insufficient production capacity
|
||||
}
|
||||
@@ -249,7 +315,7 @@ func TestTurnPlanetProductions(t *testing.T) {
|
||||
assert.Equal(t, 0.0, c.MustPlanet(R0_Planet_0_num).Colonists.F())
|
||||
c.TurnPlanetProductions()
|
||||
assert.InDelta(t, 196., c.MustPlanet(R0_Planet_0_num).Capital.F(), 0.1)
|
||||
assert.InDelta(t, 10.0, c.MustPlanet(R0_Planet_0_num).Colonists.F(), 0.000001) // FIXME: should store more exact value
|
||||
assert.Equal(t, 10.0, c.MustPlanet(R0_Planet_0_num).Colonists.F())
|
||||
|
||||
assert.NoError(t, g.PlanetProduction(Race_0.Name, pn, "MAT", ""))
|
||||
assert.Equal(t, 0.0, c.MustPlanet(R0_Planet_0_num).Material.F())
|
||||
@@ -275,7 +341,7 @@ func TestTurnPlanetProductions(t *testing.T) {
|
||||
assert.NoError(t, g.PlanetProduction(Race_0.Name, pn, "CARGO", ""))
|
||||
assert.Equal(t, 1.4, c.Race(Race_0_idx).TechLevel(game.TechCargo))
|
||||
c.TurnPlanetProductions()
|
||||
assert.InDelta(t, 1.6, c.Race(Race_0_idx).TechLevel(game.TechCargo), 0.1) // FIXME: 1.5999999999999999 -> 1.6
|
||||
assert.Equal(t, 1.6, c.Race(Race_0_idx).TechLevel(game.TechCargo))
|
||||
|
||||
assert.NoError(t, g.PlanetProduction(Race_0.Name, pn, "SCIENCE", "Equality"))
|
||||
c.TurnPlanetProductions()
|
||||
|
||||
Reference in New Issue
Block a user