Add more tests

This commit is contained in:
Christian Treffs 2020-07-15 21:26:52 +02:00
parent 8da21ec110
commit 170ee14db8
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
3 changed files with 25 additions and 5 deletions

View File

@ -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]) {

View File

@ -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()

View File

@ -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)
] ]
} }