Skip to content

Commit

Permalink
updated unit tests with hasComponent function
Browse files Browse the repository at this point in the history
  • Loading branch information
untoldengine committed Jan 15, 2025
1 parent 150d550 commit 372e818
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 13 additions & 0 deletions Tests/UntoldEngineRenderTests/RendererTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ final class RendererTests: XCTestCase {
XCTAssertEqual(0, renderComponent.mesh.count, "Mesh should be empty")
XCTAssertNil(skeletonComponent.skeleton, "Skeleton should be nil")
XCTAssertNil(getMeshesForEntity(entityId: entityId), "Entity-Mesh map should be nil")

// test if components have been removed
XCTAssertFalse(hasComponent(entityId: entityId, componentType: RenderComponent.self))
XCTAssertFalse(hasComponent(entityId: entityId, componentType: LocalTransformComponent.self))
XCTAssertFalse(hasComponent(entityId: entityId, componentType: WorldTransformComponent.self))
XCTAssertFalse(hasComponent(entityId: entityId, componentType: SkeletonComponent.self))
}

func testRemoveEntityAnimations() {
Expand All @@ -350,6 +356,9 @@ final class RendererTests: XCTestCase {

XCTAssertNil(animationComponent.currentAnimation, "Current Animation should be Nil")
XCTAssertEqual(animationComponent.animationClips.count, 0, "animation clips should be 0")

// test if component have been removed
XCTAssertFalse(hasComponent(entityId: entityId, componentType: AnimationComponent.self))
}

func testRemoveEntityKinetics() {
Expand All @@ -368,6 +377,10 @@ final class RendererTests: XCTestCase {
removeEntityKinetics(entityId: entityId)

XCTAssertEqual(kineticComponent.forces.count, 0, "All forces should be removed")

// test if components have been removed
XCTAssertFalse(hasComponent(entityId: entityId, componentType: PhysicsComponents.self))
XCTAssertFalse(hasComponent(entityId: entityId, componentType: KineticComponent.self))
}

private func testGenerateRenderTarget(targetName: String, texture: MTLTexture, isDepthTexture: Bool = false) {
Expand Down
14 changes: 2 additions & 12 deletions Tests/UntoldEngineTests/ScenegraphTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,13 @@ final class SceneGraphTests: XCTestCase {
setParent(childId: grandchildEntity, parentId: childEntity)
setParent(childId: childEntity, parentId: rootEntity)

let childEntityIndex = getEntityIndex(childEntity)
let grandChildEntityIndex = getEntityIndex(grandchildEntity)

let parentScenegraph = scene.get(component: ScenegraphComponent.self, for: rootEntity)

removeEntity(entityId: childEntity, containsResources: false)

XCTAssertEqual(parentScenegraph?.children.count, 0, "Children count should be zero")

let componentId: Int = getComponentId(for: ScenegraphComponent.self)

let childComponentMask = scene.entities[Int(childEntityIndex)].mask

XCTAssertFalse(childComponentMask.test(componentId), "Component should be set to false for child")

let grandChildComponentMask = scene.entities[Int(grandChildEntityIndex)].mask

XCTAssertFalse(grandChildComponentMask.test(componentId), "Component should be set to false for grand child")
XCTAssertFalse(hasComponent(entityId: childEntity, componentType: ScenegraphComponent.self))
XCTAssertFalse(hasComponent(entityId: grandchildEntity, componentType: ScenegraphComponent.self))
}
}

0 comments on commit 372e818

Please sign in to comment.