2020-10-10 22:49:17 -04:00
|
|
|
package d2systems
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-10-12 17:35:11 -04:00
|
|
|
"github.com/gravestench/akara"
|
2020-10-10 22:49:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTimeScaleSystem_Init(t *testing.T) {
|
2020-10-12 17:35:11 -04:00
|
|
|
cfg := akara.NewWorldConfig()
|
2020-10-10 22:49:17 -04:00
|
|
|
|
|
|
|
cfg.With(NewTimeScaleSystem())
|
|
|
|
|
2020-10-12 17:35:11 -04:00
|
|
|
world := akara.NewWorld(cfg)
|
2020-10-10 22:49:17 -04:00
|
|
|
|
|
|
|
if len(world.Systems) != 1 {
|
|
|
|
t.Error("system not added to the world")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeScaleSystem_Process(t *testing.T) {
|
2020-10-12 17:35:11 -04:00
|
|
|
cfg := akara.NewWorldConfig()
|
2020-10-10 22:49:17 -04:00
|
|
|
|
|
|
|
timescaleSystem := NewTimeScaleSystem()
|
|
|
|
|
|
|
|
cfg.With(timescaleSystem)
|
|
|
|
|
|
|
|
timescaleSystem.scale = 0.01
|
|
|
|
|
2020-10-12 17:35:11 -04:00
|
|
|
world := akara.NewWorld(cfg)
|
2020-10-10 22:49:17 -04:00
|
|
|
|
|
|
|
actual := time.Second
|
|
|
|
expected := time.Duration(timescaleSystem.scale) * actual
|
|
|
|
|
2020-11-22 04:37:55 -05:00
|
|
|
if err := world.Update(actual); err != nil {
|
|
|
|
timescaleSystem.Error(err.Error())
|
|
|
|
}
|
2020-10-10 22:49:17 -04:00
|
|
|
|
|
|
|
if world.TimeDelta != expected {
|
|
|
|
t.Error("world time delta not scaled")
|
|
|
|
}
|
|
|
|
}
|