2021-11-22 19:18:28 +00:00
|
|
|
package gohan
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestActiveEntities(t *testing.T) {
|
2022-02-01 04:07:55 +00:00
|
|
|
Reset()
|
2021-12-06 01:17:15 +00:00
|
|
|
w.cacheTime = 0
|
2021-11-22 19:18:28 +00:00
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
active := CurrentEntities()
|
2021-11-22 19:18:28 +00:00
|
|
|
if active != 0 {
|
|
|
|
t.Fatalf("expected 0 active entities, got %d", active)
|
|
|
|
}
|
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
active = CurrentEntities()
|
2021-11-22 19:18:28 +00:00
|
|
|
if active != 0 {
|
|
|
|
t.Fatalf("expected 0 active entities, got %d", active)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create entity.
|
2022-02-01 04:07:55 +00:00
|
|
|
e1 := NewEntity()
|
2021-11-22 19:18:28 +00:00
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
active = CurrentEntities()
|
2021-11-22 19:18:28 +00:00
|
|
|
if active != 1 {
|
|
|
|
t.Fatalf("expected 1 active entities, got %d", active)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create entity.
|
2022-02-01 04:07:55 +00:00
|
|
|
e2 := NewEntity()
|
2021-11-22 19:18:28 +00:00
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
active = CurrentEntities()
|
2021-11-22 19:18:28 +00:00
|
|
|
if active != 2 {
|
|
|
|
t.Fatalf("expected 2 active entities, got %d", active)
|
|
|
|
}
|
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
e1.Remove()
|
2021-11-22 19:18:28 +00:00
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
active = CurrentEntities()
|
2021-11-22 19:18:28 +00:00
|
|
|
if active != 1 {
|
|
|
|
t.Fatalf("expected 1 active entities, got %d", active)
|
|
|
|
}
|
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
e2.Remove()
|
2021-11-22 19:18:28 +00:00
|
|
|
|
2022-02-01 04:07:55 +00:00
|
|
|
active = CurrentEntities()
|
2021-11-22 19:18:28 +00:00
|
|
|
if active != 0 {
|
|
|
|
t.Fatalf("expected 0 active entities, got %d", active)
|
|
|
|
}
|
|
|
|
}
|