Skip to content

Commit

Permalink
fix kotest warning about duplicate test names (#3023)
Browse files Browse the repository at this point in the history
  • Loading branch information
abendt committed Apr 3, 2023
1 parent 493a22d commit 64eff14
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import io.kotest.property.arbitrary.boolean

class BooleanTest : StringSpec({
testLaws(
MonoidLaws(true, { x, y -> x && y }, Arb.boolean())
MonoidLaws("Boolean", true, { x, y -> x && y }, Arb.boolean())
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import io.kotest.property.arbitrary.float
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.long
import io.kotest.property.arbitrary.string
import io.kotest.property.arbitrary.nonPositiveInt
import io.kotest.property.arbitrary.short
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll

class EitherTest : StringSpec({

val ARB = Arb.either(Arb.string(), Arb.int())

testLaws(
MonoidLaws(0.right(), { x, y -> x.combine(y, String::plus, Int::plus) }, ARB)
MonoidLaws("Either", 0.right(), { x, y -> x.combine(y, String::plus, Int::plus) }, ARB)
)

"isLeft should return true if Left and false if Right" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.kotest.property.arbitrary.int
class EndoTest : StringSpec({

testLaws(
MonoidLaws(Endo(::identity), { f, g -> Endo(f.f.compose(g.f)) }, Arb.endo(Arb.int())) { a, b ->
MonoidLaws("Endo", Endo(::identity), { f, g -> Endo(f.f.compose(g.f)) }, Arb.endo(Arb.int())) { a, b ->
a.f(1) == b.f(1)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import arrow.typeclasses.Semigroup
import io.kotest.core.spec.style.StringSpec
import io.kotest.data.forAll
import io.kotest.data.row
import io.kotest.property.Arb
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.long
import io.kotest.property.arbitrary.orNull
Expand All @@ -21,7 +21,7 @@ class IorTest : StringSpec({
val ARB = Arb.ior(Arb.string(), Arb.int())

testLaws(
SemigroupLaws({ a, b ->
SemigroupLaws("Ior", { a, b ->
a.combine(b, String::plus, Int::plus)
}, ARB)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.kotest.property.checkAll

class ListKTest : StringSpec({

testLaws(MonoidLaws(emptyList(), List<Int>::plus, Arb.list(Arb.int())))
testLaws(MonoidLaws("List", emptyList(), List<Int>::plus, Arb.list(Arb.int())))

"mapNotNull() should map list and filter out null values" {
checkAll(Arb.list(Arb.int())) { listk ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import arrow.core.test.functionAToB
import arrow.core.test.intSmall
import arrow.core.test.ior
import arrow.core.test.laws.MonoidLaws
import arrow.core.test.longSmall
import arrow.core.test.map2
import arrow.core.test.map3
import arrow.core.test.option
Expand All @@ -30,14 +29,14 @@ import io.kotest.property.arbitrary.choice
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.map
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.orNull
import io.kotest.property.arbitrary.string
import io.kotest.property.arbitrary.pair
import io.kotest.property.checkAll

class MapKTest : StringSpec({
testLaws(
MonoidLaws(
"Map",
emptyMap(),
{ a, b -> a.combine(b, Int::plus) },
Arb.map(Arb.int(), Arb.intSmall(), maxSize = 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import io.kotest.core.spec.style.StringSpec
import io.kotest.inspectors.shouldForAll
import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.property.Arb
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.negativeInt
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll
import kotlin.math.max
import kotlin.math.min

class NonEmptyListTest : StringSpec({

testLaws(SemigroupLaws(NonEmptyList<Int>::plus, Arb.nonEmptyList(Arb.int())))
testLaws(SemigroupLaws("NonEmptyList", NonEmptyList<Int>::plus, Arb.nonEmptyList(Arb.int())))

"iterable.toNonEmptyListOrNull should round trip" {
checkAll(Arb.nonEmptyList(Arb.int())) { nonEmptyList ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OptionTest : StringSpec({
val none: Option<String> = None

testLaws(
MonoidLaws(None, { x, y -> x.combine(y, Int::plus) }, Arb.option(Arb.int()))
MonoidLaws("Option", None, { x, y -> x.combine(y, Int::plus) }, Arb.option(Arb.int()))
)

"ensure null in option computation" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ import arrow.core.test.unit
import arrow.typeclasses.Semigroup
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.sequences.shouldBeEmpty
import io.kotest.property.Arb
import io.kotest.property.checkAll
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.positiveInt
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll
import kotlin.math.max
import kotlin.math.min

class SequenceKTest : StringSpec({

testLaws(MonoidLaws(emptySequence(), { a, b -> sequenceOf(a, b).flatten()} , Arb.sequence(Arb.int())) { s1, s2 -> s1.toList() == s2.toList() })
testLaws(MonoidLaws("Sequence", emptySequence(), { a, b -> sequenceOf(a, b).flatten()} , Arb.sequence(Arb.int())) { s1, s2 -> s1.toList() == s2.toList() })

"traverse for Either stack-safe" {
// also verifies result order and execution order (l to r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ import io.kotest.property.arbitrary.short
class NumberInstancesTest : StringSpec({

fun <F> testAllLaws(
name: String,
zero: F,
combine: (F, F) -> F,
one: F,
combineMultiplicate: (F, F) -> F,
GEN: Arb<F>,
eq: (F, F) -> Boolean = { a, b -> a == b }
) {
testLaws(SemiringLaws(zero, combine, one, combineMultiplicate, GEN, eq))
testLaws(MonoidLaws(zero, combine, GEN, eq))
testLaws(SemiringLaws(name, zero, combine, one, combineMultiplicate, GEN, eq))
testLaws(MonoidLaws(name, zero, combine, GEN, eq))
}

testAllLaws(0, { x, y -> (x + y).toByte() }, 1, { x, y -> (x * y).toByte() }, Arb.byte())
testAllLaws(0, { x, y -> (x + y).toShort() }, 1, { x, y -> (x * y).toShort() }, Arb.short())
testAllLaws(0, { x, y -> x + y }, 1, { x, y -> x * y }, Arb.int())
testAllLaws(0, { x, y -> x + y }, 1, { x, y -> x * y }, Arb.long())
testAllLaws("Byte", 0, { x, y -> (x + y).toByte() }, 1, { x, y -> (x * y).toByte() }, Arb.byte())
testAllLaws("Short", 0, { x, y -> (x + y).toShort() }, 1, { x, y -> (x * y).toShort() }, Arb.short())
testAllLaws("Int", 0, Int::plus, 1, Int::times, Arb.int())
testAllLaws("Long", 0, Long::plus, 1, Long::times, Arb.long())

})
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ package arrow.core.test.laws
import arrow.core.test.Law
import arrow.core.test.LawSet
import arrow.core.test.equalUnderTheLaw
import io.kotest.property.Arb
import io.kotest.property.checkAll
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.PropertyContext
import io.kotest.property.arbitrary.list
import io.kotest.property.checkAll

data class MonoidLaws<F>(
val name: String,
val empty: F,
val combine: (F, F) -> F,
val GEN: Arb<F>,
val eq: (F, F) -> Boolean = { a, b -> a == b }
): LawSet {

override val laws: List<Law> =
SemigroupLaws(combine, GEN, eq).laws +
SemigroupLaws(name, combine, GEN, eq).laws +
listOf(
Law("Monoid Laws: Left identity") { monoidLeftIdentity() },
Law("Monoid Laws: Right identity") { monoidRightIdentity() },
Law("Monoid Laws: combineAll should be derived") { combineAllIsDerived() },
Law("Monoid Laws: combineAll of empty list is empty") { combineAllOfEmptyIsEmpty() }
Law("Monoid Laws ($name): Left identity") { monoidLeftIdentity() },
Law("Monoid Laws ($name): Right identity") { monoidRightIdentity() },
Law("Monoid Laws ($name): combineAll should be derived") { combineAllIsDerived() },
Law("Monoid Laws ($name): combineAll of empty list is empty") { combineAllOfEmptyIsEmpty() }
)

private suspend fun monoidLeftIdentity(): PropertyContext =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import io.kotest.property.PropertyContext
import io.kotest.property.checkAll

data class SemigroupLaws<F>(
val name: String,
val combine: (F, F) -> F,
val G: Arb<F>,
val eq: (F, F) -> Boolean = { a, b -> a == b }
): LawSet {

override val laws: List<Law> =
listOf(Law("Semigroup: associativity") { semigroupAssociative() })
listOf(Law("Semigroup Laws ($name): associativity") { semigroupAssociative() })

private suspend fun semigroupAssociative(): PropertyContext =
checkAll(G, G, G) { A, B, C ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.kotest.property.Arb
import io.kotest.property.checkAll

data class SemiringLaws<F>(
val name: String,
val zero: F,
val combine: (F, F) -> F,
val one: F,
Expand All @@ -17,18 +18,18 @@ data class SemiringLaws<F>(

override val laws: List<Law> =
listOf(
Law("Semiring: Additive commutativity") { semiringAdditiveCommutativity() },
Law("Semiring: Additive left identity") { semiringAdditiveLeftIdentity() },
Law("Semiring: Additive right identity") { semiringAdditiveRightIdentity() },
Law("Semiring: Additive associativity") { semiringAdditiveAssociativity() },
Law("Semiring: Multiplicative commutativity") { semiringMultiplicativeCommutativity() },
Law("Semiring: Multiplicative left identity") { semiringMultiplicativeLeftIdentity() },
Law("Semiring: Multiplicative right identity") { semiringMultiplicativeRightIdentity() },
Law("Semiring: Multiplicative associativity") { semiringMultiplicativeAssociativity() },
Law("Semiring: Right distributivity") { semiringRightDistributivity() },
Law("Semiring: Left distributivity") { semiringLeftDistributivity() },
Law("Semiring: Multiplicative left absorption") { semiringMultiplicativeLeftAbsorption() },
Law("Semiring: Multiplicative right absorption") { semiringMultiplicativeRightAbsorption() },
Law("Semiring Laws ($name): Additive commutativity") { semiringAdditiveCommutativity() },
Law("Semiring Laws ($name): Additive left identity") { semiringAdditiveLeftIdentity() },
Law("Semiring Laws ($name): Additive right identity") { semiringAdditiveRightIdentity() },
Law("Semiring Laws ($name): Additive associativity") { semiringAdditiveAssociativity() },
Law("Semiring Laws ($name): Multiplicative commutativity") { semiringMultiplicativeCommutativity() },
Law("Semiring Laws ($name): Multiplicative left identity") { semiringMultiplicativeLeftIdentity() },
Law("Semiring Laws ($name): Multiplicative right identity") { semiringMultiplicativeRightIdentity() },
Law("Semiring Laws ($name): Multiplicative associativity") { semiringMultiplicativeAssociativity() },
Law("Semiring Laws ($name): Right distributivity") { semiringRightDistributivity() },
Law("Semiring Laws ($name): Left distributivity") { semiringLeftDistributivity() },
Law("Semiring Laws ($name): Multiplicative left absorption") { semiringMultiplicativeLeftAbsorption() },
Law("Semiring Laws ($name): Multiplicative right absorption") { semiringMultiplicativeRightAbsorption() },
)

// a + b = b + a
Expand Down

0 comments on commit 64eff14

Please sign in to comment.