Skip to content

Commit a9f0d20

Browse files
authored
dataconnect: testing: use Arb.next(RandomSource, edgeCaseProbability) instead of PropertyContext.sampleFromArb() (#7621)
1 parent f6880d9 commit a9f0d20

File tree

2 files changed

+7
-15
lines changed
  • firebase-dataconnect/testutil/src

2 files changed

+7
-15
lines changed

firebase-dataconnect/testutil/src/main/kotlin/com/google/firebase/dataconnect/testutil/property/arbitrary/misc.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ package com.google.firebase.dataconnect.testutil.property.arbitrary
1818

1919
import com.google.firebase.dataconnect.testutil.withNullAppended
2020
import io.kotest.property.Arb
21-
import io.kotest.property.EdgeConfig
2221
import io.kotest.property.Exhaustive
23-
import io.kotest.property.PropertyContext
24-
import io.kotest.property.Sample
2522
import io.kotest.property.arbitrary.arbitrary
2623
import io.kotest.property.arbitrary.filterNot
2724
import io.kotest.property.arbitrary.flatMap
@@ -89,11 +86,6 @@ private fun pow10(n: Int): Int {
8986
return result
9087
}
9188

92-
fun <T> PropertyContext.sampleFromArb(arb: Arb<T>, edgeCaseProbability: Double): Sample<T> {
93-
val edgeConfig = EdgeConfig(edgecasesGenerationProbability = edgeCaseProbability)
94-
return arb.generate(randomSource(), edgeConfig).first()
95-
}
96-
9789
/**
9890
* Creates and returns a new [Exhaustive] whose values are all of the values of [T] and also `null`.
9991
*/

firebase-dataconnect/testutil/src/test/kotlin/com/google/firebase/dataconnect/testutil/ListContainingNullUnitTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.firebase.dataconnect.testutil
1818

1919
import com.google.firebase.dataconnect.testutil.property.arbitrary.listContainingNull
20-
import com.google.firebase.dataconnect.testutil.property.arbitrary.sampleFromArb
20+
import com.google.firebase.dataconnect.testutil.property.arbitrary.next
2121
import io.kotest.assertions.asClue
2222
import io.kotest.assertions.assertSoftly
2323
import io.kotest.assertions.withClue
@@ -40,8 +40,8 @@ class ListContainingNullUnitTest {
4040
fun `listContainingNull generates values with lengths in the given range`() = runTest {
4141
checkAll(NUM_ITERATIONS, listLengthsArb) { lengthRange ->
4242
val arb = Arb.listContainingNull(valuesGen, lengthRange)
43-
val sample = sampleFromArb(arb, edgeCaseProbability = 0.5)
44-
sample.value.asClue {
43+
val value = arb.next(randomSource(), edgeCaseProbability = 0.5f)
44+
value.asClue {
4545
assertSoftly {
4646
it.size shouldBeGreaterThanOrEqual lengthRange.first
4747
it.size shouldBeLessThanOrEqual lengthRange.last
@@ -54,8 +54,8 @@ class ListContainingNullUnitTest {
5454
fun `listContainingNull generates values from the given arb`() = runTest {
5555
checkAll(NUM_ITERATIONS, listLengthsArb) { lengthRange ->
5656
val arb = Arb.listContainingNull(valuesGen, lengthRange)
57-
val sample = sampleFromArb(arb, edgeCaseProbability = 0.5)
58-
sample.value.asClue {
57+
val value = arb.next(randomSource(), edgeCaseProbability = 0.5f)
58+
value.asClue {
5959
assertSoftly {
6060
it.forEachIndexed { index, value ->
6161
if (value !== null) {
@@ -71,8 +71,8 @@ class ListContainingNullUnitTest {
7171
fun `listContainingNull generates lists that always contain null`() = runTest {
7272
checkAll(NUM_ITERATIONS, listLengthsArb) { lengthRange ->
7373
val arb = Arb.listContainingNull(valuesGen, lengthRange)
74-
val sample = sampleFromArb(arb, edgeCaseProbability = 0.5)
75-
sample.value.asClue { it shouldContain null }
74+
val value = arb.next(randomSource(), edgeCaseProbability = 0.5f)
75+
value.asClue { it shouldContain null }
7676
}
7777
}
7878

0 commit comments

Comments
 (0)