Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b2db80b8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Controls - Large ranges improperly calculated" into rvc-qpr-dev am: 312e70e1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12994959

Change-Id: Ie41afb53bc14ae002a0f043ed18fb4725a25a901
parents 28e22347 312e70e1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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()) {
+54 −0
Original line number Diff line number Diff line
/*
 * 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)
    }
}