-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ark-physics-kit] test: skphysicsbodymanager
- Loading branch information
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
ArkKitTests/ark-physics-kit-tests/SKPhysicsBodyManagerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import XCTest | ||
@testable import ArkKit | ||
|
||
class SKPhysicsBodyManagerTests: XCTestCase { | ||
var manager: SKPhysicsBodyManager! | ||
var dummyEntity: Entity! | ||
var dummyBody: ArkSKPhysicsBody! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
manager = SKPhysicsBodyManager() | ||
dummyEntity = Entity() | ||
dummyBody = ArkSKPhysicsBody(circleOf: 10) | ||
} | ||
|
||
func testAddBody() { | ||
let added = manager.addBody(for: dummyEntity, body: dummyBody) | ||
XCTAssertTrue(added, "Should be able to add a new body.") | ||
XCTAssertEqual(manager.getBody(for: dummyEntity), dummyBody) | ||
XCTAssertEqual(manager.getEntity(for: dummyBody.node), dummyEntity) | ||
} | ||
|
||
func testRemoveBody() { | ||
_ = manager.addBody(for: dummyEntity, body: dummyBody) | ||
manager.removeBody(for: dummyEntity) | ||
|
||
XCTAssertNil(manager.getBody(for: dummyEntity), "Body should be removed.") | ||
XCTAssertNil(manager.getEntity(for: dummyBody.node), "Entity mapping should be cleared.") | ||
} | ||
|
||
func testApplyImpulseSuccessfully() { | ||
_ = manager.addBody(for: dummyEntity, body: dummyBody) | ||
let result = manager.applyImpulse(CGVector(dx: 10, dy: 20), to: dummyEntity) | ||
|
||
XCTAssertTrue(result, "Apply impulse should succeed.") | ||
} | ||
|
||
func testApplyImpulseFailsForNonexistentEntity() { | ||
let result = manager.applyImpulse(CGVector(dx: 10, dy: 20), to: dummyEntity) | ||
|
||
XCTAssertFalse(result, "Apply impulse should fail for nonexistent entity.") | ||
} | ||
|
||
func testApplyAngularImpulseSuccessfully() { | ||
_ = manager.addBody(for: dummyEntity, body: dummyBody) | ||
let result = manager.applyAngularImpulse(30, to: dummyEntity) | ||
|
||
XCTAssertTrue(result, "Apply angular impulse should succeed.") | ||
} | ||
|
||
func testApplyAngularImpulseFailsForNonexistentEntity() { | ||
let result = manager.applyAngularImpulse(30, to: dummyEntity) | ||
|
||
XCTAssertFalse(result, "Apply angular impulse should fail for nonexistent entity.") | ||
} | ||
} |