wip: battle

This commit is contained in:
Ilia Denisov
2026-01-13 18:53:17 +02:00
parent 4451850f22
commit 45c725a3ee
5 changed files with 197 additions and 30 deletions
+18
View File
@@ -1,6 +1,7 @@
package game_test
import (
"slices"
"testing"
"github.com/iliadenisov/galaxy/internal/model/game"
@@ -161,3 +162,20 @@ func TestFilterBattleOpponents(t *testing.T) {
assert.True(t, game.FilterBattleOpponents(g, 1, 3, cacheShipGroupRaceID, cacheRelation, cacheShipClass, cacheProbability))
assert.NotContains(t, cacheProbability[1], 3)
}
func TestSlicesDeleteFunc(t *testing.T) {
type Container struct {
S []int
}
c := Container{S: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}}
r1 := slices.DeleteFunc(c.S, func(e int) bool { return e%2 != 0 })
assert.Len(t, r1, 5)
for i := range r1 {
assert.Equal(t, i*2, r1[i], "elem #%d", i)
assert.Equal(t, i*2, c.S[i], "elem #%d", i)
}
assert.Len(t, c.S, 10)
for i := len(r1); i < len(c.S); i++ {
assert.Equal(t, 0, c.S[i], "elem #%d", i)
}
}