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

Commit fd9fc8e7 authored by Mike Schneider's avatar Mike Schneider
Browse files

Capitalize all `val`s in `companion object`s

This is in-line with the Compose style.

Flag: NONE Initial commits for new library, currently unused.
Test: atest mechanics_tests
Bug: 379248269
Change-Id: Ic01bdfb0aa576edbd1d8020b11484454d858beda
parent 71b7a4c7
Loading
Loading
Loading
Loading
+30 −30
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ class DirectionalMotionSpecTest {

    @Test
    fun wrongSentinelBreakpoints_throws() {
        val breakpoint1 = Breakpoint(b1, position = 10f, spring, Guarantee.None)
        val breakpoint2 = Breakpoint(b2, position = 20f, spring, Guarantee.None)
        val breakpoint1 = Breakpoint(B1, position = 10f, Spring, Guarantee.None)
        val breakpoint2 = Breakpoint(B2, position = 20f, Spring, Guarantee.None)

        assertFailsWith<IllegalArgumentException> {
            DirectionalMotionSpec(listOf(breakpoint1, breakpoint2), listOf(Mapping.Identity))
@@ -64,8 +64,8 @@ class DirectionalMotionSpecTest {

    @Test
    fun breakpointsOutOfOrder_throws() {
        val breakpoint1 = Breakpoint(b1, position = 10f, spring, Guarantee.None)
        val breakpoint2 = Breakpoint(b2, position = 20f, spring, Guarantee.None)
        val breakpoint1 = Breakpoint(B1, position = 10f, Spring, Guarantee.None)
        val breakpoint2 = Breakpoint(B2, position = 20f, Spring, Guarantee.None)
        assertFailsWith<IllegalArgumentException> {
            DirectionalMotionSpec(
                listOf(Breakpoint.minLimit, breakpoint2, breakpoint1, Breakpoint.maxLimit),
@@ -76,7 +76,7 @@ class DirectionalMotionSpecTest {

    @Test
    fun findBreakpointIndex_returnsMinForEmptySpec() {
        val underTest = DirectionalMotionSpec.builder(spring).complete()
        val underTest = DirectionalMotionSpec.builder(Spring).complete()

        assertThat(underTest.findBreakpointIndex(0f)).isEqualTo(0)
        assertThat(underTest.findBreakpointIndex(Float.MAX_VALUE)).isEqualTo(0)
@@ -85,7 +85,7 @@ class DirectionalMotionSpecTest {

    @Test
    fun findBreakpointIndex_throwsForNonFiniteInput() {
        val underTest = DirectionalMotionSpec.builder(spring).complete()
        val underTest = DirectionalMotionSpec.builder(Spring).complete()

        assertFailsWith<IllegalArgumentException> { underTest.findBreakpointIndex(Float.NaN) }
        assertFailsWith<IllegalArgumentException> {
@@ -99,7 +99,7 @@ class DirectionalMotionSpecTest {
    @Test
    fun findBreakpointIndex_atBreakpoint_returnsIndex() {
        val underTest =
            DirectionalMotionSpec.builder(spring).toBreakpoint(10f).completeWith(Mapping.Identity)
            DirectionalMotionSpec.builder(Spring).toBreakpoint(10f).completeWith(Mapping.Identity)

        assertThat(underTest.findBreakpointIndex(10f)).isEqualTo(1)
    }
@@ -107,7 +107,7 @@ class DirectionalMotionSpecTest {
    @Test
    fun findBreakpointIndex_afterBreakpoint_returnsPreviousIndex() {
        val underTest =
            DirectionalMotionSpec.builder(spring).toBreakpoint(10f).completeWith(Mapping.Identity)
            DirectionalMotionSpec.builder(Spring).toBreakpoint(10f).completeWith(Mapping.Identity)

        assertThat(underTest.findBreakpointIndex(10f.nextUp())).isEqualTo(1)
    }
@@ -115,7 +115,7 @@ class DirectionalMotionSpecTest {
    @Test
    fun findBreakpointIndex_beforeBreakpoint_returnsIndex() {
        val underTest =
            DirectionalMotionSpec.builder(spring).toBreakpoint(10f).completeWith(Mapping.Identity)
            DirectionalMotionSpec.builder(Spring).toBreakpoint(10f).completeWith(Mapping.Identity)

        assertThat(underTest.findBreakpointIndex(10f.nextDown())).isEqualTo(0)
    }
@@ -123,55 +123,55 @@ class DirectionalMotionSpecTest {
    @Test
    fun findBreakpointIndexByKey_returnsIndex() {
        val underTest =
            DirectionalMotionSpec.builder(spring)
                .toBreakpoint(10f, key = b1)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(10f, key = B1)
                .completeWith(Mapping.Identity)

        assertThat(underTest.findBreakpointIndex(b1)).isEqualTo(1)
        assertThat(underTest.findBreakpointIndex(B1)).isEqualTo(1)
    }

    @Test
    fun findBreakpointIndexByKey_unknown_returnsMinusOne() {
        val underTest =
            DirectionalMotionSpec.builder(spring)
                .toBreakpoint(10f, key = b1)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(10f, key = B1)
                .completeWith(Mapping.Identity)

        assertThat(underTest.findBreakpointIndex(b2)).isEqualTo(-1)
        assertThat(underTest.findBreakpointIndex(B2)).isEqualTo(-1)
    }

    @Test
    fun findSegmentIndex_returnsIndexForSegment_ignoringDirection() {
        val underTest =
            DirectionalMotionSpec.builder(spring)
                .toBreakpoint(10f, key = b1)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(10f, key = B1)
                .continueWith(Mapping.One)
                .toBreakpoint(20f, key = b2)
                .toBreakpoint(20f, key = B2)
                .completeWith(Mapping.Identity)

        assertThat(underTest.findSegmentIndex(SegmentKey(b1, b2, InputDirection.Max))).isEqualTo(1)
        assertThat(underTest.findSegmentIndex(SegmentKey(b1, b2, InputDirection.Min))).isEqualTo(1)
        assertThat(underTest.findSegmentIndex(SegmentKey(B1, B2, InputDirection.Max))).isEqualTo(1)
        assertThat(underTest.findSegmentIndex(SegmentKey(B1, B2, InputDirection.Min))).isEqualTo(1)
    }

    @Test
    fun findSegmentIndex_forInvalidKeys_returnsMinusOne() {
        val underTest =
            DirectionalMotionSpec.builder(spring)
                .toBreakpoint(10f, key = b1)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(10f, key = B1)
                .continueWith(Mapping.One)
                .toBreakpoint(20f, key = b2)
                .toBreakpoint(20f, key = B2)
                .continueWith(Mapping.One)
                .toBreakpoint(30f, key = b3)
                .toBreakpoint(30f, key = B3)
                .completeWith(Mapping.Identity)

        assertThat(underTest.findSegmentIndex(SegmentKey(b2, b1, InputDirection.Max))).isEqualTo(-1)
        assertThat(underTest.findSegmentIndex(SegmentKey(b1, b3, InputDirection.Max))).isEqualTo(-1)
        assertThat(underTest.findSegmentIndex(SegmentKey(B2, B1, InputDirection.Max))).isEqualTo(-1)
        assertThat(underTest.findSegmentIndex(SegmentKey(B1, B3, InputDirection.Max))).isEqualTo(-1)
    }

    companion object {
        val b1 = BreakpointKey("one")
        val b2 = BreakpointKey("two")
        val b3 = BreakpointKey("three")
        val spring = SpringParameters(stiffness = 100f, dampingRatio = 1f)
        val B1 = BreakpointKey("one")
        val B2 = BreakpointKey("two")
        val B3 = BreakpointKey("three")
        val Spring = SpringParameters(stiffness = 100f, dampingRatio = 1f)
    }
}
+33 −34
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class FluentSpecBuilderTest {

    @Test
    fun directionalSpec_buildEmptySpec() {
        val result = DirectionalMotionSpec.builder(spring).complete()
        val result = DirectionalMotionSpec.builder(Spring).complete()

        assertThat(result).breakpoints().isEmpty()
        assertThat(result).mappings().containsExactly(Mapping.Identity)
@@ -35,7 +35,7 @@ class FluentSpecBuilderTest {

    @Test
    fun directionalSpec_buildEmptySpec_inReverse() {
        val result = DirectionalMotionSpec.reverseBuilder(spring).complete()
        val result = DirectionalMotionSpec.reverseBuilder(Spring).complete()

        assertThat(result).breakpoints().isEmpty()
        assertThat(result).mappings().containsExactly(Mapping.Identity)
@@ -44,15 +44,15 @@ class FluentSpecBuilderTest {
    @Test
    fun motionSpec_sameSpecInBothDirections() {
        val result =
            MotionSpec.builder(spring, Mapping.Zero)
                .toBreakpoint(0f, b1)
            MotionSpec.builder(Spring, Mapping.Zero)
                .toBreakpoint(0f, B1)
                .continueWith(Mapping.One)
                .toBreakpoint(10f, b2)
                .toBreakpoint(10f, B2)
                .completeWith(Mapping.Two)

        assertThat(result.maxDirection).isSameInstanceAs(result.minDirection)

        assertThat(result.minDirection).breakpoints().keys().containsExactly(b1, b2).inOrder()
        assertThat(result.minDirection).breakpoints().keys().containsExactly(B1, B2).inOrder()
        assertThat(result.minDirection)
            .mappings()
            .containsExactly(Mapping.Zero, Mapping.One, Mapping.Two)
@@ -62,15 +62,15 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_addBreakpointsAndMappings() {
        val result =
            DirectionalMotionSpec.builder(spring, Mapping.Zero)
                .toBreakpoint(0f, b1)
            DirectionalMotionSpec.builder(Spring, Mapping.Zero)
                .toBreakpoint(0f, B1)
                .continueWith(Mapping.One)
                .toBreakpoint(10f, b2)
                .toBreakpoint(10f, B2)
                .completeWith(Mapping.Two)

        assertThat(result).breakpoints().keys().containsExactly(b1, b2).inOrder()
        assertThat(result).breakpoints().withKey(b1).isAt(0f)
        assertThat(result).breakpoints().withKey(b2).isAt(10f)
        assertThat(result).breakpoints().keys().containsExactly(B1, B2).inOrder()
        assertThat(result).breakpoints().withKey(B1).isAt(0f)
        assertThat(result).breakpoints().withKey(B2).isAt(10f)
        assertThat(result)
            .mappings()
            .containsExactly(Mapping.Zero, Mapping.One, Mapping.Two)
@@ -80,15 +80,15 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_addBreakpointsAndMappings_inReverse() {
        val result =
            DirectionalMotionSpec.reverseBuilder(spring, Mapping.Two)
                .toBreakpoint(10f, b2)
            DirectionalMotionSpec.reverseBuilder(Spring, Mapping.Two)
                .toBreakpoint(10f, B2)
                .continueWith(Mapping.One)
                .toBreakpoint(0f, b1)
                .toBreakpoint(0f, B1)
                .completeWith(Mapping.Zero)

        assertThat(result).breakpoints().keys().containsExactly(b1, b2).inOrder()
        assertThat(result).breakpoints().withKey(b1).isAt(0f)
        assertThat(result).breakpoints().withKey(b2).isAt(10f)
        assertThat(result).breakpoints().keys().containsExactly(B1, B2).inOrder()
        assertThat(result).breakpoints().withKey(B1).isAt(0f)
        assertThat(result).breakpoints().withKey(B2).isAt(10f)
        assertThat(result)
            .mappings()
            .containsExactly(Mapping.Zero, Mapping.One, Mapping.Two)
@@ -98,20 +98,20 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_setsDefaultSpring() {
        val result =
            DirectionalMotionSpec.builder(spring)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(10f)
                .jumpTo(20f)
                .continueWithConstantValue()
                .complete()

        assertThat(result).breakpoints().atPosition(10f).spring().isEqualTo(spring)
        assertThat(result).breakpoints().atPosition(10f).spring().isEqualTo(Spring)
    }

    @Test
    fun directionalSpec_mappingBuilder_canOverrideDefaultSpring() {
        val otherSpring = SpringParameters(stiffness = 10f, dampingRatio = 0.1f)
        val result =
            DirectionalMotionSpec.builder(spring)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(10f)
                .jumpTo(20f, spring = otherSpring)
                .continueWithConstantValue()
@@ -123,7 +123,7 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_defaultsToNoGuarantee() {
        val result =
            DirectionalMotionSpec.builder(spring)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(10f)
                .jumpTo(20f)
                .continueWithConstantValue()
@@ -136,7 +136,7 @@ class FluentSpecBuilderTest {
    fun directionalSpec_mappingBuilder_canSetGuarantee() {
        val guarantee = Guarantee.InputDelta(10f)
        val result =
            DirectionalMotionSpec.builder(spring)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(10f)
                .jumpTo(20f, guarantee = guarantee)
                .continueWithConstantValue()
@@ -148,7 +148,7 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_jumpTo_setsAbsoluteValue() {
        val result =
            DirectionalMotionSpec.builder(spring, Mapping.Fixed(99f))
            DirectionalMotionSpec.builder(Spring, Mapping.Fixed(99f))
                .toBreakpoint(10f)
                .jumpTo(20f)
                .continueWithConstantValue()
@@ -161,7 +161,7 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_jumpBy_setsRelativeValue() {
        val result =
            DirectionalMotionSpec.builder(spring, Mapping.Linear(factor = 0.5f))
            DirectionalMotionSpec.builder(Spring, Mapping.Linear(factor = 0.5f))
                .toBreakpoint(10f)
                .jumpBy(30f)
                .continueWithConstantValue()
@@ -174,7 +174,7 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_continueWithConstantValue_usesSourceValue() {
        val result =
            DirectionalMotionSpec.builder(spring, Mapping.Linear(factor = 0.5f))
            DirectionalMotionSpec.builder(Spring, Mapping.Linear(factor = 0.5f))
                .toBreakpoint(5f)
                .jumpBy(0f)
                .continueWithConstantValue()
@@ -186,7 +186,7 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_continueWithFractionalInput_matchesLinearMapping() {
        val result =
            DirectionalMotionSpec.builder(spring)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(5f)
                .jumpTo(1f)
                .continueWithFractionalInput(fraction = .1f)
@@ -201,7 +201,7 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_reverse_continueWithFractionalInput_matchesLinearMapping() {
        val result =
            DirectionalMotionSpec.reverseBuilder(spring)
            DirectionalMotionSpec.reverseBuilder(Spring)
                .toBreakpoint(15f)
                .jumpTo(2f)
                .continueWithFractionalInput(fraction = .1f)
@@ -216,7 +216,7 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_continueWithTargetValue_matchesLinearMapping() {
        val result =
            DirectionalMotionSpec.builder(spring)
            DirectionalMotionSpec.builder(Spring)
                .toBreakpoint(5f)
                .jumpTo(1f)
                .continueWithTargetValue(target = 20f)
@@ -232,7 +232,7 @@ class FluentSpecBuilderTest {
    @Test
    fun directionalSpec_mappingBuilder_reverse_continueWithTargetValue_matchesLinearMapping() {
        val result =
            DirectionalMotionSpec.reverseBuilder(spring)
            DirectionalMotionSpec.reverseBuilder(Spring)
                .toBreakpoint(30f)
                .jumpTo(20f)
                .continueWithTargetValue(target = 1f)
@@ -246,9 +246,8 @@ class FluentSpecBuilderTest {
    }

    companion object {
        val spring = SpringParameters(stiffness = 100f, dampingRatio = 1f)
        val b1 = BreakpointKey("One")
        val b2 = BreakpointKey("Two")
        val b3 = BreakpointKey("Three")
        val Spring = SpringParameters(stiffness = 100f, dampingRatio = 1f)
        val B1 = BreakpointKey("One")
        val B2 = BreakpointKey("Two")
    }
}
+57 −58

File changed.

Preview size limit exceeded, changes collapsed.

+15 −15
Original line number Diff line number Diff line
@@ -30,8 +30,8 @@ class SegmentTest {

    @Test
    fun segmentData_isValidForInput_betweenBreakpointsSameDirection_isTrue() {
        val breakpoint1 = Breakpoint(b1, position = 10f, spring, Guarantee.None)
        val breakpoint2 = Breakpoint(b2, position = 20f, spring, Guarantee.None)
        val breakpoint1 = Breakpoint(B1, position = 10f, Spring, Guarantee.None)
        val breakpoint2 = Breakpoint(B2, position = 20f, Spring, Guarantee.None)
        val underTest =
            SegmentData(fakeSpec, breakpoint1, breakpoint2, InputDirection.Max, Mapping.Identity)

@@ -40,8 +40,8 @@ class SegmentTest {

    @Test
    fun segmentData_isValidForInput_betweenBreakpointsOppositeDirection_isFalse() {
        val breakpoint1 = Breakpoint(b1, position = 10f, spring, Guarantee.None)
        val breakpoint2 = Breakpoint(b2, position = 20f, spring, Guarantee.None)
        val breakpoint1 = Breakpoint(B1, position = 10f, Spring, Guarantee.None)
        val breakpoint2 = Breakpoint(B2, position = 20f, Spring, Guarantee.None)
        val underTest =
            SegmentData(fakeSpec, breakpoint1, breakpoint2, InputDirection.Max, Mapping.Identity)

@@ -50,8 +50,8 @@ class SegmentTest {

    @Test
    fun segmentData_isValidForInput_inMaxDirection_sampledAtVariousPositions_matchesExpectation() {
        val breakpoint1 = Breakpoint(b1, position = 10f, spring, Guarantee.None)
        val breakpoint2 = Breakpoint(b2, position = 20f, spring, Guarantee.None)
        val breakpoint1 = Breakpoint(B1, position = 10f, Spring, Guarantee.None)
        val breakpoint2 = Breakpoint(B2, position = 20f, Spring, Guarantee.None)
        val underTest =
            SegmentData(fakeSpec, breakpoint1, breakpoint2, InputDirection.Max, Mapping.Identity)

@@ -65,8 +65,8 @@ class SegmentTest {

    @Test
    fun segmentData_isValidForInput_inMinDirection_sampledAtVariousPositions_matchesExpectation() {
        val breakpoint1 = Breakpoint(b1, position = 10f, spring, Guarantee.None)
        val breakpoint2 = Breakpoint(b2, position = 20f, spring, Guarantee.None)
        val breakpoint1 = Breakpoint(B1, position = 10f, Spring, Guarantee.None)
        val breakpoint2 = Breakpoint(B2, position = 20f, Spring, Guarantee.None)
        val underTest =
            SegmentData(fakeSpec, breakpoint1, breakpoint2, InputDirection.Min, Mapping.Identity)

@@ -80,8 +80,8 @@ class SegmentTest {

    @Test
    fun segmentData_entryBreakpoint_maxDirection_returnsMinBreakpoint() {
        val breakpoint1 = Breakpoint(b1, position = 10f, spring, Guarantee.None)
        val breakpoint2 = Breakpoint(b2, position = 20f, spring, Guarantee.None)
        val breakpoint1 = Breakpoint(B1, position = 10f, Spring, Guarantee.None)
        val breakpoint2 = Breakpoint(B2, position = 20f, Spring, Guarantee.None)
        val underTest =
            SegmentData(fakeSpec, breakpoint1, breakpoint2, InputDirection.Max, Mapping.Identity)

@@ -90,8 +90,8 @@ class SegmentTest {

    @Test
    fun segmentData_entryBreakpoint_minDirection_returnsMaxBreakpoint() {
        val breakpoint1 = Breakpoint(b1, position = 10f, spring, Guarantee.None)
        val breakpoint2 = Breakpoint(b2, position = 20f, spring, Guarantee.None)
        val breakpoint1 = Breakpoint(B1, position = 10f, Spring, Guarantee.None)
        val breakpoint2 = Breakpoint(B2, position = 20f, Spring, Guarantee.None)
        val underTest =
            SegmentData(fakeSpec, breakpoint1, breakpoint2, InputDirection.Min, Mapping.Identity)

@@ -99,8 +99,8 @@ class SegmentTest {
    }

    companion object {
        val b1 = BreakpointKey("one")
        val b2 = BreakpointKey("two")
        val spring = SpringParameters(stiffness = 100f, dampingRatio = 1f)
        val B1 = BreakpointKey("one")
        val B2 = BreakpointKey("two")
        val Spring = SpringParameters(stiffness = 100f, dampingRatio = 1f)
    }
}
+7 −7
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ class ComposeAndMechanicsSpringCompatibilityTest {
        initialVelocity: Float,
        parameters: SpringParameters,
    ) = buildList {
        Animatable(displacement, displacementThreshold).animateTo(
        Animatable(displacement, DisplacementThreshold).animateTo(
            0f,
            parameters.asSpringSpec(),
            initialVelocity,
@@ -99,9 +99,9 @@ class ComposeAndMechanicsSpringCompatibilityTest {
        parameters: SpringParameters,
    ) = buildList {
        var state = SpringState(displacement, initialVelocity)
        while (!state.isStable(parameters, displacementThreshold)) {
        while (!state.isStable(parameters, DisplacementThreshold)) {
            add(state)
            state = state.calculateUpdatedState(frameDelayNanos, parameters)
            state = state.calculateUpdatedState(FrameDelayNanos, parameters)
        }
    }

@@ -131,7 +131,7 @@ class ComposeAndMechanicsSpringCompatibilityTest {
            val mechanics = byMechanics.elementAtOrNull(i) ?: SpringState.AtRest
            val compose = byCompose.elementAtOrNull(i) ?: SpringState.AtRest
            assertThat(mechanics.displacement)
                .isWithin(displacementThreshold)
                .isWithin(DisplacementThreshold)
                .of(compose.displacement)
        }
    }
@@ -142,11 +142,11 @@ class ComposeAndMechanicsSpringCompatibilityTest {

    private fun runTestWithFrameClock(testBody: suspend () -> Unit) = runTest {
        val testScope: TestScope = this
        withContext(TestMonotonicFrameClock(testScope, frameDelayNanos)) { testBody() }
        withContext(TestMonotonicFrameClock(testScope, FrameDelayNanos)) { testBody() }
    }

    companion object {
        private val frameDelayNanos: Long = 16_000_000L
        private val displacementThreshold: Float = 0.01f
        private val FrameDelayNanos: Long = 16_000_000L
        private val DisplacementThreshold: Float = 0.01f
    }
}
Loading