From a8e5e723b7e1891c9b352261a3ee4c3d3563e8cf Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 26 Oct 2025 21:38:22 -0700 Subject: Checkpoint two --- .../kotlin/coffee/liz/ecs/DAGWorldTest.kt | 187 ++++++++++++++------- 1 file changed, 125 insertions(+), 62 deletions(-) (limited to 'composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt') diff --git a/composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt b/composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt index bdf7e99..a9f6249 100644 --- a/composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt +++ b/composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt @@ -4,20 +4,28 @@ import kotlin.reflect.KClass import kotlin.test.* // Test systems for circular dependency test -class CircularSystemA : System { - override val dependencies: Set> - get() = setOf(CircularSystemB::class) - override fun update(world: World, deltaTime: Float) {} +class Outside + +class CircularSystemA : System { + override val dependencies get() = setOf(CircularSystemB::class) + + override fun update( + world: World, + deltaTime: Float, + ) {} } class CircularSystemB : System { override val dependencies: Set> get() = setOf(CircularSystemA::class) - override fun update(world: World, deltaTime: Float) {} + + override fun update( + world: World, + deltaTime: Float, + ) {} } class DAGWorldTest { - @Test fun `can create entities with unique ids`() { val world = DAGWorld(emptyList()) @@ -60,13 +68,19 @@ class DAGWorldTest { @Test fun `query with multiple components returns intersection`() { val world = DAGWorld(emptyList()) - val entity1 = world.createEntity() - .add(Position(10f, 20f)) - .add(Velocity(1f, 2f)) - val entity2 = world.createEntity() - .add(Position(30f, 40f)) - val entity3 = world.createEntity() - .add(Velocity(3f, 4f)) + val entity1 = + world + .createEntity() + .add(Position(10f, 20f)) + .add(Velocity(1f, 2f)) + val entity2 = + world + .createEntity() + .add(Position(30f, 40f)) + val entity3 = + world + .createEntity() + .add(Velocity(3f, 4f)) world.update(0f) // Trigger cache update @@ -80,25 +94,39 @@ class DAGWorldTest { fun `systems execute in dependency order`() { val executionOrder = mutableListOf() - val systemA = object : System { - override fun update(world: World, deltaTime: Float) { - executionOrder.add("A") + val systemA = + object : System { + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("A") + } } - } - val systemB = object : System { - override val dependencies = setOf(systemA::class) - override fun update(world: World, deltaTime: Float) { - executionOrder.add("B") + val systemB = + object : System { + override val dependencies = setOf(systemA::class) + + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("B") + } } - } - val systemC = object : System { - override val dependencies = setOf(systemB::class) - override fun update(world: World, deltaTime: Float) { - executionOrder.add("C") + val systemC = + object : System { + override val dependencies = setOf(systemB::class) + + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("C") + } } - } val world = DAGWorld(listOf(systemC, systemA, systemB)) world.update(0f) @@ -110,17 +138,25 @@ class DAGWorldTest { fun `systems with no dependencies can execute in any order`() { val executionOrder = mutableListOf() - val systemA = object : System { - override fun update(world: World, deltaTime: Float) { - executionOrder.add("A") + val systemA = + object : System { + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("A") + } } - } - val systemB = object : System { - override fun update(world: World, deltaTime: Float) { - executionOrder.add("B") + val systemB = + object : System { + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("B") + } } - } val world = DAGWorld(listOf(systemA, systemB)) world.update(0f) @@ -144,11 +180,15 @@ class DAGWorldTest { fun `system receives correct deltaTime`() { var receivedDelta = 0f - val system = object : System { - override fun update(world: World, deltaTime: Float) { - receivedDelta = deltaTime + val system = + object : System { + override fun update( + world: World, + deltaTime: Float, + ) { + receivedDelta = deltaTime + } } - } val world = DAGWorld(listOf(system)) world.update(0.016f) @@ -160,11 +200,15 @@ class DAGWorldTest { fun `systems can query entities during update`() { var queriedEntities: Set? = null - val system = object : System { - override fun update(world: World, deltaTime: Float) { - queriedEntities = world.query() + val system = + object : System { + override fun update( + world: World, + deltaTime: Float, + ) { + queriedEntities = world.query() + } } - } val world = DAGWorld(listOf(system)) val entity = world.createEntity().add(Position(10f, 20f)) @@ -203,32 +247,51 @@ class DAGWorldTest { // \ / // D - val systemA = object : System { - override fun update(world: World, deltaTime: Float) { - executionOrder.add("A") + val systemA = + object : System { + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("A") + } } - } - val systemB = object : System { - override val dependencies = setOf(systemA::class) - override fun update(world: World, deltaTime: Float) { - executionOrder.add("B") + val systemB = + object : System { + override val dependencies = setOf(systemA::class) + + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("B") + } } - } - val systemC = object : System { - override val dependencies = setOf(systemA::class) - override fun update(world: World, deltaTime: Float) { - executionOrder.add("C") + val systemC = + object : System { + override val dependencies = setOf(systemA::class) + + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("C") + } } - } - val systemD = object : System { - override val dependencies = setOf(systemB::class, systemC::class) - override fun update(world: World, deltaTime: Float) { - executionOrder.add("D") + val systemD = + object : System { + override val dependencies = setOf(systemB::class, systemC::class) + + override fun update( + world: World, + deltaTime: Float, + ) { + executionOrder.add("D") + } } - } val world = DAGWorld(listOf(systemD, systemC, systemB, systemA)) world.update(0f) -- cgit v1.2.3-70-g09d2