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.systemui.battery
18 
19 import androidx.test.filters.SmallTest
20 import com.android.systemui.SysuiTestCase
21 import com.android.systemui.battery.BatterySpecs.BATTERY_HEIGHT
22 import com.android.systemui.battery.BatterySpecs.BATTERY_HEIGHT_WITH_SHIELD
23 import com.android.systemui.battery.BatterySpecs.BATTERY_WIDTH
24 import com.android.systemui.battery.BatterySpecs.BATTERY_WIDTH_WITH_SHIELD
25 import com.google.common.truth.Truth.assertThat
26 import org.junit.Test
27 
28 @SmallTest
29 class BatterySpecsTest : SysuiTestCase() {
30     @Test
31     fun getFullBatteryHeight_shieldFalse_returnsMainHeight() {
32         val fullHeight = BatterySpecs.getFullBatteryHeight(56f, displayShield = false)
33 
34         assertThat(fullHeight).isEqualTo(56f)
35     }
36 
37     @Test
38     fun getFullBatteryHeight_shieldTrue_returnsMainHeightPlusShield() {
39         val mainHeight = BATTERY_HEIGHT * 5
40         val fullHeight = BatterySpecs.getFullBatteryHeight(mainHeight, displayShield = true)
41 
42         // Since the main battery was scaled 5x, the output height should also be scaled 5x
43         val expectedFullHeight = BATTERY_HEIGHT_WITH_SHIELD * 5
44 
45         assertThat(fullHeight).isWithin(.0001f).of(expectedFullHeight)
46     }
47 
48     @Test
49     fun getFullBatteryWidth_shieldFalse_returnsMainWidth() {
50         val fullWidth = BatterySpecs.getFullBatteryWidth(33f, displayShield = false)
51 
52         assertThat(fullWidth).isEqualTo(33f)
53     }
54 
55     @Test
56     fun getFullBatteryWidth_shieldTrue_returnsMainWidthPlusShield() {
57         val mainWidth = BATTERY_WIDTH * 3.3f
58 
59         val fullWidth = BatterySpecs.getFullBatteryWidth(mainWidth, displayShield = true)
60 
61         // Since the main battery was scaled 3.3x, the output width should also be scaled 5x
62         val expectedFullWidth = BATTERY_WIDTH_WITH_SHIELD * 3.3f
63         assertThat(fullWidth).isWithin(.0001f).of(expectedFullWidth)
64     }
65 
66     @Test
67     fun getMainBatteryHeight_shieldFalse_returnsFullHeight() {
68         val mainHeight = BatterySpecs.getMainBatteryHeight(89f, displayShield = false)
69 
70         assertThat(mainHeight).isEqualTo(89f)
71     }
72 
73     @Test
74     fun getMainBatteryHeight_shieldTrue_returnsNotFullHeight() {
75         val fullHeight = BATTERY_HEIGHT_WITH_SHIELD * 7.7f
76 
77         val mainHeight = BatterySpecs.getMainBatteryHeight(fullHeight, displayShield = true)
78 
79         // Since the full height was scaled 7.7x, the main height should also be scaled 7.7x.
80         val expectedHeight = BATTERY_HEIGHT * 7.7f
81         assertThat(mainHeight).isWithin(.0001f).of(expectedHeight)
82     }
83 
84     @Test
85     fun getMainBatteryWidth_shieldFalse_returnsFullWidth() {
86         val mainWidth = BatterySpecs.getMainBatteryWidth(2345f, displayShield = false)
87 
88         assertThat(mainWidth).isEqualTo(2345f)
89     }
90 
91     @Test
92     fun getMainBatteryWidth_shieldTrue_returnsNotFullWidth() {
93         val fullWidth = BATTERY_WIDTH_WITH_SHIELD * 0.6f
94 
95         val mainWidth = BatterySpecs.getMainBatteryWidth(fullWidth, displayShield = true)
96 
97         // Since the full width was scaled 0.6x, the main height should also be scaled 0.6x.
98         val expectedWidth = BATTERY_WIDTH * 0.6f
99         assertThat(mainWidth).isWithin(.0001f).of(expectedWidth)
100     }
101 }
102