func (s *Sector) Init(position *position.Sector) { s.Collection = entity.NewCollection() s.position = position s.logger = log.New("world/sector", log.MapContext{"position": position}) }
// Simulates a few entity add/remove/update cycles func TestContainer(t *testing.T) { col := entity.NewCollection() e0, e1, e2 := MockEntity{0, entity.EntityType("a")}, MockEntity{1, entity.EntityType("a")}, MockEntity{2, entity.EntityType("b")} tcs := []struct { add []MockEntity entities []MockEntity remove []MockEntity }{ { add: []MockEntity{e0}, entities: []MockEntity{e0}, remove: []MockEntity{}, }, { add: []MockEntity{e1}, entities: []MockEntity{e0, e1}, remove: []MockEntity{}, }, { add: []MockEntity{}, entities: []MockEntity{e0, e1}, remove: []MockEntity{}, }, { add: []MockEntity{e2}, entities: []MockEntity{e1, e2}, remove: []MockEntity{e0}, }, { add: []MockEntity{}, entities: []MockEntity{e2}, remove: []MockEntity{e1}, }, { add: []MockEntity{}, entities: []MockEntity{}, remove: []MockEntity{e2}, }, { add: []MockEntity{}, entities: []MockEntity{}, remove: []MockEntity{}, }, } for i, tc := range tcs { t.Logf("cycle %v", i) col.Update() for _, e := range tc.add { col.Add(e) } for _, e := range tc.remove { col.Remove(e) } compareLists(t, "adding", col.Adding(), tc.add) compareLists(t, "removing", col.Removing(), tc.remove) compareLists(t, "entities", col.Entities(), tc.entities) } }