Skip to content

Commit

Permalink
refactor: migrate GeneratorsTest to kotlin-test
Browse files Browse the repository at this point in the history
  • Loading branch information
milgner committed Oct 29, 2023
1 parent 6b794a9 commit e29ce66
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package arrow.core.test

import io.kotest.core.spec.style.FreeSpec
import io.kotest.inspectors.forAll
import io.kotest.inspectors.forAtLeastOne
import io.kotest.matchers.ints.shouldBeGreaterThan
Expand All @@ -15,9 +14,11 @@ import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.next
import io.kotest.property.arbitrary.orNull
import io.kotest.property.checkAll
import kotlin.test.Test
import kotlinx.coroutines.test.runTest

class GeneratorsTest : FreeSpec({
"functionAToB: should return same result when invoked multiple times" {
class GeneratorsTest {
@Test fun functionAToBShouldReturnSameResultWhenInvokedMultipleTimes() = runTest {
checkAll(
Arb.int(),
Arb.functionAToB<Int, Int>(Arb.int())
Expand All @@ -26,7 +27,7 @@ class GeneratorsTest : FreeSpec({
}
}

"functionAToB: should return some different values" {
@Test fun functionAToBShouldReturnSomeDifferentValues() = runTest {
val a = Arb.int().next(fixedRandom)
val a2 = Arb.int().next(fixedRandom)

Expand All @@ -37,7 +38,7 @@ class GeneratorsTest : FreeSpec({
}.shouldNotBeNull()
}

"functionABCToD: should return same result when invoked multiple times" {
@Test fun functionABCToDShouldReturnSameResultWhenInvokedMultipleTimes() = runTest {
checkAll(
Arb.int(),
Arb.int(),
Expand All @@ -48,7 +49,7 @@ class GeneratorsTest : FreeSpec({
}
}

"functionABCToD: should return some different values" {
@Test fun functionABCToDShouldReturnSomeDifferentValues() = runTest {
val a = Arb.int().next(fixedRandom)
val a2 = Arb.int().next(fixedRandom)
val b = Arb.int().next(fixedRandom)
Expand All @@ -61,7 +62,7 @@ class GeneratorsTest : FreeSpec({
}.shouldNotBeNull()
}

"Arb.map2: at least one sample should share no keys" {
@Test fun arbMap2AtLeastOneSampleShouldShareNoKeys() = runTest {
val result = givenSamples(
Arb.map2(
Arb.int(),
Expand All @@ -73,7 +74,7 @@ class GeneratorsTest : FreeSpec({
result.forAtLeastOne { it.shouldBeZero() }
}

"Arb.map2: at least one sample should share some keys" {
@Test fun arbMap2AtLeastOneSampleShouldShareSomeKeys() = runTest {
val result = givenSamples(
Arb.map2(
Arb.int(),
Expand All @@ -85,35 +86,35 @@ class GeneratorsTest : FreeSpec({
result.forAtLeastOne { it.shouldBeGreaterThan(0) }
}

"Arb.map2: no null values if the arb does not produce nullables" {
@Test fun arbMap2NoNullValuesIfTheArbDoesNotProduceNullables() = runTest {
givenSamples(Arb.map2(Arb.int(), Arb.boolean(), Arb.boolean()))
.forAll { sample ->
sample.value.first.values.forAll { it.shouldNotBeNull() }
sample.value.second.values.forAll { it.shouldNotBeNull() }
}
}

"Arb.map2: can contain null values if the arb produces nullables" {
@Test fun arbMap2CanContainNullValuesIfTheArbProducesNullables() = runTest {
givenSamples(Arb.map2(Arb.int(), Arb.boolean().orNull(), Arb.boolean().orNull()))
.forAtLeastOne { sample -> sample.value.first.values.forAtLeastOne { it.shouldBeNull() } }
.forAtLeastOne { sample -> sample.value.second.values.forAtLeastOne { it.shouldBeNull() } }
}

"Arb.map3: at least one sample should share no keys" {
@Test fun arbMap3AtLeastOneSampleShouldShareNoKeys() = runTest {
val result = givenSamples(Arb.map3(Arb.int(), Arb.boolean(), Arb.boolean(), Arb.boolean()))
.map { it.value.first.keys.intersect(it.value.second.keys).size }.toList()

result.forAtLeastOne { it.shouldBeZero() }
}

"Arb.map3: at least one sample should share some keys" {
@Test fun ArbMap3AtLeastOneSampleShouldShareSomeKeys() = runTest {
val result = givenSamples(Arb.map3(Arb.int(), Arb.boolean(), Arb.boolean(), Arb.boolean()))
.map { it.value.first.keys.intersect(it.value.second.keys).size }.toList()

result.forAtLeastOne { it.shouldBeGreaterThan(0) }
}

"Arb.map3: no null values if the arb does not produce nullables" {
@Test fun arbMap3NoNullValuesIfTheArbDoesNotProduceNullables() = runTest {
givenSamples(Arb.map3(Arb.int(), Arb.boolean(), Arb.boolean(), Arb.boolean()))
.forAll { sample ->
sample.value.first.values.forAll { it.shouldNotBeNull() }
Expand All @@ -122,13 +123,13 @@ class GeneratorsTest : FreeSpec({
}
}

"Arb.map3: can contain null values if the arb produces nullables" {
@Test fun arbMap3CanContainNullValuesIfTheArbProducesNullables() = runTest {
givenSamples(Arb.map3(Arb.int(), Arb.boolean().orNull(), Arb.boolean().orNull(), Arb.boolean().orNull()))
.forAtLeastOne { sample -> sample.value.first.values.forAtLeastOne { it.shouldBeNull() } }
.forAtLeastOne { sample -> sample.value.second.values.forAtLeastOne { it.shouldBeNull() } }
.forAtLeastOne { sample -> sample.value.third.values.forAtLeastOne { it.shouldBeNull() } }
}
})
}

private fun <T> givenSamples(arb: Arb<T>, count: Int = 250) =
arb.generate(fixedRandom).take(count).toList()
Expand Down

0 comments on commit e29ce66

Please sign in to comment.