Skip to content

Commit

Permalink
[ark-physics-kit] tests: test physics component
Browse files Browse the repository at this point in the history
  • Loading branch information
markusyeo committed Apr 21, 2024
1 parent 2d569fd commit 7321112
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions ArkKitTests/ark-physics-kit-tests/PhysicsComponentTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import XCTest
import CoreGraphics
@testable import ArkKit

final class PhysicsComponentTests: XCTestCase {

func testInitializationWithCircle() {
let physicsComponent = PhysicsComponent(
shape: .circle,
radius: 10.0,
categoryBitMask: 1,
collisionBitMask: 2,
contactTestBitMask: 3
)

XCTAssertEqual(physicsComponent.shape, .circle)
XCTAssertEqual(physicsComponent.radius, 10.0)
XCTAssertNil(physicsComponent.size)
XCTAssertEqual(physicsComponent.categoryBitMask, 1)
XCTAssertEqual(physicsComponent.collisionBitMask, 2)
XCTAssertEqual(physicsComponent.contactTestBitMask, 3)
}

func testInitializationWithRectangle() {
let size = CGSize(width: 100.0, height: 50.0)
let physicsComponent = PhysicsComponent(
shape: .rectangle,
size: size,
categoryBitMask: 1,
collisionBitMask: 2,
contactTestBitMask: 3
)

XCTAssertEqual(physicsComponent.shape, .rectangle)
XCTAssertEqual(physicsComponent.size, size)
XCTAssertNil(physicsComponent.radius)
}

func testInitializationWithPolygon() {
let vertices = [CGPoint(x: 0.0, y: 0.0), CGPoint(x: 1.0, y: 1.0)]
let physicsComponent = PhysicsComponent(
shape: .polygon,
vertices: vertices,
categoryBitMask: 1,
collisionBitMask: 2,
contactTestBitMask: 3
)

XCTAssertEqual(physicsComponent.shape, .polygon)
XCTAssertEqual(physicsComponent.vertices, vertices)
XCTAssertNil(physicsComponent.radius)
XCTAssertNil(physicsComponent.size)
}

func testVelocityAndImpulse() {
var physicsComponent = PhysicsComponent(
shape: .circle,
categoryBitMask: 1,
collisionBitMask: 2,
contactTestBitMask: 3
)

let impulse = CGVector(dx: 10.0, dy: 15.0)
physicsComponent.impulse = impulse

XCTAssertEqual(physicsComponent.impulse, impulse)
XCTAssertEqual(physicsComponent.velocity, .zero)
}
}

0 comments on commit 7321112

Please sign in to comment.