From f99f171a154b1c7b22972dc45585d94ccb77c84a Mon Sep 17 00:00:00 2001 From: Christian Treffs Date: Mon, 30 Sep 2019 22:19:41 +0200 Subject: [PATCH] Add tests for scene graph implementation --- .../TypedFamilyPerformanceTests.swift | 22 +++--- Tests/FirebladeECSTests/Base.swift | 4 +- Tests/FirebladeECSTests/EntityTests.swift | 2 +- Tests/FirebladeECSTests/FamilyTests.swift | 6 +- Tests/FirebladeECSTests/SceneGraphTests.swift | 70 ++++++++++++------- Tests/FirebladeECSTests/SystemsTests.swift | 2 +- Tests/FirebladeECSTests/XCTestManifests.swift | 16 ++++- 7 files changed, 79 insertions(+), 43 deletions(-) diff --git a/Tests/FirebladeECSPerformanceTests/TypedFamilyPerformanceTests.swift b/Tests/FirebladeECSPerformanceTests/TypedFamilyPerformanceTests.swift index 7f6a0ee..ce3a897 100644 --- a/Tests/FirebladeECSPerformanceTests/TypedFamilyPerformanceTests.swift +++ b/Tests/FirebladeECSPerformanceTests/TypedFamilyPerformanceTests.swift @@ -65,7 +65,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = entity loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -81,7 +81,7 @@ class TypedFamilyPerformanceTests: XCTestCase { .forEach { (position: Position) in _ = position loopCount += 1 - } + } } XCTAssertEqual(loopCount, numEntities * 10) @@ -103,7 +103,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = position loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -127,7 +127,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = position loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -150,7 +150,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = velocity loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -175,7 +175,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = velocity loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -199,7 +199,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = name loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -225,7 +225,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = name loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -250,7 +250,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = color loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -277,7 +277,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = color loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) @@ -330,7 +330,7 @@ class TypedFamilyPerformanceTests: XCTestCase { _ = empty loopCount += 1 - } + } } XCTAssertEqual(loopCount, family.count * 10) diff --git a/Tests/FirebladeECSTests/Base.swift b/Tests/FirebladeECSTests/Base.swift index 48de411..6705191 100644 --- a/Tests/FirebladeECSTests/Base.swift +++ b/Tests/FirebladeECSTests/Base.swift @@ -79,7 +79,7 @@ class ColorSystem { color.r = 1 color.g = 2 color.b = 3 - } + } } } @@ -106,6 +106,6 @@ class PositionSystem { pos.x = x pos.y = y - } + } } } diff --git a/Tests/FirebladeECSTests/EntityTests.swift b/Tests/FirebladeECSTests/EntityTests.swift index 7721375..d15452d 100644 --- a/Tests/FirebladeECSTests/EntityTests.swift +++ b/Tests/FirebladeECSTests/EntityTests.swift @@ -21,7 +21,7 @@ class EntityTests: XCTestCase { XCTAssertEqual(max, EntityIdentifier.invalid) XCTAssertEqual(max.index, Int(UInt32.max)) } - + func testEntityIdentifierComparison() { XCTAssertTrue(EntityIdentifier(1) < EntityIdentifier(2)) XCTAssertTrue(EntityIdentifier(23) > EntityIdentifier(4)) diff --git a/Tests/FirebladeECSTests/FamilyTests.swift b/Tests/FirebladeECSTests/FamilyTests.swift index 5838973..fb7fb50 100644 --- a/Tests/FirebladeECSTests/FamilyTests.swift +++ b/Tests/FirebladeECSTests/FamilyTests.swift @@ -120,7 +120,7 @@ class FamilyTests: XCTestCase { .forEach { (entity: Entity, _: Position) in entity.assign(Velocity(a: 3.14)) entity.remove(Position.self) - } + } XCTAssertEqual(familyA.count, 0) XCTAssertEqual(familyB.count, 10) @@ -130,7 +130,7 @@ class FamilyTests: XCTestCase { .forEach { (entity: Entity, velocity: Velocity) in entity.assign(Position(x: 1, y: 2)) entity.remove(velocity) - } + } XCTAssertEqual(familyA.count, 10) XCTAssertEqual(familyB.count, 0) @@ -175,7 +175,7 @@ class FamilyTests: XCTestCase { .prefix(currentCount) .forEach { (entity: Entity) in entity.destroy() - } + } XCTAssertEqual(family.memberIds.count, (count / 2)) diff --git a/Tests/FirebladeECSTests/SceneGraphTests.swift b/Tests/FirebladeECSTests/SceneGraphTests.swift index 5591744..4b46369 100644 --- a/Tests/FirebladeECSTests/SceneGraphTests.swift +++ b/Tests/FirebladeECSTests/SceneGraphTests.swift @@ -11,7 +11,7 @@ import FirebladeECS class SceneGraphTests: XCTestCase { var nexus: Nexus! - + override func setUp() { super.setUp() nexus = Nexus() @@ -22,35 +22,57 @@ class SceneGraphTests: XCTestCase { nexus = nil } - func testParent() { + func testAddChild() { + let nttParrent = nexus.createEntity() + let nttChild1 = nexus.createEntity() + XCTAssertEqual(nttParrent.numChildren, 0) + XCTAssertTrue(nttParrent.addChild(nttChild1)) + XCTAssertEqual(nttParrent.numChildren, 1) + XCTAssertFalse(nttParrent.addChild(nttChild1)) + XCTAssertEqual(nttParrent.numChildren, 1) + } + + func testRemoveChild() { + let nttParrent = nexus.createEntity() + let nttChild1 = nexus.createEntity() + + XCTAssertEqual(nttParrent.numChildren, 0) + XCTAssertTrue(nttParrent.addChild(nttChild1)) + XCTAssertEqual(nttParrent.numChildren, 1) + XCTAssertTrue(nttParrent.removeChild(nttChild1)) + XCTAssertEqual(nttParrent.numChildren, 0) + XCTAssertFalse(nttParrent.removeChild(nttChild1)) + XCTAssertEqual(nttParrent.numChildren, 0) + XCTAssertTrue(nttParrent.addChild(nttChild1)) + XCTAssertEqual(nttParrent.numChildren, 1) + } + + func testRemoveAllChildren() { + let nttParrent = nexus.createEntity() + let nttChild1 = nexus.createEntity() + let nttChild2 = nexus.createEntity() + + XCTAssertEqual(nttParrent.numChildren, 0) + nttParrent.addChild(nttChild1) + nttParrent.addChild(nttChild2) + XCTAssertEqual(nttParrent.numChildren, 2) + + nttParrent.removeAllChildren() + XCTAssertEqual(nttParrent.numChildren, 0) + } + + func testDescendRelatives() { let nttParrent = nexus.createEntity(with: Position(x: 1, y: 1)) - let nttChild1 = nexus.createEntity(with: Position(x: 2, y: 2)) - let nttChild2 = nexus.createEntity(with: Position(x: 3, y: 3)) - + nttParrent.addChild(nttChild1) - nttParrent.removeChild(nttChild1) - nttParrent.addChild(nttChild1) - + let family = nexus.family(requires: Position.self) - - + family - .descendRelatives.forEach { (parent: Position, child: Position) in - + .descendRelatives.forEach { (_: Position, _: Position) in + // TODO: } - - let family2 = nexus.family(requiresAll: Position.self, Name.self) - - family2 - .descendRelatives - .forEach { (parent, child) in - let (pPos, pName) = parent - let (cPos, cName) = child - - - } - } } diff --git a/Tests/FirebladeECSTests/SystemsTests.swift b/Tests/FirebladeECSTests/SystemsTests.swift index a40ed60..ac815bd 100644 --- a/Tests/FirebladeECSTests/SystemsTests.swift +++ b/Tests/FirebladeECSTests/SystemsTests.swift @@ -121,6 +121,6 @@ class SystemsTests: XCTestCase { .prefix(count) .forEach { (entity: Entity) in entity.destroy() - } + } } } diff --git a/Tests/FirebladeECSTests/XCTestManifests.swift b/Tests/FirebladeECSTests/XCTestManifests.swift index 6f3020b..1f17d34 100644 --- a/Tests/FirebladeECSTests/XCTestManifests.swift +++ b/Tests/FirebladeECSTests/XCTestManifests.swift @@ -15,7 +15,8 @@ extension EntityTests { // `swift test --generate-linuxmain` // to regenerate. static let __allTests__EntityTests = [ - ("testEntityIdentifierAndIndex", testEntityIdentifierAndIndex) + ("testEntityIdentifierAndIndex", testEntityIdentifierAndIndex), + ("testEntityIdentifierComparison", testEntityIdentifierComparison) ] } @@ -67,6 +68,18 @@ extension NexusTests { ] } +extension SceneGraphTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__SceneGraphTests = [ + ("testAddChild", testAddChild), + ("testDescendRelatives", testDescendRelatives), + ("testRemoveAllChildren", testRemoveAllChildren), + ("testRemoveChild", testRemoveChild) + ] +} + extension SingleTests { // DO NOT MODIFY: This is autogenerated, use: // `swift test --generate-linuxmain` @@ -116,6 +129,7 @@ public func __allTests() -> [XCTestCaseEntry] { testCase(FamilyTraitsTests.__allTests__FamilyTraitsTests), testCase(HashingTests.__allTests__HashingTests), testCase(NexusTests.__allTests__NexusTests), + testCase(SceneGraphTests.__allTests__SceneGraphTests), testCase(SingleTests.__allTests__SingleTests), testCase(SparseSetTests.__allTests__SparseSetTests), testCase(SystemsTests.__allTests__SystemsTests)