Add tests
This commit is contained in:
parent
0d66a30544
commit
d751359ea0
|
|
@ -10,6 +10,29 @@ import FirebladeECS
|
|||
class EmptyComponent: Component {
|
||||
}
|
||||
|
||||
final class Optionals: Component, DefaultInitializable {
|
||||
var int: Int?
|
||||
var float: Float?
|
||||
var string: String?
|
||||
|
||||
convenience init() {
|
||||
self.init(nil, nil, nil)
|
||||
}
|
||||
|
||||
init(_ int: Int?, _ float: Float?, _ string: String?) {
|
||||
self.int = int
|
||||
self.float = float
|
||||
self.string = string
|
||||
}
|
||||
}
|
||||
extension Optionals: Equatable {
|
||||
static func == (lhs: Optionals, rhs: Optionals) -> Bool {
|
||||
lhs.int == rhs.int &&
|
||||
lhs.float == rhs.float &&
|
||||
lhs.string == rhs.string
|
||||
}
|
||||
}
|
||||
|
||||
final class Name: Component, DefaultInitializable {
|
||||
var name: String
|
||||
init(name: String) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class EntityTests: XCTestCase {
|
|||
entity.assign(name, vel)
|
||||
|
||||
let expectedComponents: [Component] = [pos, name, vel]
|
||||
let allComponents = entity.allComponents()
|
||||
let allComponents = Array(entity.makeComponentsIterator())
|
||||
|
||||
XCTAssertTrue(allComponents.elementsEqualUnordered(expectedComponents) { $0 === $1 })
|
||||
}
|
||||
|
|
@ -117,6 +117,56 @@ class EntityTests: XCTestCase {
|
|||
entity[Position.self] = nil // remove position component
|
||||
XCTAssertNil(entity[Position.self])
|
||||
|
||||
let opts = Optionals(1, 2, "hello")
|
||||
entity[Optionals.self] = opts
|
||||
XCTAssertEqual(entity[Optionals.self], opts)
|
||||
|
||||
entity[\Optionals.float] = nil
|
||||
XCTAssertEqual(entity[\Optionals.float], nil)
|
||||
XCTAssertEqual(entity[\Optionals.int], 1)
|
||||
XCTAssertEqual(entity[\Optionals.string], "hello")
|
||||
|
||||
entity[Optionals.self] = nil
|
||||
XCTAssertNil(entity[Optionals.self])
|
||||
entity[\Optionals.string] = "world"
|
||||
XCTAssertEqual(entity[\Optionals.string], "world")
|
||||
|
||||
entity.assign(Comp1(12))
|
||||
XCTAssertEqual(entity[\Comp1.value], 12)
|
||||
}
|
||||
|
||||
func testComponentsIteration() {
|
||||
let nexus = Nexus()
|
||||
let entity = nexus.createEntity()
|
||||
XCTAssertTrue(Array(entity.makeComponentsIterator()).isEmpty)
|
||||
entity.assign(Position())
|
||||
XCTAssertEqual(Array(entity.makeComponentsIterator()).count, 1)
|
||||
}
|
||||
|
||||
func testEntityCreationIntrinsic() {
|
||||
let nexus = Nexus()
|
||||
let entity = nexus.createEntity()
|
||||
|
||||
let secondEntity = entity.createEntity()
|
||||
XCTAssertNotEqual(secondEntity, entity)
|
||||
|
||||
let thirdEntity = secondEntity.createEntity()
|
||||
XCTAssertNotEqual(secondEntity, thirdEntity)
|
||||
XCTAssertNotEqual(entity, thirdEntity)
|
||||
|
||||
let entityWithComponents = entity.createEntity(with: Position(), Name())
|
||||
XCTAssertTrue(entityWithComponents.has(Position.self))
|
||||
XCTAssertTrue(entityWithComponents.has(Name.self))
|
||||
|
||||
XCTAssertEqual(nexus.numEntities, 4)
|
||||
XCTAssertEqual(nexus.numComponents, 2)
|
||||
}
|
||||
|
||||
func testEntityDescriptions() {
|
||||
let nexus = Nexus()
|
||||
let entt = nexus.createEntity()
|
||||
XCTAssertFalse(entt.description.isEmpty)
|
||||
XCTAssertFalse(entt.debugDescription.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,6 +140,9 @@ extension EntityTests {
|
|||
// to regenerate.
|
||||
static let __allTests__EntityTests = [
|
||||
("testAllComponentsOfEntity", testAllComponentsOfEntity),
|
||||
("testComponentsIteration", testComponentsIteration),
|
||||
("testEntityCreationIntrinsic", testEntityCreationIntrinsic),
|
||||
("testEntityDescriptions", testEntityDescriptions),
|
||||
("testEntityEquality", testEntityEquality),
|
||||
("testEntityIdentifierAndIndex", testEntityIdentifierAndIndex),
|
||||
("testEntityIdGenerator", testEntityIdGenerator),
|
||||
|
|
|
|||
Loading…
Reference in New Issue