|
| 1 | +/* |
| 2 | + Copyright 2017-present The Material Motion Authors. All Rights Reserved. |
| 3 | + |
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | + |
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + |
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import XCTest |
| 18 | +import MotionInterchange |
| 19 | + |
| 20 | +class MDMLegacyAPITests: XCTestCase { |
| 21 | + |
| 22 | + func testTimingValuesMatchTraitValues() { |
| 23 | + let timing = MotionTiming(delay: 0.1, |
| 24 | + duration: 0.2, |
| 25 | + curve: MotionCurveMakeBezier(p1x: 0.3, p1y: 0.4, p2x: 0.5, p2y: 0.6), |
| 26 | + repetition: .init(type: .duration, amount: 0.7, autoreverses: true)) |
| 27 | + |
| 28 | + let traits = MDMAnimationTraits(motionTiming: timing) |
| 29 | + |
| 30 | + XCTAssertEqualWithAccuracy(traits.duration, timing.duration, accuracy: 0.001) |
| 31 | + XCTAssertEqualWithAccuracy(traits.delay, timing.delay, accuracy: 0.001) |
| 32 | + XCTAssertTrue(traits.timingCurve is CAMediaTimingFunction) |
| 33 | + if let timingCurve = traits.timingCurve as? CAMediaTimingFunction { |
| 34 | + XCTAssertEqualWithAccuracy(timingCurve.mdm_point1.x, timing.curve.data.0, accuracy: 0.001) |
| 35 | + XCTAssertEqualWithAccuracy(timingCurve.mdm_point1.y, timing.curve.data.1, accuracy: 0.001) |
| 36 | + XCTAssertEqualWithAccuracy(timingCurve.mdm_point2.x, timing.curve.data.2, accuracy: 0.001) |
| 37 | + XCTAssertEqualWithAccuracy(timingCurve.mdm_point2.y, timing.curve.data.3, accuracy: 0.001) |
| 38 | + } |
| 39 | + XCTAssertTrue(traits.repetition is MDMRepetitionOverTime) |
| 40 | + if let repetition = traits.repetition as? MDMRepetitionOverTime { |
| 41 | + XCTAssertEqualWithAccuracy(repetition.duration, timing.repetition.amount, accuracy: 0.001) |
| 42 | + XCTAssertEqual(repetition.autoreverses, timing.repetition.autoreverses.boolValue) |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | +} |
| 47 | + |
0 commit comments