You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.5 KiB
86 lines
2.5 KiB
import XCTest
|
|
@testable import DropTwoCore
|
|
|
|
final class CropPlanTests: XCTestCase {
|
|
func testDefaultPlanIsCenteredWithSingleKeyframe() {
|
|
let plan = CropPlan()
|
|
|
|
XCTAssertTrue(plan.isDefault)
|
|
XCTAssertEqual(plan.keyframes.count, 1)
|
|
XCTAssertEqual(plan.offset(at: 0), 0)
|
|
XCTAssertEqual(plan.offset(at: 100), 0)
|
|
}
|
|
|
|
func testOffsetIsClamped() {
|
|
XCTAssertEqual(CropPlan(offset: 3).offset(at: 0), 1)
|
|
XCTAssertEqual(CropPlan(offset: -3).offset(at: 0), -1)
|
|
}
|
|
|
|
func testKeyframeHoldsUntilNextOne() {
|
|
var plan = CropPlan(offset: -1)
|
|
plan.addKeyframe(at: 2)
|
|
plan.setOffset(1, at: 2)
|
|
|
|
XCTAssertEqual(plan.offset(at: 0), -1)
|
|
XCTAssertEqual(plan.offset(at: 1.99), -1)
|
|
XCTAssertEqual(plan.offset(at: 2), 1)
|
|
XCTAssertEqual(plan.offset(at: 10), 1)
|
|
XCTAssertFalse(plan.isDefault)
|
|
}
|
|
|
|
func testNewKeyframeTakesOverCurrentOffset() {
|
|
var plan = CropPlan(offset: 0.4)
|
|
let keyframe = plan.addKeyframe(at: 3)
|
|
|
|
XCTAssertEqual(keyframe?.offset, 0.4)
|
|
}
|
|
|
|
func testKeyframeAtExistingTimeIsIgnored() {
|
|
var plan = CropPlan()
|
|
plan.addKeyframe(at: 2)
|
|
|
|
XCTAssertNil(plan.addKeyframe(at: 2.0005))
|
|
XCTAssertNil(plan.addKeyframe(at: 0))
|
|
XCTAssertEqual(plan.keyframes.count, 2)
|
|
}
|
|
|
|
func testKeyframesStaySorted() {
|
|
var plan = CropPlan()
|
|
plan.addKeyframe(at: 5)
|
|
plan.addKeyframe(at: 1)
|
|
plan.addKeyframe(at: 3)
|
|
|
|
XCTAssertEqual(plan.keyframes.map(\.time), [0, 1, 3, 5])
|
|
}
|
|
|
|
func testFirstKeyframeCannotBeRemoved() {
|
|
var plan = CropPlan()
|
|
let second = plan.addKeyframe(at: 2)!
|
|
|
|
plan.removeKeyframe(id: plan.keyframes[0].id)
|
|
XCTAssertEqual(plan.keyframes.count, 2)
|
|
|
|
plan.removeKeyframe(id: second.id)
|
|
XCTAssertEqual(plan.keyframes.count, 1)
|
|
}
|
|
|
|
func testInitFromKeyframesPullsEarliestToZero() {
|
|
let plan = CropPlan(keyframes: [
|
|
.init(time: 4, offset: 1),
|
|
.init(time: 1.5, offset: -1)
|
|
])
|
|
|
|
XCTAssertEqual(plan.keyframes.map(\.time), [0, 4])
|
|
XCTAssertEqual(plan.offset(at: 0), -1)
|
|
}
|
|
|
|
func testToleranceAbsorbsPlayerRoundingNoise() {
|
|
var plan = CropPlan()
|
|
plan.addKeyframe(at: 1.0)
|
|
plan.setOffset(1, at: 1.0)
|
|
|
|
// Frame-PTS minimal vor der Marke, wie es aus CMTime-Rundung kommt.
|
|
XCTAssertEqual(plan.offset(at: 0.9999), 1)
|
|
}
|
|
}
|