<commit_before>/*
 * Copyright 2018 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 androidx.viewpager2.widget

import android.widget.TextView
import androidx.test.filters.LargeTest
import androidx.testutils.PollingCheck
import androidx.viewpager2.adapter.StatefulAdapter
import androidx.viewpager2.widget.MutableCollectionsTest.Action
import androidx.viewpager2.widget.MutableCollectionsTest.Action.AddItem
import androidx.viewpager2.widget.MutableCollectionsTest.Action.ChangeItem
import androidx.viewpager2.widget.MutableCollectionsTest.Action.RemoveItem
import androidx.viewpager2.widget.MutableCollectionsTest.TestConfig
import androidx.viewpager2.widget.ViewPager2.ORIENTATION_HORIZONTAL
import androidx.viewpager2.widget.ViewPager2.ORIENTATION_VERTICAL
import androidx.viewpager2.widget.swipe.PageView
import androidx.viewpager2.widget.swipe.SelfChecking
import org.hamcrest.Matchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.util.Random
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger

private const val RANDOM_TESTS_PER_CONFIG = 0 // increase to have random tests generated

@RunWith(Parameterized::class)
@LargeTest
class MutableCollectionsTest(private val testConfig: TestConfig) : BaseTest() {

    @Test
    fun test() {
        testConfig.apply {
            setUpTest(orientation).apply {
                setAdapterSync(adapterProvider.provider(items))

                verifyViewPagerContent(items) // quick check

                actions.forEach { action ->
                    if (items.isNotEmpty()) {
                        // useful when designing test cases, e.g. delete item before current
                        setCurrentItemSync(viewPager.middleItem)
                    }

                    action.perform(items)
                    if (action is ChangeItem && viewPager.adapter is StatefulAdapter) {
                        handleStatefulAdapterItemChange(action.position, items, this)
                    }

                    notifyDataSetChangedSync()<commit_msg>Mark MutableCollectionsTest as flaky<commit_after>/*
 * Copyright 2018 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 androidx.viewpager2.widget

import android.widget.TextView
import androidx.test.filters.FlakyTest
import androidx.test.filters.LargeTest
import androidx.testutils.PollingCheck
import androidx.viewpager2.adapter.StatefulAdapter
import androidx.viewpager2.widget.MutableCollectionsTest.Action
import androidx.viewpager2.widget.MutableCollectionsTest.Action.AddItem
import androidx.viewpager2.widget.MutableCollectionsTest.Action.ChangeItem
import androidx.viewpager2.widget.MutableCollectionsTest.Action.RemoveItem
import androidx.viewpager2.widget.MutableCollectionsTest.TestConfig
import androidx.viewpager2.widget.ViewPager2.ORIENTATION_HORIZONTAL
import androidx.viewpager2.widget.ViewPager2.ORIENTATION_VERTICAL
import androidx.viewpager2.widget.swipe.PageView
import androidx.viewpager2.widget.swipe.SelfChecking
import org.hamcrest.Matchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.util.Random
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger

private const val RANDOM_TESTS_PER_CONFIG = 0 // increase to have random tests generated

@RunWith(Parameterized::class)
@LargeTest
class MutableCollectionsTest(private val testConfig: TestConfig) : BaseTest() {

    @FlakyTest(bugId = 210157798)
    @Test
    fun test() {
        testConfig.apply {
            setUpTest(orientation).apply {
                setAdapterSync(adapterProvider.provider(items))

                verifyViewPagerContent(items) // quick check

                actions.forEach { action ->
                    if (items.isNotEmpty()) {
                        // useful when designing test cases, e.g. delete item before current
                        setCurrentItemSync(viewPager.middleItem)
                    }

                    action.perform(items)
                    if (action is ChangeItem && viewPager.adapter is StatefulAdapter) {
                        handleStatefulAdapterItemChange(action.position, items, this)
                    }

                    notifyDataSetChangedSync()
{'fraction_non_alphanumeric': 0.06982142857142858, 'fraction_numerical': 0.009464285714285715, 'mean_word_length': 3.4523052464228936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6821486', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1442, 'n_words': 380}