refactor: floats, tests
This commit is contained in:
@@ -145,14 +145,14 @@ func TestProduceShips(t *testing.T) {
|
||||
assert.Len(t, slices.Collect(c.RaceShipGroups(Race_0_idx)), 0)
|
||||
assert.NotNil(t, c.MustPlanet(R0_Planet_0_num).Production.Progress)
|
||||
progress := *c.MustPlanet(R0_Planet_0_num).Production.Progress
|
||||
assert.InDelta(t, 0.45, progress, 0.001)
|
||||
assert.InDelta(t, 0.45, progress.F(), 0.001)
|
||||
|
||||
assert.NoError(t, c.CreateShipType(Race_0_idx, "Drone", 1, 0, 0, 0, 0))
|
||||
assert.NoError(t, c.CreateShips(Race_0_idx, "Drone", uint(pn), 7))
|
||||
assert.Len(t, slices.Collect(c.RaceShipGroups(Race_0_idx)), 1)
|
||||
assert.Equal(t, uint(7), c.ShipGroup(0).Number)
|
||||
assert.NoError(t, g.PlanetProduction(Race_0.Name, pn, "SHIP", "Drone"))
|
||||
assert.InDelta(t, shipMass*progress, c.MustPlanet(R0_Planet_0_num).Material.F(), 0.00001) // 99.(0099) material build
|
||||
assert.InDelta(t, shipMass*progress.F(), c.MustPlanet(R0_Planet_0_num).Material.F(), 0.00001) // 99.(0099) material build
|
||||
|
||||
c.MustPlanet(R0_Planet_0_num).Material = 0
|
||||
c.MustPlanet(R0_Planet_0_num).Colonists = 0
|
||||
@@ -162,7 +162,7 @@ func TestProduceShips(t *testing.T) {
|
||||
assert.Len(t, slices.Collect(c.RaceShipGroups(Race_0_idx)), 1)
|
||||
assert.Equal(t, uint(106), c.ShipGroup(0).Number)
|
||||
progress = *c.MustPlanet(R0_Planet_0_num).Production.Progress
|
||||
assert.InDelta(t, 0.0099, progress, 0.00001) // 1.(0099) drones with no CAP on planet
|
||||
assert.InDelta(t, 0.0099, progress.F(), 0.00001) // 1.(0099) drones with no CAP on planet
|
||||
}
|
||||
|
||||
func TestProduceShip(t *testing.T) {
|
||||
@@ -186,26 +186,26 @@ func TestProduceShip(t *testing.T) {
|
||||
|
||||
r := controller.ProduceShip(&p, p.ProductionCapacity(), Drone.EmptyMass())
|
||||
assert.Equal(t, uint(99), r)
|
||||
assert.InDelta(t, 0.0099, *p.Production.Progress, 0.000001)
|
||||
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)
|
||||
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, 0.001)
|
||||
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)
|
||||
assert.Equal(t, 1./9., (*p.Production.Progress).F())
|
||||
|
||||
// TODO: test with insufficient production capacity
|
||||
}
|
||||
@@ -213,6 +213,10 @@ func TestProduceShip(t *testing.T) {
|
||||
func TestListProducingPlanets(t *testing.T) {
|
||||
c, g := newCache()
|
||||
|
||||
c.MustPlanet(0).Production = game.ProductionNone.AsType(uuid.Nil)
|
||||
c.MustPlanet(1).Production = game.ProductionNone.AsType(uuid.Nil)
|
||||
c.MustPlanet(2).Production = game.ProductionNone.AsType(uuid.Nil)
|
||||
|
||||
planets := slices.Collect(c.ListProducingPlanets())
|
||||
assert.Len(t, planets, 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user