Add tests for scene graph implementation

This commit is contained in:
Christian Treffs 2019-09-30 22:19:41 +02:00
parent f312f9335e
commit f99f171a15
7 changed files with 79 additions and 43 deletions

View File

@ -22,35 +22,57 @@ class SceneGraphTests: XCTestCase {
nexus = nil nexus = nil
} }
func testParent() { func testAddChild() {
let nttParrent = nexus.createEntity(with: Position(x: 1, y: 1)) 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)
}
let nttChild1 = nexus.createEntity(with: Position(x: 2, y: 2)) func testRemoveChild() {
let nttChild2 = nexus.createEntity(with: Position(x: 3, y: 3)) 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(nttChild1)
nttParrent.removeChild(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))
nttParrent.addChild(nttChild1) nttParrent.addChild(nttChild1)
let family = nexus.family(requires: Position.self) let family = nexus.family(requires: Position.self)
family 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
}
} }
} }

View File

@ -15,7 +15,8 @@ extension EntityTests {
// `swift test --generate-linuxmain` // `swift test --generate-linuxmain`
// to regenerate. // to regenerate.
static let __allTests__EntityTests = [ 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 { extension SingleTests {
// DO NOT MODIFY: This is autogenerated, use: // DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain` // `swift test --generate-linuxmain`
@ -116,6 +129,7 @@ public func __allTests() -> [XCTestCaseEntry] {
testCase(FamilyTraitsTests.__allTests__FamilyTraitsTests), testCase(FamilyTraitsTests.__allTests__FamilyTraitsTests),
testCase(HashingTests.__allTests__HashingTests), testCase(HashingTests.__allTests__HashingTests),
testCase(NexusTests.__allTests__NexusTests), testCase(NexusTests.__allTests__NexusTests),
testCase(SceneGraphTests.__allTests__SceneGraphTests),
testCase(SingleTests.__allTests__SingleTests), testCase(SingleTests.__allTests__SingleTests),
testCase(SparseSetTests.__allTests__SparseSetTests), testCase(SparseSetTests.__allTests__SparseSetTests),
testCase(SystemsTests.__allTests__SystemsTests) testCase(SystemsTests.__allTests__SystemsTests)