<commit_before>package reactivecircus.flowbinding.material

import android.view.MotionEvent
import androidx.test.filters.LargeTest
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.google.android.material.slider.Slider
import org.amshove.kluent.shouldEqual
import org.junit.Test
import reactivecircus.flowbinding.material.fixtures.MaterialFragment2
import reactivecircus.flowbinding.material.test.R
import reactivecircus.flowbinding.testing.FlowRecorder
import reactivecircus.flowbinding.testing.launchTest
import reactivecircus.flowbinding.testing.motionEventAtPosition
import reactivecircus.flowbinding.testing.recordWith

@LargeTest
class SliderChangeEventFlowTest {

    @Test
    fun sliderChangeEvents() {
        launchTest<MaterialFragment2> {
            val recorder = FlowRecorder<SliderChangeEvent>(testScope)
            val slider = getViewById<Slider>(R.id.slider)
            slider.changeEvents().recordWith(recorder)

            recorder.assertNoMoreValues()

            getInstrumentation().sendPointerSync(motionEventAtPosition(slider, MotionEvent.ACTION_DOWN, 20, 50))
            getInstrumentation().sendPointerSync(motionEventAtPosition(slider, MotionEvent.ACTION_MOVE, 100, 50))
            recorder.takeValue().also { sliderChangeEvent ->
                sliderChangeEvent.slider shouldEqual slider
                sliderChangeEvent.value shouldEqual 1f
                sliderChangeEvent.fromUser shouldEqual true
            }
            recorder.assertNoMoreValues()

            getInstrumentation().sendPointerSync(motionEventAtPosition(slider, MotionEvent.ACTION_MOVE, 0, 50))
            recorder.takeValue().also { sliderChangeEvent ->
                sliderChangeEvent.slider shouldEqual slider
                sliderChangeEvent.value shouldEqual 0f
                sliderChangeEvent.fromUser shouldEqual true
            }
            recorder.assertNoMoreValues()

            cancelTestScope()

            getInstrumentation().sendPointerSync(motionEventAtPosition(slider, MotionEvent.ACTION_MOVE, 50, 50))
            recorder.assertNoMoreValues()
        }
    }

    @Test
    fun sliderChangeEvents_programmatic() {
        launchTest<MaterialFragment2> {
            val recorder = FlowRecorder<SliderChangeEvent>(testScope)
            val slider = getViewById<Slider>(R.id.slider)
            slider.changeEvents().recordWith(recorder)

            recorder.assertNoMoreValues()

            UiThreadStatement.runOnUiThread {
                slider.value = 0.5f
            }
            recorder.takeValue().also { sliderChangeEvent ->
                sliderChangeEvent.slider shouldEqual slider
                sliderChangeEvent.value shouldEqual 0.5f
                sliderChangeEvent.fromUser shouldEqual false
            }
            recorder.assertNoMoreValues()

            UiThreadStatement.runOnUiThread {
                slider.value = 0.75f
            }
            recorder.takeValue().also { sliderChangeEvent ->
                sliderChangeEvent.slider shouldEqual slider
                sliderChangeEvent.value shouldEqual 0.75f
                sliderChangeEvent.fromUser shouldEqual false
            }
            recorder.assertNoMoreValues()

            cancelTestScope()

            UiThreadStatement.runOnUiThread {
                slider.value = 1f
            }
            recorder.assertNoMoreValues()
        }
    }

    @Test
    fun sliderChangeEvents_emitImmediately() {
        launchTest<MaterialFragment2> {
            val recorder = FlowRecorder<SliderChangeEvent>(testScope)
            val slider = getViewById<Slider>(R.id.slider)
            slider.changeEvents(emitImmediately = true).recordWith(recorder)

            recorder.takeValue().also { sliderChangeEvent ->
                sliderChangeEvent.slider shouldEqual slider
                sliderChangeEvent.value shouldEqual 0f
                sliderChangeEvent.fromUser shouldEqual false
            }
            recorder.assertNoMoreValues()

            UiThreadStatement.runOnUiThread {
                slider.value = 0.5f
            }
            recorder.takeValue().also { sliderChangeEvent ->
                sliderChangeEvent.slider shouldEqual slider
                sliderChangeEvent.value shouldEqual 0.5f
                sliderChangeEvent.fromUser shouldEqual false
            }
            recorder.assertNoMoreValues()

            cancelTestScope()

            UiThreadStatement.runOnUiThread {
                slider.value = 1f
            }
            recorder.assertNoMoreValues()
        }
    }
}
<commit_msg>Minor test clean up.<commit_after>package reactivecircus.flowbinding.material

