Lint tests
This commit is contained in:
parent
29cd66b947
commit
5117127ee3
|
|
@ -1,7 +1,6 @@
|
|||
included:
|
||||
- Sources
|
||||
excluded:
|
||||
- Tests
|
||||
- docs
|
||||
- build
|
||||
identifier_name:
|
||||
|
|
|
|||
|
|
@ -10,33 +10,33 @@ import FirebladeECS
|
|||
class EmptyComponent: Component { }
|
||||
|
||||
class Name: Component {
|
||||
var name: String
|
||||
init(name: String) {
|
||||
self.name = name
|
||||
}
|
||||
var name: String
|
||||
init(name: String) {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
|
||||
class Position: Component {
|
||||
var x: Int
|
||||
var y: Int
|
||||
init(x: Int, y: Int) {
|
||||
self.x = x
|
||||
self.y = y
|
||||
}
|
||||
var x: Int
|
||||
var y: Int
|
||||
init(x: Int, y: Int) {
|
||||
self.x = x
|
||||
self.y = y
|
||||
}
|
||||
}
|
||||
|
||||
class Velocity: Component {
|
||||
var a: Float
|
||||
init(a: Float) {
|
||||
self.a = a
|
||||
}
|
||||
var a: Float
|
||||
init(a: Float) {
|
||||
self.a = a
|
||||
}
|
||||
}
|
||||
|
||||
class Party: Component {
|
||||
var partying: Bool
|
||||
init(partying: Bool) {
|
||||
self.partying = partying
|
||||
}
|
||||
var partying: Bool
|
||||
init(partying: Bool) {
|
||||
self.partying = partying
|
||||
}
|
||||
}
|
||||
|
||||
class Color: Component {
|
||||
|
|
@ -46,26 +46,21 @@ class Color: Component {
|
|||
}
|
||||
|
||||
class ExampleSystem {
|
||||
private let family: Family2<Position, Velocity>
|
||||
private let family: Family2<Position, Velocity>
|
||||
|
||||
init(nexus: Nexus) {
|
||||
family = nexus.family(requiresAll: Position.self, Velocity.self, excludesAll: EmptyComponent.self)
|
||||
}
|
||||
init(nexus: Nexus) {
|
||||
family = nexus.family(requiresAll: Position.self, Velocity.self, excludesAll: EmptyComponent.self)
|
||||
}
|
||||
|
||||
func update(deltaT: Double) {
|
||||
func update(deltaT: Double) {
|
||||
family.forEach { (position: Position, velocity: Velocity) in
|
||||
position.x *= 2
|
||||
velocity.a *= 2
|
||||
|
||||
position.x *= 2
|
||||
velocity.a *= 2
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class SingleGameState: SingleComponent {
|
||||
var shouldQuit: Bool = false
|
||||
var playerHealth: Int = 67
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
class ComponentTests: XCTestCase {
|
||||
|
||||
func testMeasureStaticComponentIdentifier() {
|
||||
let number: Int = 10_000
|
||||
measure {
|
||||
|
|
|
|||
|
|
@ -5,11 +5,10 @@
|
|||
// Created by Christian Treffs on 14.02.19.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import FirebladeECS
|
||||
import XCTest
|
||||
|
||||
class HashingPerformanceTests: XCTestCase {
|
||||
|
||||
func testMeasureCombineHash() {
|
||||
let a: Set<Int> = Set<Int>([14_561_291, 26_451_562, 34_562_182, 488_972_556, 5_128_426_962, 68_211_812])
|
||||
let b: Set<Int> = Set<Int>([1_083_838, 912_312, 83_333, 71_234_555, 4_343_234])
|
||||
|
|
@ -37,6 +36,4 @@ class HashingPerformanceTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
class TypedFamilyPerformanceTests: XCTestCase {
|
||||
|
||||
let numEntities: Int = 10_000
|
||||
var nexus: Nexus!
|
||||
|
||||
|
|
@ -19,10 +18,10 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
|
||||
for i in 0..<numEntities {
|
||||
nexus.createEntity().assign(Position(x: 1 + i, y: 2 + i),
|
||||
Name(name: "myName\(i)"),
|
||||
Velocity(a: 3.14),
|
||||
EmptyComponent(),
|
||||
Color())
|
||||
Name(name: "myName\(i)"),
|
||||
Velocity(a: 3.14),
|
||||
EmptyComponent(),
|
||||
Color())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +31,6 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testMeasureTraitMatching() {
|
||||
|
||||
let a = nexus.createEntity()
|
||||
a.assign(Position(x: 1, y: 2))
|
||||
a.assign(Name(name: "myName"))
|
||||
|
|
@ -67,7 +65,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = entity
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -83,7 +81,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
.forEach { (position: Position) in
|
||||
_ = position
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, numEntities * 10)
|
||||
|
|
@ -105,7 +103,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = position
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -129,7 +127,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = position
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -152,7 +150,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = velocity
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -177,7 +175,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = velocity
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -201,7 +199,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = name
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -227,7 +225,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = name
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -252,7 +250,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = color
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -279,7 +277,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = color
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
@ -332,7 +330,7 @@ class TypedFamilyPerformanceTests: XCTestCase {
|
|||
_ = empty
|
||||
|
||||
loopCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(loopCount, family.count * 10)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ extension ComponentTests {
|
|||
// to regenerate.
|
||||
static let __allTests__ComponentTests = [
|
||||
("testMeasureComponentIdentifier", testMeasureComponentIdentifier),
|
||||
("testMeasureStaticComponentIdentifier", testMeasureStaticComponentIdentifier),
|
||||
("testMeasureStaticComponentIdentifier", testMeasureStaticComponentIdentifier)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ extension HashingPerformanceTests {
|
|||
// to regenerate.
|
||||
static let __allTests__HashingPerformanceTests = [
|
||||
("testMeasureCombineHash", testMeasureCombineHash),
|
||||
("testMeasureSetOfSetHash", testMeasureSetOfSetHash),
|
||||
("testMeasureSetOfSetHash", testMeasureSetOfSetHash)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ extension TypedFamilyPerformanceTests {
|
|||
("testPerformanceTypedFamilyFourComponents", testPerformanceTypedFamilyFourComponents),
|
||||
("testPerformanceTypedFamilyOneComponent", testPerformanceTypedFamilyOneComponent),
|
||||
("testPerformanceTypedFamilyThreeComponents", testPerformanceTypedFamilyThreeComponents),
|
||||
("testPerformanceTypedFamilyTwoComponents", testPerformanceTypedFamilyTwoComponents),
|
||||
("testPerformanceTypedFamilyTwoComponents", testPerformanceTypedFamilyTwoComponents)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ public func __allTests() -> [XCTestCaseEntry] {
|
|||
return [
|
||||
testCase(ComponentTests.__allTests__ComponentTests),
|
||||
testCase(HashingPerformanceTests.__allTests__HashingPerformanceTests),
|
||||
testCase(TypedFamilyPerformanceTests.__allTests__TypedFamilyPerformanceTests),
|
||||
testCase(TypedFamilyPerformanceTests.__allTests__TypedFamilyPerformanceTests)
|
||||
]
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,14 +5,11 @@
|
|||
// Created by Christian Treffs on 25.06.19.
|
||||
//
|
||||
|
||||
|
||||
|
||||
import FirebladeECS
|
||||
import XCTest
|
||||
|
||||
#if swift(>=5.1)
|
||||
class AccessTests: XCTestCase {
|
||||
|
||||
func testReadOnly() {
|
||||
let pos = Position(x: 1, y: 2)
|
||||
|
||||
|
|
@ -39,7 +36,6 @@ class AccessTests: XCTestCase {
|
|||
|
||||
XCTAssertEqual(writable.y, 2)
|
||||
XCTAssertEqual(pos.y, 2)
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -45,14 +45,11 @@ class Color: Component {
|
|||
var b: UInt8 = 0
|
||||
}
|
||||
|
||||
|
||||
final class SingleGameState: SingleComponent {
|
||||
var shouldQuit: Bool = false
|
||||
var playerHealth: Int = 67
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ExampleSystem {
|
||||
private let family: Family2<Position, Velocity>
|
||||
|
||||
|
|
@ -64,16 +61,11 @@ class ExampleSystem {
|
|||
family.forEach { (position: Position, velocity: Velocity) in
|
||||
position.x *= 2
|
||||
velocity.a *= 2
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ColorSystem {
|
||||
|
||||
let nexus: Nexus
|
||||
lazy var colors = nexus.family(requires: Color.self)
|
||||
|
||||
|
|
@ -87,7 +79,7 @@ class ColorSystem {
|
|||
color.r = 1
|
||||
color.g = 2
|
||||
color.b = 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +99,6 @@ class PositionSystem {
|
|||
func update() {
|
||||
positions
|
||||
.forEach { [unowned self](pos: Position) in
|
||||
|
||||
let deltaX: Double = self.velocity * ((self.randNorm() * 2) - 1)
|
||||
let deltaY: Double = self.velocity * ((self.randNorm() * 2) - 1)
|
||||
let x = pos.x + Int(deltaX)
|
||||
|
|
@ -115,8 +106,6 @@ class PositionSystem {
|
|||
|
||||
pos.x = x
|
||||
pos.y = y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,9 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
class ComponentTests: XCTestCase {
|
||||
|
||||
func testComponentIdentifier() {
|
||||
XCTAssertEqual(Position.identifier, Position.identifier)
|
||||
XCTAssertEqual(Velocity.identifier, Velocity.identifier)
|
||||
func testComponentIdentifier() {
|
||||
XCTAssertEqual(Position.identifier, Position.identifier)
|
||||
XCTAssertEqual(Velocity.identifier, Velocity.identifier)
|
||||
XCTAssertNotEqual(Velocity.identifier, Position.identifier)
|
||||
|
||||
let p1 = Position(x: 1, y: 2)
|
||||
|
|
@ -20,8 +19,5 @@ class ComponentTests: XCTestCase {
|
|||
XCTAssertEqual(p1.identifier, Position.identifier)
|
||||
XCTAssertEqual(v1.identifier, Velocity.identifier)
|
||||
XCTAssertNotEqual(v1.identifier, p1.identifier)
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,20 +9,16 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
class EntityTests: XCTestCase {
|
||||
|
||||
func testEntityIdentifierAndIndex() {
|
||||
|
||||
let min = EntityIdentifier(.min)
|
||||
XCTAssertEqual(min.index, Int(UInt32.min))
|
||||
func testEntityIdentifierAndIndex() {
|
||||
let min = EntityIdentifier(.min)
|
||||
XCTAssertEqual(min.index, Int(UInt32.min))
|
||||
|
||||
let uRand = UInt32.random(in: UInt32.min...UInt32.max)
|
||||
let rand = EntityIdentifier(uRand)
|
||||
XCTAssertEqual(rand.index, Int(uRand))
|
||||
let rand = EntityIdentifier(uRand)
|
||||
XCTAssertEqual(rand.index, Int(uRand))
|
||||
|
||||
let max = EntityIdentifier(.max)
|
||||
XCTAssertEqual(max, EntityIdentifier.invalid)
|
||||
let max = EntityIdentifier(.max)
|
||||
XCTAssertEqual(max, EntityIdentifier.invalid)
|
||||
XCTAssertEqual(max.index, Int(UInt32.max))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
import XCTest
|
||||
|
||||
class FamilyTests: XCTestCase {
|
||||
|
||||
var nexus: Nexus!
|
||||
|
||||
override func setUp() {
|
||||
|
|
@ -29,7 +28,6 @@ class FamilyTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testFamilyCreation() {
|
||||
|
||||
let family = nexus.family(requires: Position.self,
|
||||
excludesAll: Name.self)
|
||||
|
||||
|
|
@ -44,7 +42,6 @@ class FamilyTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testFamilyReuse() {
|
||||
|
||||
let familyA = nexus.family(requires: Position.self,
|
||||
excludesAll: Name.self)
|
||||
|
||||
|
|
@ -83,7 +80,6 @@ class FamilyTests: XCTestCase {
|
|||
XCTAssertEqual(nexus.numFamilies, 1)
|
||||
XCTAssertEqual(nexus.numComponents, 0)
|
||||
XCTAssertEqual(nexus.numEntities, 0)
|
||||
|
||||
}
|
||||
|
||||
func testFamilyLateMember() {
|
||||
|
|
@ -121,7 +117,7 @@ class FamilyTests: XCTestCase {
|
|||
|
||||
familyA
|
||||
.entityAndComponents
|
||||
.forEach { (entity: Entity, position: Position) in
|
||||
.forEach { (entity: Entity, _: Position) in
|
||||
entity.assign(Velocity(a: 3.14))
|
||||
entity.remove(Position.self)
|
||||
}
|
||||
|
|
@ -132,17 +128,15 @@ class FamilyTests: XCTestCase {
|
|||
familyB
|
||||
.entityAndComponents
|
||||
.forEach { (entity: Entity, velocity: Velocity) in
|
||||
entity.assign(Position(x: 1, y: 2))
|
||||
entity.remove(velocity)
|
||||
}
|
||||
entity.assign(Position(x: 1, y: 2))
|
||||
entity.remove(velocity)
|
||||
}
|
||||
|
||||
XCTAssertEqual(familyA.count, 10)
|
||||
XCTAssertEqual(familyB.count, 0)
|
||||
|
||||
}
|
||||
|
||||
func testFamilyMemberBasicIteration() {
|
||||
|
||||
for i in 0..<1000 {
|
||||
nexus.createEntity(with: Position(x: i + 1, y: i + 2))
|
||||
nexus.createEntity(with: Velocity(a: Float(i)))
|
||||
|
|
@ -181,8 +175,7 @@ class FamilyTests: XCTestCase {
|
|||
.prefix(currentCount)
|
||||
.forEach { (entity: Entity) in
|
||||
entity.destroy()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertEqual(family.memberIds.count, (count / 2))
|
||||
|
||||
|
|
@ -192,5 +185,4 @@ class FamilyTests: XCTestCase {
|
|||
|
||||
XCTAssertEqual(family.memberIds.count, count + (count / 2))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
class FamilyTraitsTests: XCTestCase {
|
||||
|
||||
var nexus: Nexus!
|
||||
|
||||
override func setUp() {
|
||||
|
|
@ -23,7 +22,6 @@ class FamilyTraitsTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testTraitCommutativity() {
|
||||
|
||||
let t1 = FamilyTraitSet(requiresAll: [Position.self, Velocity.self],
|
||||
excludesAll: [Name.self])
|
||||
let t2 = FamilyTraitSet(requiresAll: [Velocity.self, Position.self],
|
||||
|
|
@ -31,11 +29,9 @@ class FamilyTraitsTests: XCTestCase {
|
|||
|
||||
XCTAssertEqual(t1, t2)
|
||||
XCTAssertEqual(t1.hashValue, t2.hashValue)
|
||||
|
||||
}
|
||||
|
||||
func testTraitMatching() {
|
||||
|
||||
let a = nexus.createEntity()
|
||||
a.assign(Position(x: 1, y: 2))
|
||||
a.assign(Name(name: "myName"))
|
||||
|
|
@ -49,7 +45,5 @@ class FamilyTraitsTests: XCTestCase {
|
|||
|
||||
XCTAssertFalse(noMatch.canBecomeMember(a))
|
||||
XCTAssertTrue(isMatch.canBecomeMember(a))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
import XCTest
|
||||
|
||||
class HashingTests: XCTestCase {
|
||||
|
||||
func makeComponent() -> Int {
|
||||
let upperBound: Int = 44
|
||||
let range = UInt32.min...UInt32.max
|
||||
|
|
@ -25,7 +24,6 @@ class HashingTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testCollisionsInCritialRange() {
|
||||
|
||||
var hashSet: Set<Int> = Set<Int>()
|
||||
|
||||
var range: CountableRange<UInt32> = 0 ..< 1_000_000
|
||||
|
|
@ -52,6 +50,4 @@ class HashingTests: XCTestCase {
|
|||
XCTAssert(EntityComponentHash.decompose(h, with: entityId) == cH)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,25 +9,24 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
class NexusTests: XCTestCase {
|
||||
|
||||
var nexus: Nexus!
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
nexus = Nexus()
|
||||
}
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
override func tearDown() {
|
||||
nexus = nil
|
||||
super.tearDown()
|
||||
}
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testEntityCreate() {
|
||||
func testEntityCreate() {
|
||||
XCTAssertEqual(nexus.numEntities, 0)
|
||||
|
||||
let e0 = nexus.createEntity()
|
||||
let e0 = nexus.createEntity()
|
||||
|
||||
XCTAssertEqual(e0.identifier.index, 0)
|
||||
XCTAssertEqual(e0.identifier.index, 0)
|
||||
XCTAssertEqual(nexus.numEntities, 1)
|
||||
|
||||
let e1 = nexus.createEntity(with: Name(name: "Entity 1"))
|
||||
|
|
@ -37,7 +36,7 @@ class NexusTests: XCTestCase {
|
|||
|
||||
//FIXME: XCTAssertNil(e0.name)
|
||||
//FIXME: XCTAssertEqual(e1.name, "Entity 1")
|
||||
}
|
||||
}
|
||||
|
||||
func testEntityDestroy() {
|
||||
testEntityCreate()
|
||||
|
|
@ -61,72 +60,69 @@ class NexusTests: XCTestCase {
|
|||
XCTAssertEqual(nexus.numEntities, 0)
|
||||
}
|
||||
|
||||
func testComponentCreation() {
|
||||
func testComponentCreation() {
|
||||
XCTAssert(nexus.numEntities == 0)
|
||||
|
||||
XCTAssert(nexus.numEntities == 0)
|
||||
let e0: Entity = nexus.createEntity()
|
||||
|
||||
let e0: Entity = nexus.createEntity()
|
||||
let p0 = Position(x: 1, y: 2)
|
||||
|
||||
let p0 = Position(x: 1, y: 2)
|
||||
|
||||
e0.assign(p0)
|
||||
e0.assign(p0)
|
||||
// component collision: e0.assign(p0)
|
||||
|
||||
XCTAssert(e0.hasComponents)
|
||||
XCTAssert(e0.numComponents == 1)
|
||||
XCTAssert(e0.hasComponents)
|
||||
XCTAssert(e0.numComponents == 1)
|
||||
|
||||
let rP0: Position = e0.get(component: Position.self)!
|
||||
XCTAssert(rP0.x == 1)
|
||||
XCTAssert(rP0.y == 2)
|
||||
}
|
||||
let rP0: Position = e0.get(component: Position.self)!
|
||||
XCTAssert(rP0.x == 1)
|
||||
XCTAssert(rP0.y == 2)
|
||||
}
|
||||
|
||||
func testComponentDeletion() {
|
||||
func testComponentDeletion() {
|
||||
let identifier: EntityIdentifier = nexus.createEntity().identifier
|
||||
|
||||
let identifier: EntityIdentifier = nexus.createEntity().identifier
|
||||
let e0 = nexus.get(entity: identifier)!
|
||||
|
||||
let e0 = nexus.get(entity: identifier)!
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
e0.remove(Position.self)
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
e0.remove(Position.self)
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
let n0 = Name(name: "myName")
|
||||
let p0 = Position(x: 99, y: 111)
|
||||
|
||||
let n0 = Name(name: "myName")
|
||||
let p0 = Position(x: 99, y: 111)
|
||||
e0.assign(n0)
|
||||
XCTAssert(e0.numComponents == 1)
|
||||
XCTAssert(e0.hasComponents)
|
||||
|
||||
e0.assign(n0)
|
||||
XCTAssert(e0.numComponents == 1)
|
||||
XCTAssert(e0.hasComponents)
|
||||
e0.remove(Name.self)
|
||||
|
||||
e0.remove(Name.self)
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
XCTAssert(!e0.hasComponents)
|
||||
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
XCTAssert(!e0.hasComponents)
|
||||
e0.assign(p0)
|
||||
|
||||
e0.assign(p0)
|
||||
XCTAssert(e0.numComponents == 1)
|
||||
XCTAssert(e0.hasComponents)
|
||||
|
||||
XCTAssert(e0.numComponents == 1)
|
||||
XCTAssert(e0.hasComponents)
|
||||
e0.remove(p0)
|
||||
|
||||
e0.remove(p0)
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
XCTAssert(!e0.hasComponents)
|
||||
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
XCTAssert(!e0.hasComponents)
|
||||
e0.assign(n0)
|
||||
e0.assign(p0)
|
||||
|
||||
e0.assign(n0)
|
||||
e0.assign(p0)
|
||||
XCTAssert(e0.numComponents == 2)
|
||||
let (name, position) = e0.get(components: Name.self, Position.self)
|
||||
|
||||
XCTAssert(e0.numComponents == 2)
|
||||
let (name, position) = e0.get(components: Name.self, Position.self)
|
||||
XCTAssert(name?.name == "myName")
|
||||
XCTAssert(position?.x == 99)
|
||||
XCTAssert(position?.y == 111)
|
||||
|
||||
XCTAssert(name?.name == "myName")
|
||||
XCTAssert(position?.x == 99)
|
||||
XCTAssert(position?.y == 111)
|
||||
e0.destroy()
|
||||
|
||||
e0.destroy()
|
||||
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
|
||||
}
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
}
|
||||
|
||||
func testComponentRetrieval() {
|
||||
let pos = Position(x: 1, y: 2)
|
||||
|
|
@ -136,33 +132,29 @@ class NexusTests: XCTestCase {
|
|||
|
||||
let (rPos, rName, rVel) = entity.get(components: Position.self, Name.self, Velocity.self)
|
||||
|
||||
|
||||
XCTAssertTrue(rPos === pos)
|
||||
XCTAssertTrue(rName === name)
|
||||
XCTAssertTrue(rVel === vel)
|
||||
|
||||
}
|
||||
|
||||
func testComponentUniqueness() {
|
||||
let a = nexus.createEntity()
|
||||
let b = nexus.createEntity()
|
||||
let c = nexus.createEntity()
|
||||
func testComponentUniqueness() {
|
||||
let a = nexus.createEntity()
|
||||
let b = nexus.createEntity()
|
||||
let c = nexus.createEntity()
|
||||
|
||||
XCTAssert(nexus.numEntities == 3)
|
||||
XCTAssert(nexus.numEntities == 3)
|
||||
|
||||
a.assign(Position(x: 0, y: 0))
|
||||
b.assign(Position(x: 0, y: 0))
|
||||
c.assign(Position(x: 0, y: 0))
|
||||
a.assign(Position(x: 0, y: 0))
|
||||
b.assign(Position(x: 0, y: 0))
|
||||
c.assign(Position(x: 0, y: 0))
|
||||
|
||||
let pA: Position = a.get()!
|
||||
let pB: Position = b.get()!
|
||||
let pA: Position = a.get()!
|
||||
let pB: Position = b.get()!
|
||||
|
||||
pA.x = 23
|
||||
pA.y = 32
|
||||
|
||||
XCTAssert(pB.x != pA.x)
|
||||
XCTAssert(pB.y != pA.y)
|
||||
|
||||
}
|
||||
pA.x = 23
|
||||
pA.y = 32
|
||||
|
||||
XCTAssert(pB.x != pA.x)
|
||||
XCTAssert(pB.y != pA.y)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ class SingleTests: XCTestCase {
|
|||
XCTAssertEqual(singleA, singleB)
|
||||
}
|
||||
|
||||
|
||||
func testSingleEntityAndComponentCreation() {
|
||||
let single = nexus.single(SingleGameState.self)
|
||||
let gameState = SingleGameState()
|
||||
|
|
@ -54,7 +53,6 @@ class SingleTests: XCTestCase {
|
|||
XCTAssertNotNil(single.component)
|
||||
XCTAssertEqual(single.component.shouldQuit, gameState.shouldQuit)
|
||||
XCTAssertEqual(single.component.playerHealth, gameState.playerHealth)
|
||||
|
||||
}
|
||||
|
||||
func testSingleCreationOnExistingFamilyMember() {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
import XCTest
|
||||
|
||||
class SparseSetTests: XCTestCase {
|
||||
|
||||
var set: UnorderedSparseSet<Position>!
|
||||
|
||||
override func setUp() {
|
||||
|
|
@ -23,7 +22,6 @@ class SparseSetTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testSparseSetAdd() {
|
||||
|
||||
let num: Int = 100
|
||||
|
||||
for idx in 0..<num {
|
||||
|
|
@ -47,7 +45,6 @@ class SparseSetTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testSparseSetAddAndReplace() {
|
||||
|
||||
let p1 = Position(x: 1, y: 1)
|
||||
let p2 = Position(x: 2, y: 2)
|
||||
|
||||
|
|
@ -60,11 +57,9 @@ class SparseSetTests: XCTestCase {
|
|||
|
||||
XCTAssertEqual(set.get(at: 10)?.x, p2.x)
|
||||
XCTAssertEqual(set.count, 1)
|
||||
|
||||
}
|
||||
|
||||
func testSparseSetGet() {
|
||||
|
||||
let p1 = Position(x: 1, y: 1)
|
||||
|
||||
set.insert(p1, at: 10)
|
||||
|
|
@ -79,7 +74,6 @@ class SparseSetTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testSparseSetRemove() {
|
||||
|
||||
let num: Int = 7
|
||||
|
||||
for idx in 0..<num {
|
||||
|
|
@ -358,7 +352,6 @@ class SparseSetTests: XCTestCase {
|
|||
XCTAssertEqual(set.sparse[5], nil)
|
||||
XCTAssertEqual(set.sparse[6], nil)
|
||||
XCTAssertEqual(set.sparse[7], nil)
|
||||
|
||||
}
|
||||
|
||||
func testSparseSetRemoveAndAdd() {
|
||||
|
|
@ -384,11 +377,9 @@ class SparseSetTests: XCTestCase {
|
|||
XCTAssertEqual(set.get(at: 56)?.x, 56)
|
||||
XCTAssertEqual(set.get(at: 99)?.x, 99)
|
||||
XCTAssertEqual(set.get(at: 3)?.x, 3)
|
||||
|
||||
}
|
||||
|
||||
func testSparseSetRemoveNonPresent() {
|
||||
|
||||
XCTAssertTrue(set.isEmpty)
|
||||
XCTAssertNil(set.remove(at: 100))
|
||||
XCTAssertTrue(set.isEmpty)
|
||||
|
|
@ -427,11 +418,9 @@ class SparseSetTests: XCTestCase {
|
|||
XCTAssertTrue(set.get(at: 0) === a)
|
||||
|
||||
XCTAssertEqual(set.count, 1)
|
||||
|
||||
}
|
||||
|
||||
func testSparseSetNonCongiuousData() {
|
||||
|
||||
var indices: Set<Int> = [0, 30, 1, 21, 78, 56, 99, 3]
|
||||
|
||||
for idx in indices {
|
||||
|
|
@ -462,7 +451,6 @@ class SparseSetTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testSparseSetClear() {
|
||||
|
||||
let num: Int = 100
|
||||
|
||||
XCTAssertEqual(set.count, 0)
|
||||
|
|
@ -506,7 +494,6 @@ class SparseSetTests: XCTestCase {
|
|||
|
||||
// NOTE: this tests only dense insertion order, this is no guarantee for the real ordering.
|
||||
XCTAssertEqual(string, "Hello World")
|
||||
|
||||
}
|
||||
|
||||
func testSubscript() {
|
||||
|
|
@ -541,7 +528,6 @@ class SparseSetTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testStartEndIndex() {
|
||||
|
||||
let set = UnorderedSparseSet<Character>()
|
||||
|
||||
set.insert("C", at: 33)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
import XCTest
|
||||
|
||||
class SystemsTests: XCTestCase {
|
||||
|
||||
var nexus: Nexus!
|
||||
var colorSystem: ColorSystem!
|
||||
var positionSystem: PositionSystem!
|
||||
|
|
@ -26,11 +25,9 @@ class SystemsTests: XCTestCase {
|
|||
positionSystem = nil
|
||||
nexus = nil
|
||||
super.tearDown()
|
||||
|
||||
}
|
||||
|
||||
func testSystemsUpdate() {
|
||||
|
||||
let num: Int = 10_000
|
||||
|
||||
colorSystem.update()
|
||||
|
|
@ -124,7 +121,6 @@ class SystemsTests: XCTestCase {
|
|||
.prefix(count)
|
||||
.forEach { (entity: Entity) in
|
||||
entity.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ extension ComponentTests {
|
|||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__ComponentTests = [
|
||||
("testComponentIdentifier", testComponentIdentifier),
|
||||
("testComponentIdentifier", testComponentIdentifier)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ extension EntityTests {
|
|||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__EntityTests = [
|
||||
("testEntityIdentifierAndIndex", testEntityIdentifierAndIndex),
|
||||
("testEntityIdentifierAndIndex", testEntityIdentifierAndIndex)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ extension FamilyTests {
|
|||
("testFamilyExchange", testFamilyExchange),
|
||||
("testFamilyLateMember", testFamilyLateMember),
|
||||
("testFamilyMemberBasicIteration", testFamilyMemberBasicIteration),
|
||||
("testFamilyReuse", testFamilyReuse),
|
||||
("testFamilyReuse", testFamilyReuse)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ extension FamilyTraitsTests {
|
|||
// to regenerate.
|
||||
static let __allTests__FamilyTraitsTests = [
|
||||
("testTraitCommutativity", testTraitCommutativity),
|
||||
("testTraitMatching", testTraitMatching),
|
||||
("testTraitMatching", testTraitMatching)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ extension HashingTests {
|
|||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__HashingTests = [
|
||||
("testCollisionsInCritialRange", testCollisionsInCritialRange),
|
||||
("testCollisionsInCritialRange", testCollisionsInCritialRange)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ extension NexusTests {
|
|||
("testComponentRetrieval", testComponentRetrieval),
|
||||
("testComponentUniqueness", testComponentUniqueness),
|
||||
("testEntityCreate", testEntityCreate),
|
||||
("testEntityDestroy", testEntityDestroy),
|
||||
("testEntityDestroy", testEntityDestroy)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ extension SingleTests {
|
|||
("testSingleCreation", testSingleCreation),
|
||||
("testSingleCreationOnExistingFamilyMember", testSingleCreationOnExistingFamilyMember),
|
||||
("testSingleEntityAndComponentCreation", testSingleEntityAndComponentCreation),
|
||||
("testSingleReuse", testSingleReuse),
|
||||
("testSingleReuse", testSingleReuse)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ extension SparseSetTests {
|
|||
("testSparseSetRemoveAndAdd", testSparseSetRemoveAndAdd),
|
||||
("testSparseSetRemoveNonPresent", testSparseSetRemoveNonPresent),
|
||||
("testStartEndIndex", testStartEndIndex),
|
||||
("testSubscript", testSubscript),
|
||||
("testSubscript", testSubscript)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ extension SystemsTests {
|
|||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__SystemsTests = [
|
||||
("testSystemsUpdate", testSystemsUpdate),
|
||||
("testSystemsUpdate", testSystemsUpdate)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ public func __allTests() -> [XCTestCaseEntry] {
|
|||
testCase(NexusTests.__allTests__NexusTests),
|
||||
testCase(SingleTests.__allTests__SingleTests),
|
||||
testCase(SparseSetTests.__allTests__SparseSetTests),
|
||||
testCase(SystemsTests.__allTests__SystemsTests),
|
||||
testCase(SystemsTests.__allTests__SystemsTests)
|
||||
]
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue