Entity Component System framework for Ebitengine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1015 B

package gohan
import (
"testing"
"time"
)
func TestActiveEntities(t *testing.T) {
t.Parallel()
active := ActiveEntities()
if active != 0 {
t.Fatalf("expected 0 active entities, got %d", active)
}
wait()
active = ActiveEntities()
if active != 0 {
t.Fatalf("expected 0 active entities, got %d", active)
}
// Create entity.
e1 := NewEntity()
wait()
active = ActiveEntities()
if active != 1 {
t.Fatalf("expected 1 active entities, got %d", active)
}
// Create entity.
e2 := NewEntity()
wait()
active = ActiveEntities()
if active != 2 {
t.Fatalf("expected 2 active entities, got %d", active)
}
e1.Remove()
wait()
active = ActiveEntities()
if active != 1 {
t.Fatalf("expected 1 active entities, got %d", active)
}
e2.Remove()
wait()
active = ActiveEntities()
if active != 0 {
t.Fatalf("expected 0 active entities, got %d", active)
}
}
// wait causes the program to wait long enough to expire all duration-based caches.
func wait() {
time.Sleep(2 * time.Second)
}