import android.view.MotionEvent
import androidx.test.filters.LargeTest
import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.google.android.material.slider.Slider
import org.amshove.kluent.shouldEqual
import org.junit.Test
import reactivecircus.flowbinding.material.fixtures.MaterialFragment2
import reactivecircus.flowbinding.material.test.R
import reactivecircus.flowbinding.testing.FlowRecorder
import reactivecircus.flowbinding.testing.launchTest
import reactivecircus.flowbinding.testing.motionEventAtPosition
import reactivecircus.flowbinding.testing.recordWith

@LargeTest
class SliderChangeEventFlowTest {

    @Test
    fun sliderChangeEvents() {
        launchTest<MaterialFragment2> {
            val recorder = FlowRecorder<SliderChangeEvent>(testScope)
            val slider = getViewById<Slider>(R.id.slider)
            slider.changeEvents().recordWith(recorder)

            recorder.assertNoMoreValues()

            getInstrumentation().sendPointerSync(motionEventAtPosition(slider, MotionEvent.ACTION_DOWN, 20, 50))
            getInstrumentation().sendPointerSync(motionEventAtPosition(slider, MotionEvent.ACTION_MOVE, 100, 50))
            val sliderChangeEvent1 = recorder.takeValue()
            sliderChangeEvent1.slider shouldEqual slider
            sliderChangeEvent1.value shouldEqual 1f
            sliderChangeEvent1.fromUser shouldEqual true
            recorder.assertNoMoreValues()

            getInstrumentation().sendPointerSync(motionEventAtPosition(slider, MotionEvent.ACTION_MOVE, 0, 50))
            val sliderChangeEvent2 = recorder.takeValue()
            sliderChangeEvent2.slider shouldEqual slider
            sliderChangeEvent2.value shouldEqual 0f
            sliderChangeEvent2.fromUser shouldEqual true
            recorder.assertNoMoreValues()

            cancelTestScope()

            getInstrumentation().sendPointerSync(motionEventAtPosition(slider, MotionEvent.ACTION_MOVE, 50, 50))
            recorder.assertNoMoreValues()
        }
    }

    @Test
    fun sliderChangeEvents_programmatic() {
        launchTest<MaterialFragment2> {
            val recorder = FlowRecorder<SliderChangeEvent>(testScope)
            val slider = getViewById<Slider>(R.id.slider)
            slider.changeEvents().recordWith(recorder)

            recorder.assertNoMoreValues()

            runOnUiThread {
                slider.value = 0.5f
            }
            val sliderChangeEvent1 = recorder.takeValue()
            sliderChangeEvent1.slider shouldEqual slider
            sliderChangeEvent1.value shouldEqual 0.5f
            sliderChangeEvent1.fromUser shouldEqual false
            recorder.assertNoMoreValues()

            runOnUiThread {
                slider.value = 0.75f
            }
            val sliderChangeEvent2 = recorder.takeValue()
            sliderChangeEvent2.slider shouldEqual slider
            sliderChangeEvent2.value shouldEqual 0.75f
            sliderChangeEvent2.fromUser shouldEqual false
            recorder.assertNoMoreValues()

            cancelTestScope()

            runOnUiThread {
                slider.value = 1f
            }
            recorder.assertNoMoreValues()
        }
    }

    @Test
    fun sliderChangeEvents_emitImmediately() {
        launchTest<MaterialFragment2> {
            val recorder = FlowRecorder<SliderChangeEvent>(testScope)
            val slider = getViewById<Slider>(R.id.slider)
            slider.changeEvents(emitImmediately = true).recordWith(recorder)

            val sliderChangeEvent1 = recorder.takeValue()
            sliderChangeEvent1.slider shouldEqual slider
            sliderChangeEvent1.value shouldEqual 0f
            sliderChangeEvent1.fromUser shouldEqual false
            recorder.assertNoMoreValues()

            runOnUiThread {
                slider.value = 0.5f
            }
            val sliderChangeEvent2 = recorder.takeValue()
            sliderChangeEvent2.slider shouldEqual slider
            sliderChangeEvent2.value shouldEqual 0.5f
            sliderChangeEvent2.fromUser shouldEqual false
            recorder.assertNoMoreValues()

            cancelTestScope()

            runOnUiThread {
                slider.value = 1f
            }
            recorder.assertNoMoreValues()
        }
    }
}

{'fraction_non_alphanumeric': 0.06602641056422569, 'fraction_numerical': 0.011349994543271855, 'mean_word_length': 2.4206793579693917, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5401706', 'n_tokens_mistral': 2457, 'n_tokens_neox': 2211, 'n_words': 361}