add tests for EntityStateMachine.createState

This commit is contained in:
Igor Kravchenko 2020-10-01 18:16:15 +03:00
parent 3e30812c99
commit 7bd1b3cc82
2 changed files with 19 additions and 0 deletions

View File

@ -386,6 +386,21 @@ class EntityStateMachineTests: XCTestCase {
XCTAssertTrue(entity.get(component: MockComponent.self) === component3)
}
func testCreateStateAddsState() {
let state = fsm.createState(name: "test")
let component = MockComponent()
state.add(MockComponent.self).withInstance(component)
fsm.changeState(name: "test")
XCTAssertTrue(entity.get(component: MockComponent.self) === component)
}
func testCreateStateDoesNotChangeState() {
let state = fsm.createState(name: "test")
let component = MockComponent()
state.add(MockComponent.self).withInstance(component)
XCTAssertNil(entity.get(component: MockComponent.self))
}
class MockComponent: ComponentInitializable {
let value: Int
@ -411,6 +426,8 @@ class EntityStateMachineTests: XCTestCase {
}
}
// MARK: -
class StateComponentMappingTests: XCTestCase {
func testAddReturnsSameMappingForSameComponentType() {
let state = EntityState()

View File

@ -96,6 +96,8 @@ extension EntityStateMachineTests {
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__EntityStateMachineTests = [
("testCreateStateAddsState", testCreateStateAddsState),
("testCreateStateDoesNotChangeState", testCreateStateDoesNotChangeState),
("testEnterSecondStateAddsSecondStatesComponents", testEnterSecondStateAddsSecondStatesComponents),
("testEnterSecondStateDoesNotRemoveOverlappingComponents", testEnterSecondStateDoesNotRemoveOverlappingComponents),
("testEnterSecondStateRemovesDifferentComponentsOfSameType", testEnterSecondStateRemovesDifferentComponentsOfSameType),