1 /*
2  * Copyright (C) 2023 The Android Open Source Project
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 package com.android.dream.lowlight.util
17 
18 import android.testing.AndroidTestingRunner
19 import androidx.test.filters.SmallTest
20 import com.android.app.animation.Interpolators
21 import com.google.common.truth.Truth
22 import org.junit.Test
23 import org.junit.runner.RunWith
24 
25 @SmallTest
26 @RunWith(AndroidTestingRunner::class)
27 class TruncatedInterpolatorTest {
28     @Test
truncatedInterpolator_matchesRegularInterpolatornull29     fun truncatedInterpolator_matchesRegularInterpolator() {
30         val originalInterpolator = Interpolators.EMPHASIZED
31         val truncatedInterpolator =
32             TruncatedInterpolator(originalInterpolator, ORIGINAL_DURATION_MS, NEW_DURATION_MS)
33 
34         // Both interpolators should start at the same value.
35         var animationPercent = 0f
36         Truth.assertThat(truncatedInterpolator.getInterpolation(animationPercent))
37             .isEqualTo(originalInterpolator.getInterpolation(animationPercent))
38 
39         animationPercent = 1f
40         Truth.assertThat(truncatedInterpolator.getInterpolation(animationPercent))
41             .isEqualTo(originalInterpolator.getInterpolation(animationPercent * DURATION_RATIO))
42 
43         animationPercent = 0.25f
44         Truth.assertThat(truncatedInterpolator.getInterpolation(animationPercent))
45             .isEqualTo(originalInterpolator.getInterpolation(animationPercent * DURATION_RATIO))
46     }
47 
48     companion object {
49         private const val ORIGINAL_DURATION_MS: Float = 1000f
50         private const val NEW_DURATION_MS: Float = 200f
51         private const val DURATION_RATIO: Float = NEW_DURATION_MS / ORIGINAL_DURATION_MS
52     }
53 }
54