1 /*
2  * Copyright (C) 2022 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 
17 package com.android.keyguard
18 
19 import android.test.suitebuilder.annotation.SmallTest
20 import android.testing.AndroidTestingRunner
21 import com.android.systemui.SysuiTestCase
22 import com.google.common.truth.Truth.assertThat
23 import org.junit.Assert.assertEquals
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 
27 @RunWith(AndroidTestingRunner::class)
28 @SmallTest
29 class BouncerPanelExpansionCalculatorTest : SysuiTestCase() {
30     @Test
31     fun testGetHostViewScaledExpansion() {
32         assertThat(BouncerPanelExpansionCalculator.showBouncerProgress(1f))
33                 .isEqualTo(1f)
34         assertThat(BouncerPanelExpansionCalculator.showBouncerProgress(0.9f))
35                 .isEqualTo(1f)
36         assertThat(BouncerPanelExpansionCalculator.showBouncerProgress(0.59f))
37                 .isEqualTo(0f)
38         assertThat(BouncerPanelExpansionCalculator.showBouncerProgress(0f))
39                 .isEqualTo(0f)
40         assertEquals(BouncerPanelExpansionCalculator
41                 .showBouncerProgress(0.8f), 2f / 3f, 0.01f)
42     }
43 
44     @Test
45     fun testGetBackScrimScaledExpansion() {
46         assertThat(BouncerPanelExpansionCalculator.aboutToShowBouncerProgress(1f))
47                 .isEqualTo(1f)
48         assertEquals(BouncerPanelExpansionCalculator
49                 .aboutToShowBouncerProgress(0.95f), 1f / 2f, 0.01f)
50         assertThat(BouncerPanelExpansionCalculator.aboutToShowBouncerProgress(0.9f))
51                 .isEqualTo(0f)
52         assertThat(BouncerPanelExpansionCalculator.aboutToShowBouncerProgress(0.5f))
53                 .isEqualTo(0f)
54         assertThat(BouncerPanelExpansionCalculator.aboutToShowBouncerProgress(0f))
55                 .isEqualTo(0f)
56     }
57 
58     @Test
59     fun testGetKeyguardClockScaledExpansion() {
60         assertThat(BouncerPanelExpansionCalculator.getKeyguardClockScaledExpansion(1f))
61                 .isEqualTo(1f)
62         assertEquals(BouncerPanelExpansionCalculator
63                 .getKeyguardClockScaledExpansion(0.8f), 1f / 3f, 0.01f)
64         assertThat(BouncerPanelExpansionCalculator.getKeyguardClockScaledExpansion(0.7f))
65                 .isEqualTo(0f)
66         assertThat(BouncerPanelExpansionCalculator.aboutToShowBouncerProgress(0.5f))
67                 .isEqualTo(0f)
68         assertThat(BouncerPanelExpansionCalculator.aboutToShowBouncerProgress(0f))
69                 .isEqualTo(0f)
70     }
71 }
72