Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/fix tests after ECS refactor #43

Merged
merged 1 commit into from Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,9 +12,16 @@ import XCTest
final class SpriteComponentTests: XCTestCase {
func testEqual_initComponent() {
let player = createPlayerEntity()
let spriteComponent = SpriteComponent(entityId: player.id, image: "", textureAtlas: "", size: .zero)
XCTAssertEqual(spriteComponent.size, .zero, "Size should be initialized")
let textureSet = createTextureSet()
let spriteComponent = SpriteComponent(
entityId: player.id,
image: "",
textureSet: textureSet,
textureAtlas: "",
size: .zero)
XCTAssertEqual(spriteComponent.image, "", "Image should be initialized")
XCTAssertEqual(spriteComponent.textureSet?.run, textureSet.run, "TextureSet should be initialized")
XCTAssertEqual(spriteComponent.textureAtlas, "", "TextureAtlas should be initialized")
XCTAssertEqual(spriteComponent.size, .zero, "Size should be initialized")
}
}
23 changes: 12 additions & 11 deletions star-dash/star-dashTests/GameEngine/EntityManagerTests.swift
Expand Up @@ -14,30 +14,30 @@ final class EntityManagerTests: XCTestCase {
let entityManager = createEntityManager()
let player = createPlayerEntity()
entityManager.add(entity: player)
XCTAssertEqual(entityManager.entityMap.count, 1, "Entity should be added to the entityMap")
XCTAssertEqual(entityManager.entities.count, 1, "Entity should be added to the entityMap")
}

func testEqual_addSameEntity() {
let entityManager = createEntityManager()
let player = createPlayerEntity()
entityManager.add(entity: player)
entityManager.add(entity: player)
XCTAssertEqual(entityManager.entityMap.count, 1, "Repeated entity should not be added to the entityMap")
XCTAssertEqual(entityManager.entities.count, 1, "Repeated entity should not be added to the entityMap")
}

func testEqual_removeEntity() {
let entityManager = createEntityManager()
let player = createPlayerEntity()
entityManager.add(entity: player)
entityManager.remove(entity: player)
XCTAssertEqual(entityManager.entityMap.count, 0, "Entity should be removed from the entityMap")
XCTAssertEqual(entityManager.entities.count, 0, "Entity should be removed from the entityMap")
}

func testEqual_removeEntityNotInList() {
let entityManager = createEntityManager()
let player = createPlayerEntity()
entityManager.remove(entity: player)
XCTAssertEqual(entityManager.entityMap.count, 0, "Entity should not be removed from the entityMap")
XCTAssertEqual(entityManager.entities.count, 0, "Entity should not be removed from the entityMap")
}

func testNotNil_getEntity() {
Expand All @@ -51,27 +51,28 @@ final class EntityManagerTests: XCTestCase {
func testNotNil_getComponent() {
let entityManager = createEntityManager()
let player = createPlayerEntity()
let positionComponent = PositionComponent(entityId: player.id, position: .zero, rotation: .zero)
entityManager.add(entity: player)
player.setUpAndAdd(to: entityManager)
let positionComponent = entityManager.component(ofType: PositionComponent.self, of: player.id)
XCTAssertNotNil(positionComponent, "Component should be retrieved from the componentMap")
entityManager.add(component: positionComponent)
let retrievedComponent = entityManager.component(ofType: PositionComponent.self, of: player.id)
XCTAssertNotNil(retrievedComponent, "Component should be retrieved from the componentMap")
}

func testNil_getComponentOfRemovedEntity() {
let entityManager = createEntityManager()
let player = createPlayerEntity()
let positionComponent = PositionComponent(entityId: player.id, position: .zero, rotation: .zero)
entityManager.add(entity: player)
player.setUpAndAdd(to: entityManager)
entityManager.add(component: positionComponent)
entityManager.remove(entity: player)
let positionComponent = entityManager.component(ofType: PositionComponent.self, of: player.id)
XCTAssertNil(positionComponent, "Component should not be retrieved from the componentMap if entity is removed")
let retrievedComponent = entityManager.component(ofType: PositionComponent.self, of: player.id)
XCTAssertNil(retrievedComponent, "Component should not be retrieved from the componentMap if entity is removed")
}

func testNil_getEntityOfRemovedEntity() {
let entityManager = createEntityManager()
let player = createPlayerEntity()
entityManager.add(entity: player)
player.setUpAndAdd(to: entityManager)
entityManager.remove(entity: player)
let entity = entityManager.entity(with: player.id)
XCTAssertNil(entity, "Entity should not be retrieved from the entityMap if entity is removed")
Expand Down
6 changes: 5 additions & 1 deletion star-dash/star-dashTests/Util.swift
Expand Up @@ -9,9 +9,13 @@ import Foundation
@testable import star_dash

func createPlayerEntity() -> Player {
Player(position: CGPoint(x: 0, y: 0), playerSprite: .RedNose)
Player(id: UUID())
}

func createEntityManager() -> EntityManager {
EntityManager()
}

func createTextureSet() -> TextureSet {
TextureSet(run: "")
}