Skip to content

Commit

Permalink
[ark-animation-kit] tests: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
markusyeo committed Apr 21, 2024
1 parent 5081c0a commit 2d569fd
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ArkKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@
2894242E2BD554E50063C5EF /* ButtonRenderableComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2894242D2BD554E50063C5EF /* ButtonRenderableComponentTests.swift */; };
289424302BD554EF0063C5EF /* JoystickRenderableComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2894242F2BD554EF0063C5EF /* JoystickRenderableComponentTests.swift */; };
289424362BD557D30063C5EF /* MockArkEventManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 289424352BD557D30063C5EF /* MockArkEventManager.swift */; };
289424382BD55BCC0063C5EF /* PhysicsComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 289424372BD55BCC0063C5EF /* PhysicsComponentTests.swift */; };
2894243B2BD55BFE0063C5EF /* ArkAnimationsComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2894243A2BD55BFE0063C5EF /* ArkAnimationsComponentTests.swift */; };
2894243D2BD55C1D0063C5EF /* ArkAnimationInstanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2894243C2BD55C1D0063C5EF /* ArkAnimationInstanceTests.swift */; };
2894243F2BD55C2D0063C5EF /* ArkAnimationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2894243E2BD55C2D0063C5EF /* ArkAnimationTests.swift */; };
28A032DC2BAD4E8200851BFF /* StopWatchComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28A032DB2BAD4E8200851BFF /* StopWatchComponent.swift */; };
28A032DF2BAD4F2A00851BFF /* ArkTimeSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28A032DE2BAD4F2A00851BFF /* ArkTimeSystem.swift */; };
28A032E52BAD781900851BFF /* AbstractPhysicsArkSimulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28A032E42BAD781900851BFF /* AbstractPhysicsArkSimulator.swift */; };
Expand Down Expand Up @@ -581,6 +585,10 @@
2894242D2BD554E50063C5EF /* ButtonRenderableComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonRenderableComponentTests.swift; sourceTree = "<group>"; };
2894242F2BD554EF0063C5EF /* JoystickRenderableComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoystickRenderableComponentTests.swift; sourceTree = "<group>"; };
289424352BD557D30063C5EF /* MockArkEventManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockArkEventManager.swift; sourceTree = "<group>"; };
289424372BD55BCC0063C5EF /* PhysicsComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhysicsComponentTests.swift; sourceTree = "<group>"; };
2894243A2BD55BFE0063C5EF /* ArkAnimationsComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArkAnimationsComponentTests.swift; sourceTree = "<group>"; };
2894243C2BD55C1D0063C5EF /* ArkAnimationInstanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArkAnimationInstanceTests.swift; sourceTree = "<group>"; };
2894243E2BD55C2D0063C5EF /* ArkAnimationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArkAnimationTests.swift; sourceTree = "<group>"; };
28A032DB2BAD4E8200851BFF /* StopWatchComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StopWatchComponent.swift; sourceTree = "<group>"; };
28A032DE2BAD4F2A00851BFF /* ArkTimeSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArkTimeSystem.swift; sourceTree = "<group>"; };
28A032E42BAD781900851BFF /* AbstractPhysicsArkSimulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AbstractPhysicsArkSimulator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1474,6 +1482,16 @@
path = "ark-render-kit-tests";
sourceTree = "<group>";
};
289424392BD55BF10063C5EF /* ark-animation-kit-tests */ = {
isa = PBXGroup;
children = (
2894243A2BD55BFE0063C5EF /* ArkAnimationsComponentTests.swift */,
2894243C2BD55C1D0063C5EF /* ArkAnimationInstanceTests.swift */,
2894243E2BD55C2D0063C5EF /* ArkAnimationTests.swift */,
);
path = "ark-animation-kit-tests";
sourceTree = "<group>";
};
28A032DD2BAD4ED200851BFF /* InternalSystems */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1516,6 +1534,7 @@
28A34CFA2BD3A31900BD3F4C /* SKPhysicsBodyManagerTests.swift */,
28A34D072BD3BCEC00BD3F4C /* AbstractArkPhysicsSceneTests.swift */,
28A34D092BD3BCFE00BD3F4C /* AbstractArkPhysicsBodyTests.swift */,
289424372BD55BCC0063C5EF /* PhysicsComponentTests.swift */,
);
path = "ark-physics-kit-tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -2069,6 +2088,7 @@
AD787A662B9C6373003EBBD0 /* ArkKitTests */ = {
isa = PBXGroup;
children = (
289424392BD55BF10063C5EF /* ark-animation-kit-tests */,
289424242BD551BC0063C5EF /* ark-render-kit-tests */,
02EDED402BD53D9100FFA756 /* ark-tests */,
02EDED392BD5397B00FFA756 /* ark-camera-kit-tests */,
Expand Down Expand Up @@ -2587,6 +2607,7 @@
AD3ECF492BB01CF2002C758D /* ArkECSTests.swift in Sources */,
AD0B9E112BD3C2940095C001 /* ComponentRegistryTests.swift in Sources */,
AD0B9E1B2BD3C9F40095C001 /* ArkHostNetworkSubscriberTests.swift in Sources */,
2894243B2BD55BFE0063C5EF /* ArkAnimationsComponentTests.swift in Sources */,
AD3ECF472BB01ABC002C758D /* SystemManagerTests.swift in Sources */,
281AE1282BD3911F00B79B91 /* HeapTests.swift in Sources */,
2894242A2BD551F40063C5EF /* PolygonRenderableComponentTests.swift in Sources */,
Expand All @@ -2607,6 +2628,7 @@
281AE12A2BD3928100B79B91 /* QueueTests.swift in Sources */,
281AE12E2BD3928D00B79B91 /* OrderedDictionaryTests.swift in Sources */,
28A34D082BD3BCEC00BD3F4C /* AbstractArkPhysicsSceneTests.swift in Sources */,
289424382BD55BCC0063C5EF /* PhysicsComponentTests.swift in Sources */,
02A438262BB007C9000135BC /* ArkRuleKitTests.swift in Sources */,
02EDED3B2BD5399200FFA756 /* ArkCameraContextTests.swift in Sources */,
02EDED442BD543E000FFA756 /* MockRootView.swift in Sources */,
Expand All @@ -2615,6 +2637,8 @@
AD0B9E232BD4D26C0095C001 /* MockHostNetworkPublisher.swift in Sources */,
28A34D0C2BD3C16E00BD3F4C /* MockBaseSKScene.swift in Sources */,
28A34D1B2BD3E7AA00BD3F4C /* MockArkSKPhysicsBodyFactory.swift in Sources */,
2894243D2BD55C1D0063C5EF /* ArkAnimationInstanceTests.swift in Sources */,
2894243F2BD55C2D0063C5EF /* ArkAnimationTests.swift in Sources */,
02A4382F2BB00D9C000135BC /* MockDisplayContext.swift in Sources */,
02A438292BB00D2B000135BC /* MockAction.swift in Sources */,
AD0B9E172BD3C8960095C001 /* ArkMultiplayerGameLoopTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import XCTest
@testable import ArkKit

final class ArkAnimationInstanceTests: XCTestCase {

func testInitialization() {
let animation = ArkAnimation<String>().keyframe("Frame1", duration: 1.0)
let animationInstance = ArkAnimationInstance(animation: animation)

XCTAssertTrue(animationInstance.isPlaying)
XCTAssertEqual(animationInstance.currentFrame.value, "Frame1")
XCTAssertFalse(animationInstance.shouldDestroy)
}

func testPlayPauseStop() {
var animationInstance = ArkAnimationInstance(
animation: ArkAnimation<String>().keyframe("Frame1", duration: 1.0),
isPlaying: false
)

animationInstance.play()
XCTAssertTrue(animationInstance.isPlaying)

animationInstance.pause()
XCTAssertFalse(animationInstance.isPlaying)

animationInstance.stop()
XCTAssertTrue(animationInstance.shouldDestroy)
}

func testAdvanceThroughKeyframes() {
let animation = ArkAnimation<Double>()
.keyframe(0.0, duration: 1.0)
.keyframe(10.0, duration: 1.0)
.keyframe(20.0, duration: 1.0)

var animationInstance = ArkAnimationInstance(animation: animation)

animationInstance.advance(by: 0.5)
XCTAssertEqual(animationInstance.currentFrame.value, 0.0)

animationInstance.advance(by: 0.5)
XCTAssertEqual(animationInstance.currentFrame.value, 10.0)

animationInstance.advance(by: 1.0)
XCTAssertEqual(animationInstance.currentFrame.value, 20.0)
}
}
39 changes: 39 additions & 0 deletions ArkKitTests/ark-animation-kit-tests/ArkAnimationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import XCTest
@testable import ArkKit

final class ArkAnimationTests: XCTestCase {

func testKeyframeAddition() {
var animation = ArkAnimation<String>()
animation = animation.keyframe("Frame1", duration: 1.0)

XCTAssertEqual(animation.keyframes.count, 1)
XCTAssertEqual(animation.keyframes.first?.value, "Frame1")
}

func testLoop() {
var animation = ArkAnimation<String>().keyframe("Frame1", duration: 1.0)
animation = animation.loop()

XCTAssertTrue(animation.isLooping)
}

func testReverse() {
var animation = ArkAnimation<String>()
.keyframe("Frame1", duration: 1.0)
.keyframe("Frame2", duration: 2.0)

animation = animation.reverse()

XCTAssertEqual(animation.keyframes.count, 2)
XCTAssertEqual(animation.keyframes.first?.value, "Frame2")
XCTAssertEqual(animation.keyframes.last?.value, "Frame1")
}

func testRepeat() {
var animation = ArkAnimation<String>().keyframe("Frame1", duration: 1.0)
animation = animation.repeat(times: 3)

XCTAssertEqual(animation.runCount, 3)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import XCTest
@testable import ArkKit

final class ArkAnimationsComponentTests: XCTestCase {

func testAddAnimation() {
var animationsComponent = ArkAnimationsComponent()
let animation = ArkAnimationInstance(animation: ArkAnimation<String>().keyframe("Frame1", duration: 1.0))

animationsComponent.addAnimation(animation)

XCTAssertEqual(animationsComponent.animations.count, 1)
XCTAssertTrue(animationsComponent.animations.contains(where: { $0 === animation }))
}

func testRemoveAnimation() {
var animationsComponent = ArkAnimationsComponent()
let animation = ArkAnimationInstance(animation: ArkAnimation<String>().keyframe("Frame1", duration: 1.0))

animationsComponent.addAnimation(animation)
animationsComponent.removeAnimation(animation)

XCTAssertEqual(animationsComponent.animations.count, 0)
XCTAssertFalse(animationsComponent.animations.contains(where: { $0 === animation }))
}
}

0 comments on commit 2d569fd

Please sign in to comment.