Add more tests
This commit is contained in:
parent
8da21ec110
commit
170ee14db8
|
|
@ -12,8 +12,8 @@ internal final class EntityIdentifierGenerator {
|
||||||
stack.count
|
stack.count
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
convenience init() {
|
||||||
stack = [0]
|
self.init([EntityIdentifier(0)])
|
||||||
}
|
}
|
||||||
|
|
||||||
init(_ entityIds: [EntityIdentifier]) {
|
init(_ entityIds: [EntityIdentifier]) {
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,7 @@ class EntityTests: XCTestCase {
|
||||||
|
|
||||||
let entity = nexus.createEntity()
|
let entity = nexus.createEntity()
|
||||||
entity.assign(pos)
|
entity.assign(pos)
|
||||||
entity.assign(name)
|
entity.assign(name, vel)
|
||||||
entity.assign(vel)
|
|
||||||
|
|
||||||
let expectedComponents: [Component] = [pos, name, vel]
|
let expectedComponents: [Component] = [pos, name, vel]
|
||||||
let allComponents = entity.allComponents()
|
let allComponents = entity.allComponents()
|
||||||
|
|
@ -40,6 +39,25 @@ class EntityTests: XCTestCase {
|
||||||
XCTAssertTrue(allComponents.elementsEqualUnordered(expectedComponents) { $0 === $1 })
|
XCTAssertTrue(allComponents.elementsEqualUnordered(expectedComponents) { $0 === $1 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testEntityEquality() {
|
||||||
|
let nexus = Nexus()
|
||||||
|
|
||||||
|
let entityA = nexus.createEntity()
|
||||||
|
let entityB = nexus.createEntity()
|
||||||
|
|
||||||
|
XCTAssertEqual(entityA, entityA)
|
||||||
|
XCTAssertNotEqual(entityA, entityB)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRemoveAllComponentsFromEntity() {
|
||||||
|
let nexus = Nexus()
|
||||||
|
|
||||||
|
let entity = nexus.createEntity(with: Position(x: 1, y: 2), Name(name: "MyEntity"))
|
||||||
|
XCTAssertEqual(entity.numComponents, 2)
|
||||||
|
entity.removeAll()
|
||||||
|
XCTAssertEqual(entity.numComponents, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func testEntityIdGenerator() {
|
func testEntityIdGenerator() {
|
||||||
let generator = EntityIdentifierGenerator()
|
let generator = EntityIdentifierGenerator()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,10 @@ extension EntityTests {
|
||||||
// to regenerate.
|
// to regenerate.
|
||||||
static let __allTests__EntityTests = [
|
static let __allTests__EntityTests = [
|
||||||
("testAllComponentsOfEntity", testAllComponentsOfEntity),
|
("testAllComponentsOfEntity", testAllComponentsOfEntity),
|
||||||
|
("testEntityEquality", testEntityEquality),
|
||||||
("testEntityIdentifierAndIndex", testEntityIdentifierAndIndex),
|
("testEntityIdentifierAndIndex", testEntityIdentifierAndIndex),
|
||||||
("testEntityIdGenerator", testEntityIdGenerator)
|
("testEntityIdGenerator", testEntityIdGenerator),
|
||||||
|
("testRemoveAllComponentsFromEntity", testRemoveAllComponentsFromEntity)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue