Add tests for scene graph implementation
This commit is contained in:
parent
f312f9335e
commit
f99f171a15
|
|
@ -65,7 +65,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = entity
|
_ = entity
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -81,7 +81,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
.forEach { (position: Position) in
|
.forEach { (position: Position) in
|
||||||
_ = position
|
_ = position
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, numEntities * 10)
|
XCTAssertEqual(loopCount, numEntities * 10)
|
||||||
|
|
@ -103,7 +103,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = position
|
_ = position
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -127,7 +127,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = position
|
_ = position
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -150,7 +150,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = velocity
|
_ = velocity
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -175,7 +175,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = velocity
|
_ = velocity
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -199,7 +199,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = name
|
_ = name
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -225,7 +225,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = name
|
_ = name
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -250,7 +250,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = color
|
_ = color
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -277,7 +277,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = color
|
_ = color
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
@ -330,7 +330,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
||||||
_ = empty
|
_ = empty
|
||||||
|
|
||||||
loopCount += 1
|
loopCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(loopCount, family.count * 10)
|
XCTAssertEqual(loopCount, family.count * 10)
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class ColorSystem {
|
||||||
color.r = 1
|
color.r = 1
|
||||||
color.g = 2
|
color.g = 2
|
||||||
color.b = 3
|
color.b = 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,6 +106,6 @@ class PositionSystem {
|
||||||
|
|
||||||
pos.x = x
|
pos.x = x
|
||||||
pos.y = y
|
pos.y = y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class EntityTests: XCTestCase {
|
||||||
XCTAssertEqual(max, EntityIdentifier.invalid)
|
XCTAssertEqual(max, EntityIdentifier.invalid)
|
||||||
XCTAssertEqual(max.index, Int(UInt32.max))
|
XCTAssertEqual(max.index, Int(UInt32.max))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEntityIdentifierComparison() {
|
func testEntityIdentifierComparison() {
|
||||||
XCTAssertTrue(EntityIdentifier(1) < EntityIdentifier(2))
|
XCTAssertTrue(EntityIdentifier(1) < EntityIdentifier(2))
|
||||||
XCTAssertTrue(EntityIdentifier(23) > EntityIdentifier(4))
|
XCTAssertTrue(EntityIdentifier(23) > EntityIdentifier(4))
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ class FamilyTests: XCTestCase {
|
||||||
.forEach { (entity: Entity, _: Position) in
|
.forEach { (entity: Entity, _: Position) in
|
||||||
entity.assign(Velocity(a: 3.14))
|
entity.assign(Velocity(a: 3.14))
|
||||||
entity.remove(Position.self)
|
entity.remove(Position.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(familyA.count, 0)
|
XCTAssertEqual(familyA.count, 0)
|
||||||
XCTAssertEqual(familyB.count, 10)
|
XCTAssertEqual(familyB.count, 10)
|
||||||
|
|
@ -130,7 +130,7 @@ class FamilyTests: XCTestCase {
|
||||||
.forEach { (entity: Entity, velocity: Velocity) in
|
.forEach { (entity: Entity, velocity: Velocity) in
|
||||||
entity.assign(Position(x: 1, y: 2))
|
entity.assign(Position(x: 1, y: 2))
|
||||||
entity.remove(velocity)
|
entity.remove(velocity)
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(familyA.count, 10)
|
XCTAssertEqual(familyA.count, 10)
|
||||||
XCTAssertEqual(familyB.count, 0)
|
XCTAssertEqual(familyB.count, 0)
|
||||||
|
|
@ -175,7 +175,7 @@ class FamilyTests: XCTestCase {
|
||||||
.prefix(currentCount)
|
.prefix(currentCount)
|
||||||
.forEach { (entity: Entity) in
|
.forEach { (entity: Entity) in
|
||||||
entity.destroy()
|
entity.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(family.memberIds.count, (count / 2))
|
XCTAssertEqual(family.memberIds.count, (count / 2))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import FirebladeECS
|
||||||
class SceneGraphTests: XCTestCase {
|
class SceneGraphTests: XCTestCase {
|
||||||
|
|
||||||
var nexus: Nexus!
|
var nexus: Nexus!
|
||||||
|
|
||||||
override func setUp() {
|
override func setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
nexus = Nexus()
|
nexus = Nexus()
|
||||||
|
|
@ -22,35 +22,57 @@ class SceneGraphTests: XCTestCase {
|
||||||
nexus = nil
|
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 nttParrent = nexus.createEntity(with: Position(x: 1, y: 1))
|
||||||
|
|
||||||
let nttChild1 = nexus.createEntity(with: Position(x: 2, y: 2))
|
let nttChild1 = nexus.createEntity(with: Position(x: 2, y: 2))
|
||||||
let nttChild2 = nexus.createEntity(with: Position(x: 3, y: 3))
|
|
||||||
|
|
||||||
nttParrent.addChild(nttChild1)
|
nttParrent.addChild(nttChild1)
|
||||||
nttParrent.removeChild(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
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,6 @@ class SystemsTests: XCTestCase {
|
||||||
.prefix(count)
|
.prefix(count)
|
||||||
.forEach { (entity: Entity) in
|
.forEach { (entity: Entity) in
|
||||||
entity.destroy()
|
entity.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue