Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions world.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ func (world *World) SetEntityName(entityId EntityId, name string) {
world.entitiesNames[entityName] = entityId
}

// Count returns the number of entities in World.
func (world *World) Count() int {
return len(world.entities)
}

func stringToEntityName(name string) entityName {
var nameByte entityName
copy(nameByte[:], name)
Expand Down
18 changes: 18 additions & 0 deletions world_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,21 @@ func TestWorld_GetEntityName(t *testing.T) {
t.Errorf("world.GetEntityName does not return empty string for entityId 0")
}
}

func TestWorld_Count(t *testing.T) {
world := CreateWorld(1024)

if world.Count() != 0 {
t.Errorf("world.Count should return 0 if the world is empty")
}

entities := make([]EntityId, TEST_ENTITY_NUMBER)

for i := 0; i < TEST_ENTITY_NUMBER; i++ {
entities[i] = world.CreateEntity(fmt.Sprint(i))
}

if world.Count() != TEST_ENTITY_NUMBER {
t.Errorf("world.Count returned %d after inserting %d entities", world.Count(), TEST_ENTITY_NUMBER)
}
}