diff options
| author | 2020-11-05 09:45:24 -0500 | |
|---|---|---|
| committer | 2020-11-05 15:54:39 +0000 | |
| commit | fe29d512b17f8062527017d2cba4489b08fd1b31 (patch) | |
| tree | a2c3ff785cd3f897b62c66a4f9b5ab9dd7026fbe | |
| parent | 2efeb4274fba6a4780df928e7d27b3dd9804446d (diff) | |
Controls - Large ranges improperly calculated
There was an error in calculating ranges where the min, max difference
was greater than 1000. Set the default value properly to
Float.MAX_VALUE.
Bug: 171422049
Test: atest ToggleRangeTemplateTest
Change-Id: I157643264e6139642dcb0db0d7c474ea55722347
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt | 2 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/controls/ui/ToggleRangeTemplateTest.kt | 54 |
2 files changed, 55 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt index aa11df41a7b7..a3a937acec76 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt @@ -301,7 +301,7 @@ class ToggleRangeBehavior : Behavior { } fun findNearestStep(value: Float): Float { - var minDiff = 1000f + var minDiff = Float.MAX_VALUE var f = rangeTemplate.getMinValue() while (f <= rangeTemplate.getMaxValue()) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ToggleRangeTemplateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ToggleRangeTemplateTest.kt new file mode 100644 index 000000000000..31e09549a2b5 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ToggleRangeTemplateTest.kt @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.controls.ui + +import android.service.controls.templates.RangeTemplate +import android.testing.AndroidTestingRunner +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +@SmallTest +@RunWith(AndroidTestingRunner::class) +class ToggleRangeTemplateTest : SysuiTestCase() { + + @Test + fun testLargeRangeNearestStep() { + val trt = ToggleRangeBehavior() + trt.rangeTemplate = RangeTemplate("range", -100000f, 100000f, 0f, 5f, null) + + assertEquals(255f, trt.findNearestStep(253f), 0.1f) + } + + @Test + fun testLargeRangeNearestStepWithNegativeValues() { + val trt = ToggleRangeBehavior() + trt.rangeTemplate = RangeTemplate("range", -100000f, 100000f, 0f, 5f, null) + + assertEquals(-7855f, trt.findNearestStep(-7853.2f), 0.1f) + } + + @Test + fun testFractionalRangeNearestStep() { + val trt = ToggleRangeBehavior() + trt.rangeTemplate = RangeTemplate("range", 10f, 11f, 10f, .01f, null) + + assertEquals(10.54f, trt.findNearestStep(10.543f), 0.01f) + } +} |