test: player base report
This commit is contained in:
@@ -263,7 +263,6 @@ func (c *Cache) FleetIndex(ID uuid.UUID) (int, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: rename / [fleetIndex]
|
||||
func (c *Cache) MustFleetIndex(ID uuid.UUID) int {
|
||||
if v, ok := c.FleetIndex(ID); ok {
|
||||
return v
|
||||
|
||||
@@ -109,19 +109,17 @@ func (c *Cache) ReportRace(ri int, rep *mr.Report, battles []*mr.BattleReport, b
|
||||
rep.RaceID = r.ID
|
||||
|
||||
// votes based on population
|
||||
// TODO: check vote values was previously calculated
|
||||
rep.Votes = mr.F(r.Votes.F())
|
||||
|
||||
// relations
|
||||
for i := range r.Relations {
|
||||
rii := slices.IndexFunc(rep.Player, func(v mr.Player) bool { return v.ID == r.Relations[i].RaceID })
|
||||
if rii < 0 {
|
||||
panic(fmt.Sprintf("relation race not found, id=%v", r.Relations[i].RaceID))
|
||||
panic(fmt.Sprintf("opponent race for relation not found, id=%v", r.Relations[i].RaceID))
|
||||
}
|
||||
rep.Player[rii].Relation = r.Relations[i].Relation.String()
|
||||
}
|
||||
// self-relation is undefined
|
||||
|
||||
if i := slices.IndexFunc(rep.Player, func(v mr.Player) bool { return v.ID == r.ID }); i < 0 {
|
||||
panic(fmt.Sprintf("race not found in report, id=%v", r.ID))
|
||||
} else {
|
||||
|
||||
@@ -8,6 +8,49 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestReportRace(t *testing.T) {
|
||||
c, _ := newCache()
|
||||
|
||||
c.TurnCalculateVotes()
|
||||
|
||||
rep := c.InitReport(2)
|
||||
assert.Equal(t, 2, int(rep.Turn))
|
||||
|
||||
c.ReportRace(Race_0_idx, rep, nil, nil)
|
||||
|
||||
assert.Equal(t, Race_0.Name, rep.Race)
|
||||
assert.Equal(t, Race_0.ID, rep.RaceID)
|
||||
assert.Equal(t, 0.1, float64(rep.Votes))
|
||||
|
||||
for i := range rep.Player {
|
||||
p := &rep.Player[i]
|
||||
switch p.ID {
|
||||
case Race_0_ID:
|
||||
assert.Equal(t, Race_0.Name, p.Name)
|
||||
assert.Equal(t, 1.1, float64(p.Drive))
|
||||
assert.Equal(t, 1.2, float64(p.Weapons))
|
||||
assert.Equal(t, 1.3, float64(p.Shields))
|
||||
assert.Equal(t, 1.4, float64(p.Cargo))
|
||||
assert.Equal(t, 100., float64(p.Population))
|
||||
assert.Equal(t, 100., float64(p.Industry))
|
||||
assert.Equal(t, 2, int(p.Planets))
|
||||
assert.Equal(t, 0.1, float64(p.Votes))
|
||||
assert.Equal(t, "-", p.Relation)
|
||||
case Race_1_ID:
|
||||
assert.Equal(t, Race_1.Name, p.Name)
|
||||
assert.Equal(t, 2.1, float64(p.Drive))
|
||||
assert.Equal(t, 2.2, float64(p.Weapons))
|
||||
assert.Equal(t, 2.3, float64(p.Shields))
|
||||
assert.Equal(t, 2.4, float64(p.Cargo))
|
||||
assert.Equal(t, 0., float64(p.Population))
|
||||
assert.Equal(t, 0., float64(p.Industry))
|
||||
assert.Equal(t, 1, int(p.Planets))
|
||||
assert.Equal(t, 0., float64(p.Votes))
|
||||
assert.Equal(t, "War", p.Relation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReportLocalShipClass(t *testing.T) {
|
||||
c, _ := newCache()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user