-
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-animation-kit] tests: add test cases
- Loading branch information
Showing
4 changed files
with
137 additions
and
0 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
48 changes: 48 additions & 0 deletions
48
ArkKitTests/ark-animation-kit-tests/ArkAnimationInstanceTests.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,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
39
ArkKitTests/ark-animation-kit-tests/ArkAnimationTests.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,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) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
ArkKitTests/ark-animation-kit-tests/ArkAnimationsComponentTests.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,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 })) | ||
} | ||
} |