cmd: join group to fleet
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package game_test
|
||||
|
||||
import (
|
||||
"iter"
|
||||
"math/rand/v2"
|
||||
"slices"
|
||||
"testing"
|
||||
@@ -272,24 +271,25 @@ func TestShipGroupEqual(t *testing.T) {
|
||||
|
||||
func TestCreateShips(t *testing.T) {
|
||||
g := copyGame()
|
||||
var err error
|
||||
|
||||
err = g.CreateShips(Race_0_idx, "Unknown_Ship_Type", R0_Planet_0_num, 2)
|
||||
assert.ErrorContains(t, err, e.GenericErrorText(e.ErrInputEntityNotExists))
|
||||
err = g.CreateShips(Race_0_idx, Race_0_Gunship, R1_Planet_1_num, 2)
|
||||
assert.ErrorContains(t, err, e.GenericErrorText(e.ErrInputEntityNotOwned))
|
||||
assert.ErrorContains(t,
|
||||
g.CreateShips(Race_0_idx, "Unknown_Ship_Type", R0_Planet_0_num, 2),
|
||||
e.GenericErrorText(e.ErrInputEntityNotExists))
|
||||
assert.ErrorContains(t,
|
||||
g.CreateShips(Race_0_idx, Race_0_Gunship, R1_Planet_1_num, 2),
|
||||
e.GenericErrorText(e.ErrInputEntityNotOwned))
|
||||
|
||||
assert.NoError(t, g.CreateShips(Race_0_idx, Race_0_Freighter, R0_Planet_0_num, 1))
|
||||
assert.Len(t, collectGroups(g.ListShipGroups(Race_0_idx)), 1)
|
||||
assert.Len(t, slices.Collect(g.ListShipGroups(Race_0_idx)), 1)
|
||||
|
||||
assert.NoError(t, g.CreateShips(Race_1_idx, Race_1_Freighter, R1_Planet_1_num, 1))
|
||||
assert.Len(t, collectGroups(g.ListShipGroups(1)), 1)
|
||||
assert.Len(t, slices.Collect(g.ListShipGroups(1)), 1)
|
||||
|
||||
assert.NoError(t, g.CreateShips(Race_0_idx, Race_0_Freighter, R0_Planet_0_num, 6))
|
||||
assert.Len(t, collectGroups(g.ListShipGroups(Race_0_idx)), 2)
|
||||
assert.Len(t, slices.Collect(g.ListShipGroups(Race_0_idx)), 2)
|
||||
|
||||
assert.NoError(t, g.CreateShips(Race_1_idx, Race_1_Gunship, R1_Planet_1_num, 1))
|
||||
assert.Len(t, collectGroups(g.ListShipGroups(1)), 2)
|
||||
assert.Len(t, slices.Collect(g.ListShipGroups(1)), 2)
|
||||
}
|
||||
|
||||
func TestJoinEqualGroups(t *testing.T) {
|
||||
@@ -307,16 +307,16 @@ func TestJoinEqualGroups(t *testing.T) {
|
||||
assert.NoError(t, g.CreateShips(Race_0_idx, Race_0_Gunship, R0_Planet_0_num, 4)) // (6)
|
||||
assert.NoError(t, g.CreateShips(Race_0_idx, Race_0_Freighter, R0_Planet_0_num, 4)) // (7)
|
||||
|
||||
assert.Len(t, collectGroups(g.ListShipGroups(Race_0_idx)), 7)
|
||||
assert.Len(t, slices.Collect(g.ListShipGroups(Race_0_idx)), 7)
|
||||
|
||||
g.Race[Race_1_idx].Shields = 2.0
|
||||
assert.NoError(t, g.CreateShips(1, Race_1_Freighter, R1_Planet_1_num, 1))
|
||||
assert.Len(t, collectGroups(g.ListShipGroups(Race_1_idx)), 3)
|
||||
assert.Len(t, slices.Collect(g.ListShipGroups(Race_1_idx)), 3)
|
||||
|
||||
assert.NoError(t, g.JoinEqualGroups(Race_0.Name))
|
||||
|
||||
assert.Len(t, collectGroups(g.ListShipGroups(Race_1_idx)), 3)
|
||||
assert.Len(t, collectGroups(g.ListShipGroups(Race_0_idx)), 4)
|
||||
assert.Len(t, slices.Collect(g.ListShipGroups(Race_1_idx)), 3)
|
||||
assert.Len(t, slices.Collect(g.ListShipGroups(Race_0_idx)), 4)
|
||||
|
||||
shipTypeID := func(ri int, name string) uuid.UUID {
|
||||
st := slices.IndexFunc(g.Race[ri].ShipTypes, func(v game.ShipType) bool { return v.Name == name })
|
||||
@@ -327,7 +327,7 @@ func TestJoinEqualGroups(t *testing.T) {
|
||||
return g.Race[ri].ShipTypes[st].ID
|
||||
}
|
||||
|
||||
for _, sg := range g.ListShipGroups(Race_0_idx) {
|
||||
for sg := range g.ListShipGroups(Race_0_idx) {
|
||||
switch {
|
||||
case sg.TypeID == shipTypeID(Race_0_idx, Race_0_Freighter) && sg.Drive == 1.1:
|
||||
assert.Equal(t, uint(7), sg.Number)
|
||||
@@ -346,11 +346,3 @@ func TestJoinEqualGroups(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func collectGroups(i iter.Seq2[int, game.ShipGroup]) []game.ShipGroup {
|
||||
result := make([]game.ShipGroup, 0)
|
||||
for _, sg := range i {
|
||||
result = append(result, sg)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user