From 370ff78028ba5ee17bae69d1ad723c01353ec809 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Tue, 7 Nov 2023 18:32:19 +0100 Subject: [PATCH] Move tests from `serialization` and `functions` completely to `kotlin.test` --- .../arrow-core-serialization/build.gradle.kts | 10 +- .../arrow/core/serialization/BackAgainTest.kt | 35 +-- arrow-libs/core/arrow-core/build.gradle.kts | 1 - .../commonMain/kotlin/arrow/core/Either.kt | 8 +- .../kotlin/arrow/core/FunctionSyntaxTest.kt | 158 ----------- .../kotlin/arrow/core/MemoizationTest.kt | 251 ------------------ .../kotlin/arrow/core/test/Generators.kt | 17 +- .../kotlin/examples/example-either-01.kt | 8 +- .../kotlin/arrow/core/CurryingTest.kt | 201 +++++++++----- build.gradle.kts | 1 + 10 files changed, 166 insertions(+), 524 deletions(-) delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt delete mode 100644 arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MemoizationTest.kt rename arrow-libs/core/{arrow-core => arrow-functions}/src/commonTest/kotlin/arrow/core/CurryingTest.kt (86%) diff --git a/arrow-libs/core/arrow-core-serialization/build.gradle.kts b/arrow-libs/core/arrow-core-serialization/build.gradle.kts index 58d852c31d0..53ff992767d 100644 --- a/arrow-libs/core/arrow-core-serialization/build.gradle.kts +++ b/arrow-libs/core/arrow-core-serialization/build.gradle.kts @@ -4,7 +4,8 @@ plugins { id(libs.plugins.kotlin.multiplatform.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) alias(libs.plugins.arrowGradleConfig.publish) - alias(libs.plugins.kotest.multiplatform) + alias(libs.plugins.kotlinx.kover) + alias(libs.plugins.spotless) id(libs.plugins.kotlinx.serialization.get().pluginId) } @@ -25,17 +26,10 @@ kotlin { implementation(libs.kotlinx.serializationJson) implementation(libs.kotlin.test) implementation(libs.coroutines.test) - implementation(libs.kotest.frameworkEngine) implementation(libs.kotest.assertionsCore) implementation(libs.kotest.property) } } - - jvmTest { - dependencies { - runtimeOnly(libs.kotest.runnerJUnit5) - } - } } jvm { diff --git a/arrow-libs/core/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/BackAgainTest.kt b/arrow-libs/core/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/BackAgainTest.kt index c8fe782a083..f76c7c0c804 100644 --- a/arrow-libs/core/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/BackAgainTest.kt +++ b/arrow-libs/core/arrow-core-serialization/src/commonTest/kotlin/arrow/core/serialization/BackAgainTest.kt @@ -13,17 +13,18 @@ import arrow.core.Ior import arrow.core.NonEmptyList import arrow.core.NonEmptySet import arrow.core.Option -import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.checkAll +import io.kotest.property.arbitrary.int +import io.kotest.property.arbitrary.map +import io.kotest.property.arbitrary.string +import kotlin.test.Test +import kotlinx.coroutines.test.runTest import kotlinx.serialization.UseSerializers import kotlinx.serialization.json.Json import kotlinx.serialization.json.encodeToJsonElement import kotlinx.serialization.json.decodeFromJsonElement -import io.kotest.matchers.shouldBe -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.map -import io.kotest.property.arbitrary.string import kotlinx.serialization.Serializable /* @@ -46,24 +47,28 @@ data class NonEmptyListInside(val thing: NonEmptyList) @Serializable data class NonEmptySetInside(val thing: NonEmptySet) -inline fun StringSpec.backAgain(generator: Arb) { - "there and back again, ${T::class.simpleName}" { +inline fun backAgain(generator: Arb) = + runTest { checkAll(generator) { e -> val result = Json.encodeToJsonElement(e) val back = Json.decodeFromJsonElement(result) back shouldBe e } } -} /** * Checks that the result of serializing a value into JSON, * and then deserializing it, gives back the original. */ -class BackAgainTest : StringSpec({ - backAgain(Arb.either(Arb.string(), Arb.int()).map(::EitherInside)) - backAgain(Arb.ior(Arb.string(), Arb.int()).map(::IorInside)) - backAgain(Arb.option(Arb.string()).map(::OptionInside)) - backAgain(Arb.nonEmptyList(Arb.int()).map(::NonEmptyListInside)) - backAgain(Arb.nonEmptySet(Arb.int()).map(::NonEmptySetInside)) -}) +class BackAgainTest { + @Test fun backAgainEither() = + backAgain(Arb.either(Arb.string(), Arb.int()).map(::EitherInside)) + @Test fun backAgainIor() = + backAgain(Arb.ior(Arb.string(), Arb.int()).map(::IorInside)) + @Test fun backAgainOption() = + backAgain(Arb.option(Arb.string()).map(::OptionInside)) + @Test fun backAgainNonEmptyList() = + backAgain(Arb.nonEmptyList(Arb.int()).map(::NonEmptyListInside)) + @Test fun backAgainNonEmptySet() = + backAgain(Arb.nonEmptySet(Arb.int()).map(::NonEmptySetInside)) +} diff --git a/arrow-libs/core/arrow-core/build.gradle.kts b/arrow-libs/core/arrow-core/build.gradle.kts index cb1e5ded6fd..afcf7ecbe22 100644 --- a/arrow-libs/core/arrow-core/build.gradle.kts +++ b/arrow-libs/core/arrow-core/build.gradle.kts @@ -32,7 +32,6 @@ kotlin { commonTest { dependencies { implementation(projects.arrowFxCoroutines) - implementation(projects.arrowFunctions) implementation(libs.kotlin.test) implementation(libs.coroutines.test) implementation(libs.kotest.frameworkEngine) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index f195fbb99a8..85590c561d7 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -32,13 +32,15 @@ public typealias EitherNel = Either, A> * all becomes even more unwieldy when we try to compose exception-throwing procedures. * * ```kotlin - * import arrow.core.andThen - * * //sampleStart * val throwsSomeStuff: (Int) -> Double = {x -> x.toDouble()} * val throwsOtherThings: (Double) -> String = {x -> x.toString()} * val moreThrowing: (String) -> List = {x -> listOf(x)} - * val magic = throwsSomeStuff.andThen(throwsOtherThings).andThen(moreThrowing) + * val magic: (Int) -> List = { x -> + * val y = throwsSomeStuff(x) + * val z = throwsOtherThings(y) + * moreThrowing(z) + * } * //sampleEnd * fun main() { * println ("magic = $magic") diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt deleted file mode 100644 index 204cb0f7863..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/FunctionSyntaxTest.kt +++ /dev/null @@ -1,158 +0,0 @@ -package arrow.core - -import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe - -class FunctionSyntaxTest : StringSpec({ - - val sum = { i1: Int, i2: Int -> i1 + i2 } - val add5 = { i: Int -> i + 5 } - val multiplyBy2 = { i: Int -> i * 2 } - - "it should compose function correctly (andThen)" { - val potato = "potato" - val ninja = "ninja" - val get = { potato } - val map = { word: String -> ninja + word } - (get andThen map)() - (ninja + potato) shouldBe (get andThen map)() - } - - "testAndThen" { - val add5andMultiplyBy2 = add5 andThen multiplyBy2 - add5andMultiplyBy2(2) shouldBe 14 - } - - "testAndThen2" { - val sumAndMultiplyBy2 = sum andThen multiplyBy2 - sumAndMultiplyBy2(5, 2) shouldBe 14 - } - - "testCompose" { - val multiplyBy2andAdd5 = add5 compose multiplyBy2 - multiplyBy2andAdd5(2) shouldBe 9 - } - - "testCurrying" { - val sum2ints = { x: Int, y: Int -> x + y } - val curried = sum2ints.curried() - curried(2)(4) shouldBe 6 - val addFive = curried(5) - addFive(7) shouldBe 12 - } - - "testUncurrying" { - val sum2ints: (Int, Int) -> Int = { x, y -> x + y } - val curried: (Int) -> (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - // same type as sum2ints, - curried.uncurried()(2, 4) shouldBe 6 - sum2ints(2, 4) shouldBe 6 - } - - "testCurryingEffect" { - val sum2ints: suspend (Int, Int) -> Int = { x: Int, y: Int -> x + y } - val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - val addFive: suspend (Int) -> Int = curried(5) - addFive(7) shouldBe 12 - } - - "testUncurryingEffect" { - val sum2ints: suspend (Int, Int) -> Int = { x, y -> x + y } - val curried: (Int) -> suspend (Int) -> Int = sum2ints.curried() - curried(2)(4) shouldBe 6 - // same type as sum2ints, - curried.uncurried()(2, 4) shouldBe 6 - sum2ints(2, 4) shouldBe 6 - } - - "memoize" { - var counterA = 0 - var counterB = 0 - - val a = { _: Int -> counterA++ } - val b = { _: Int -> counterB++ }.memoize() - - repeat(5) { a(1) } - repeat(5) { b(1) } - - counterA shouldBe 5 - counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once - } - - "memoizeEmpty" { - var counterA = 0 - var counterB = 0 - - val a = { counterA++ } - val b = { counterB++ }.memoize() - - repeat(5) { a() } - repeat(5) { b() } - - counterA shouldBe 5 - counterB shouldBe 1 // calling several times a memoized function with the same parameter is computed just once - } - - "partially" { - val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10 = sum5ints.partially5(10) - val sum3intsTo15 = sum4intsTo10.partially4(5) - val sum2intsTo17 = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - - val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - - val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "suspend partially" { - val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10 = sum5ints.partially5(10) - val sum3intsTo15 = sum4intsTo10.partially4(5) - val sum2intsTo17 = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - - val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - - val helloX = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "partials" { - val sum5ints = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10: (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) - val sum3intsTo15: (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) - val sum2intsTo17: (Int, Int) -> Int = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - val prefixAndPostfix = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - val helloX: (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "suspend partials" { - val sum5ints: suspend (Int, Int, Int, Int, Int) -> Int = { a: Int, b: Int, c: Int, d: Int, e: Int -> a + b + c + d + e } - val sum4intsTo10: suspend (Int, Int, Int, Int) -> Int = sum5ints.partially5(10) - val sum3intsTo15: suspend (Int, Int, Int) -> Int = sum4intsTo10.partially4(5) - val sum2intsTo17: suspend (Int, Int) -> Int = sum3intsTo15.partially3(2) - sum2intsTo17(1, 2) shouldBe 20 - val prefixAndPostfix: suspend (String, String, String) -> String = { prefix: String, x: String, postfix: String -> "$prefix$x$postfix" } - val helloX: suspend (String) -> String = prefixAndPostfix.partially1("Hello, ").partially2("!") - helloX("Arrow") shouldBe "Hello, Arrow!" - } - - "bind" { - var i = 0 - fun inc(a: Int) { - i += a - } - - val binded = ::inc.partially1(5) - i shouldBe 0 - binded() - i shouldBe 5 - } - -}) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MemoizationTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MemoizationTest.kt deleted file mode 100644 index b3a5c484bdb..00000000000 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MemoizationTest.kt +++ /dev/null @@ -1,251 +0,0 @@ -package arrow.core - -import io.kotest.core.spec.style.StringSpec -import io.kotest.property.checkAll -import io.kotest.matchers.shouldBe -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import kotlin.random.Random - -class MemoizationTest : StringSpec({ - "Memoize races" { - checkAll { - fun sum(): Int = - Random.nextInt(Int.MAX_VALUE) - - val memoized = ::sum.memoize() - - val (first, second) = listOf( - async { memoized() }, - async { memoized() } - ).awaitAll() - - first shouldBe second - } - } - - "Memoize P0 only first execution runs" { - var runs = 0 - fun sum(): Int { - runs++ - return 1 - } - - val memoized = ::sum.memoize() - - memoized() shouldBe 1 - memoized() shouldBe 1 - runs shouldBe 1 - } - - "Memoize P0 nullable" { - var runs = 0 - fun sum(): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized() shouldBe null - memoized() shouldBe null - runs shouldBe 1 - } - - "Memoize P1 only first execution runs" { - var runs = 0 - fun sum(n: Int): Int { - runs++ - return n + 1 - } - - val memoized = ::sum.memoize() - - memoized(1) shouldBe 2 - memoized(1) shouldBe 2 - runs shouldBe 1 - memoized(2) shouldBe 3 - runs shouldBe 2 - memoized(3) shouldBe 4 - runs shouldBe 3 - } - - "Memoize P1 nullable" { - var runs = 0 - fun sum(n: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1) shouldBe null - memoized(1) shouldBe null - runs shouldBe 1 - } - - "Memoize P2 only first execution runs" { - var runs = 0 - fun sum(n1: Int, n2: Int): Int { - runs++ - return n1 + n2 + 1 - } - - val memoized = ::sum.memoize() - val result = consecSumResult(2) + 1 - - memoized(1, 2) shouldBe result - memoized(1, 2) shouldBe result - runs shouldBe 1 - memoized(2, 1) shouldBe result - runs shouldBe 2 - memoized(3, 2) shouldBe 6 - runs shouldBe 3 - } - - "Memoize P2 nullable" { - var runs = 0 - fun sum(n: Int, m: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1, 2) shouldBe null - memoized(1, 2) shouldBe null - runs shouldBe 1 - } - - "Memoize P3 only first execution runs" { - var runs = 0 - fun sum(n1: Int, n2: Int, n3: Int): Int { - runs++ - return n1 + n2 + n3 + 1 - } - - val memoized = ::sum.memoize() - val result = consecSumResult(3) + 1 - - memoized(1, 2, 3) shouldBe result - memoized(1, 2, 3) shouldBe result - runs shouldBe 1 - memoized(2, 3, 1) shouldBe result - runs shouldBe 2 - memoized(3, 1, 2) shouldBe result - runs shouldBe 3 - } - - "Memoize P3 nullable" { - var runs = 0 - fun sum(a: Int, b: Int, c: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1, 2, 3) shouldBe null - memoized(1, 2, 3) shouldBe null - runs shouldBe 1 - } - - "Memoize P4 only first execution runs" { - var runs = 0 - fun sum(n1: Int, n2: Int, n3: Int, n4: Int): Int { - runs++ - return n1 + n2 + n3 + n4 + 1 - } - - val memoized = ::sum.memoize() - val result = consecSumResult(4) + 1 - - memoized(1, 2, 3, 4) shouldBe result - memoized(1, 2, 3, 4) shouldBe result - runs shouldBe 1 - memoized(2, 3, 4, 1) shouldBe result - runs shouldBe 2 - memoized(3, 4, 1, 2) shouldBe result - runs shouldBe 3 - } - - "Memoize P4 nullable" { - var runs = 0 - fun sum(a: Int, b: Int, c: Int, d: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1, 2, 3, 4) shouldBe null - memoized(1, 2, 3, 4) shouldBe null - runs shouldBe 1 - } - - "Memoize P5 only first execution runs" { - var runs = 0 - fun sum(n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Int { - runs++ - return n1 + n2 + n3 + n4 + n5 + 1 - } - - val memoized = ::sum.memoize() - val result = consecSumResult(5) + 1 - - memoized(1, 2, 3, 4, 5) shouldBe result - memoized(1, 2, 3, 4, 5) shouldBe result - runs shouldBe 1 - memoized(2, 3, 4, 5, 1) shouldBe result - runs shouldBe 2 - memoized(3, 4, 5, 1, 2) shouldBe result - runs shouldBe 3 - } - - "Memoize P5 nullable" { - var runs = 0 - fun sum(a: Int, b: Int, c: Int, d: Int, e: Int): Int? { - runs++ - return null - } - - val memoized = ::sum.memoize() - - memoized(1, 2, 3, 4, 5) shouldBe null - memoized(1, 2, 3, 4, 5) shouldBe null - runs shouldBe 1 - } - - "Recursive memoization" { - var runs = 0 - val memoizedDeepRecursiveFibonacci: DeepRecursiveFunction = - MemoizedDeepRecursiveFunction { n -> - when (n) { - 0 -> 0.also { runs++ } - 1 -> 1 - else -> callRecursive(n - 1) + callRecursive(n - 2) - } - } - val result = memoizedDeepRecursiveFibonacci(5) - result shouldBe 5 - runs shouldBe 1 - } - - "Recursive memoization, run twice should be memoized" { - var runs = 0 - val memoizedDeepRecursiveFibonacci: DeepRecursiveFunction = - MemoizedDeepRecursiveFunction { n -> - when (n) { - 0 -> 0.also { runs++ } - 1 -> 1 - else -> callRecursive(n - 1) + callRecursive(n - 2) - } - } - val result1 = memoizedDeepRecursiveFibonacci(5) - val result2 = memoizedDeepRecursiveFibonacci(5) - result1 shouldBe result2 - runs shouldBe 1 - } -}) - -private fun consecSumResult(n: Int): Int = (n * (n + 1)) / 2 diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt index 8aaea6cd455..d0d0166edad 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/test/Generators.kt @@ -1,15 +1,6 @@ package arrow.core.test -import arrow.core.Either -import arrow.core.Ior -import arrow.core.NonEmptyList -import arrow.core.NonEmptySet -import arrow.core.Option -import arrow.core.left -import arrow.core.memoize -import arrow.core.right -import arrow.core.toNonEmptySetOrNull -import arrow.core.toOption +import arrow.core.* import io.kotest.property.Arb import io.kotest.property.arbitrary.arbitrary import io.kotest.property.arbitrary.bind @@ -47,11 +38,13 @@ fun Arb.Companion.sequence(arb: Arb, range: IntRange = 0 .. 100): Arb Arb.Companion.functionAToB(arb: Arb): Arb<(A) -> B> = arbitrary { random -> - { _: A -> arb.next(random) }.memoize() + val memoized = MemoizedDeepRecursiveFunction { _ -> arb.next(random) } + fun (x: A): B = memoized(x) } fun Arb.Companion.functionABCToD(arb: Arb): Arb<(A, B, C) -> D> = arbitrary { random -> - { _: A, _:B, _:C -> arb.next(random)}.memoize() + val memoized = MemoizedDeepRecursiveFunction, D> { _ -> arb.next(random) } + fun (x: A, y: B, z: C): D = memoized(Triple(x, y, z)) } fun Arb.Companion.throwable(): Arb = diff --git a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt index 313a4846eda..2239f19f668 100644 --- a/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt +++ b/arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-either-01.kt @@ -1,12 +1,14 @@ // This file was automatically generated from Either.kt by Knit tool. Do not edit. package arrow.core.examples.exampleEither01 -import arrow.core.andThen - val throwsSomeStuff: (Int) -> Double = {x -> x.toDouble()} val throwsOtherThings: (Double) -> String = {x -> x.toString()} val moreThrowing: (String) -> List = {x -> listOf(x)} -val magic = throwsSomeStuff.andThen(throwsOtherThings).andThen(moreThrowing) +val magic: (Int) -> List = { x -> + val y = throwsSomeStuff(x) + val z = throwsOtherThings(y) + moreThrowing(z) +} fun main() { println ("magic = $magic") } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/CurryingTest.kt similarity index 86% rename from arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt rename to arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/CurryingTest.kt index cec444b9c23..28886cab4bc 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt +++ b/arrow-libs/core/arrow-functions/src/commonTest/kotlin/arrow/core/CurryingTest.kt @@ -1,162 +1,184 @@ package arrow.core -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.string import io.kotest.property.checkAll +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class CurryingTest : StringSpec({ +class CurryingTest { fun arb(): Arb = Arb.string(1) //region curried - "A 2-arity curried function returns the same result as the function before being curried" { + @Test + fun curry2() = runTest { checkAll(arb(), arb()) { a1, a2 -> val add = { p1: String, p2: String -> p1 + p2 } add.curried()(a1)(a2) shouldBe add(a1, a2) } } - "A 3-arity curried function returns the same result as the function before being curried" { + @Test + fun curry3() = runTest { checkAll(arb(), arb(), arb()) { a1, a2, a3 -> val add = { p1: String, p2: String, p3: String -> p1 + p2 + p3 } add.curried()(a1)(a2)(a3) shouldBe add(a1, a2, a3) } } - "A 4-arity curried function returns the same result as the function before being curried" { + @Test + fun curry4() = runTest { checkAll(arb(), arb(), arb(), arb()) { a1, a2, a3, a4 -> val add = { p1: String, p2: String, p3: String, p4: String -> p1 + p2 + p3 + p4 } add.curried()(a1)(a2)(a3)(a4) shouldBe add(a1, a2, a3, a4) } } - "A 5-arity curried function returns the same result as the function before being curried" { + @Test + fun curry5() = runTest { checkAll(arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String -> p1 + p2 + p3 + p4 + p5 } add.curried()(a1)(a2)(a3)(a4)(a5) shouldBe add(a1, a2, a3, a4, a5) } } - "A 6-arity curried function returns the same result as the function before being curried" { + @Test + fun curry6() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String -> p1 + p2 + p3 + p4 + p5 + p6 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6) shouldBe add(a1, a2, a3, a4, a5, a6) } } - "A 7-arity curried function returns the same result as the function before being curried" { + @Test + fun curry7() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7) shouldBe add(a1, a2, a3, a4, a5, a6, a7) } } - "An 8-arity curried function returns the same result as the function before being curried" { + @Test + fun curry8() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8) } } - "A 9-arity curried function returns the same result as the function before being curried" { + @Test + fun curry9() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9) } } - "A 10-arity curried function returns the same result as the function before being curried" { + @Test + fun curry10() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) } } - "An 11-arity curried function returns the same result as the function before being curried" { + @Test + fun curry11() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) } } - "A 12-arity curried function returns the same result as the function before being curried" { + @Test + fun curry12() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) } } - /* Waiting for Kotest 5.6.0 to be released + /* - "A 13-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> + @Test + fun curry13() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) } } - "A 14-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14 -> + @Test + fun curry14() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) } } - "A 15-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 -> + @Test + fun curry15() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) } } - "A 16-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16 -> + @Test + fun curry16() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) } } - "A 17-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17 -> + @Test + fun curry17() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) } } - "A 18-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18 -> + @Test + fun curry18() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) } } - "A 19-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19 -> + @Test + fun curry19() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String, p19: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) } } - "A 20-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 -> + @Test + fun curry20() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String, p19: String, p20: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 + p20 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)(a20) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) } } - "A 21-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21 -> + @Test + fun curry21() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String, p19: String, p20: String, p21: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 + p20 + p21 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)(a20)(a21) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21) } } - "A 22-arity curried function returns the same result as the function before being curried" { - checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22 -> + @Test + fun curry22() = runTest { + checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String, p13: String, p14: String, p15: String, p16: String, p17: String, p18: String, p19: String, p20: String, p21: String, p22: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 + p20 + p21 + p22 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)(a20)(a21)(a22) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22) } @@ -168,7 +190,8 @@ class CurryingTest : StringSpec({ // region uncurried - "A 2-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry2() = runTest { checkAll(arb(), arb()) { a1, a2 -> val add = { p1: String, p2: String -> p1 + p2 } val curriedAdd = add.curried() @@ -176,7 +199,8 @@ class CurryingTest : StringSpec({ } } - "A 3-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry3() = runTest { checkAll(arb(), arb(), arb()) { a1, a2, a3 -> val add = { p1: String, p2: String, p3: String -> p1 + p2 + p3 } val curriedAdd = add.curried() @@ -184,7 +208,8 @@ class CurryingTest : StringSpec({ } } - "A 4-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry4() = runTest { checkAll(arb(), arb(), arb(), arb()) { a1, a2, a3, a4 -> val add = { p1: String, p2: String, p3: String, p4: String -> p1 + p2 + p3 + p4 } val curriedAdd = add.curried() @@ -192,7 +217,8 @@ class CurryingTest : StringSpec({ } } - "A 5-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry5() = runTest { checkAll(arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String -> p1 + p2 + p3 + p4 + p5 } val curriedAdd = add.curried() @@ -200,7 +226,8 @@ class CurryingTest : StringSpec({ } } - "A 6-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry6() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String -> p1 + p2 + p3 + p4 + p5 + p6 } val curriedAdd = add.curried() @@ -208,7 +235,8 @@ class CurryingTest : StringSpec({ } } - "A 7-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry7() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } val curriedAdd = add.curried() @@ -216,7 +244,8 @@ class CurryingTest : StringSpec({ } } - "A 8-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry8() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } val curriedAdd = add.curried() @@ -224,7 +253,8 @@ class CurryingTest : StringSpec({ } } - "A 9-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry9() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } val curriedAdd = add.curried() @@ -232,7 +262,8 @@ class CurryingTest : StringSpec({ } } - "A 10-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry10() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } val curriedAdd = add.curried() @@ -240,7 +271,8 @@ class CurryingTest : StringSpec({ } } - "A 11-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry11() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 } val curriedAdd = add.curried() @@ -248,7 +280,8 @@ class CurryingTest : StringSpec({ } } - "A 12-arity curried function returns the same result as the function after being uncurried" { + @Test + fun uncurry12() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 -> val add = { p1: String, p2: String, p3: String, p4: String, p5: String, p6: String, p7: String, p8: String, p9: String, p10: String, p11: String, p12: String-> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 } val curriedAdd = add.curried() @@ -256,7 +289,7 @@ class CurryingTest : StringSpec({ } } - /* Waiting for Kotest 5.6.0 to be released + /* "A 13-arity curried function returns the same result as the function after being uncurried" { checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> @@ -344,84 +377,95 @@ class CurryingTest : StringSpec({ // region curried effect - "A 2-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect2() = runTest { checkAll(arb(), arb()) { a1, a2 -> val add: suspend (String, String) -> String = { p1, p2 -> p1 + p2 } add.curried()(a1)(a2) shouldBe add(a1, a2) } } - "A 3-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect3() = runTest { checkAll(arb(), arb(), arb()) { a1, a2, a3 -> val add: suspend (String, String, String) -> String = { p1, p2, p3 -> p1 + p2 + p3 } add.curried()(a1)(a2)(a3) shouldBe add(a1, a2, a3) } } - "A 4-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect4() = runTest { checkAll(arb(), arb(), arb(), arb()) { a1, a2, a3, a4 -> val add: suspend (String, String, String, String) -> String = { p1, p2, p3, p4 -> p1 + p2 + p3 + p4 } add.curried()(a1)(a2)(a3)(a4) shouldBe add(a1, a2, a3, a4) } } -// - "A 5-arity curried effect returns the same result as the effect before being curried" { + + @Test + fun curryEffect5() = runTest { checkAll(arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5 -> val add: suspend (String, String, String, String, String) -> String = { p1, p2, p3, p4, p5 -> p1 + p2 + p3 + p4 + p5 } add.curried()(a1)(a2)(a3)(a4)(a5) shouldBe add(a1, a2, a3, a4, a5) } } - "A 6-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect6() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6 -> val add: suspend (String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6 -> p1 + p2 + p3 + p4 + p5 + p6 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6) shouldBe add(a1, a2, a3, a4, a5, a6) } } - "A 7-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect7() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7 -> val add: suspend (String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7) shouldBe add(a1, a2, a3, a4, a5, a6, a7) } } - "An 8-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect8() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8 -> val add: suspend (String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8) } } - "A 9-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect9() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> val add: suspend (String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9) } } - "A 10-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect10() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -> val add: suspend (String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) } } - "An 11-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect11() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 -> val add: suspend (String, String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) } } - "A 12-arity curried effect returns the same result as the effect before being curried" { + @Test + fun curryEffect12() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 -> val add: suspend (String, String, String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 } add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12) shouldBe add(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) } } - /* Waiting for Kotest 5.6.0 to be released + /* "A 13-arity curried effect returns the same result as the effect before being curried" { checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> @@ -499,7 +543,8 @@ class CurryingTest : StringSpec({ // region uncurried effect - "A 2-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect2() = runTest { checkAll(arb(), arb()) { a1, a2 -> val add: suspend (String, String) -> String = { p1, p2 -> p1 + p2 } val curriedAdd = add.curried() @@ -507,7 +552,8 @@ class CurryingTest : StringSpec({ } } - "A 3-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect3() = runTest { checkAll(arb(), arb(), arb()) { a1, a2, a3 -> val add: suspend (String, String, String) -> String = { p1, p2, p3 -> p1 + p2 + p3 } val curriedAdd = add.curried() @@ -515,15 +561,17 @@ class CurryingTest : StringSpec({ } } - "A 4-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect4() = runTest { checkAll(arb(), arb(), arb(), arb()) { a1, a2, a3, a4 -> val add: suspend (String, String, String, String) -> String = { p1, p2, p3, p4 -> p1 + p2 + p3 + p4 } val curriedAdd = add.curried() curriedAdd(a1)(a2)(a3)(a4) shouldBe curriedAdd.uncurried()(a1, a2, a3, a4) } } -// - "A 5-arity curried effect returns the same result as the effect after being uncurried" { + + @Test + fun curryUncurryEffect5() = runTest { checkAll(arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5 -> val add: suspend (String, String, String, String, String) -> String = { p1, p2, p3, p4, p5 -> p1 + p2 + p3 + p4 + p5 } val curriedAdd = add.curried() @@ -531,7 +579,8 @@ class CurryingTest : StringSpec({ } } - "A 6-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect6() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6 -> val add: suspend (String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6 -> p1 + p2 + p3 + p4 + p5 + p6 } val curriedAdd = add.curried() @@ -539,7 +588,8 @@ class CurryingTest : StringSpec({ } } - "A 7-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect7() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7 -> val add: suspend (String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } val curriedAdd = add.curried() @@ -547,7 +597,8 @@ class CurryingTest : StringSpec({ } } - "An 8-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect8() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8 -> val add: suspend (String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } val curriedAdd = add.curried() @@ -555,7 +606,8 @@ class CurryingTest : StringSpec({ } } - "A 9-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect9() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> val add: suspend (String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } val curriedAdd = add.curried() @@ -563,7 +615,8 @@ class CurryingTest : StringSpec({ } } - "A 10-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect10() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -> val add: suspend (String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } val curriedAdd = add.curried() @@ -571,7 +624,8 @@ class CurryingTest : StringSpec({ } } - "An 11-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect11() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 -> val add: suspend (String, String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 } val curriedAdd = add.curried() @@ -579,7 +633,8 @@ class CurryingTest : StringSpec({ } } - "A 12-arity curried effect returns the same result as the effect after being uncurried" { + @Test + fun curryUncurryEffect12() = runTest { checkAll(arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 -> val add: suspend (String, String, String, String, String, String, String, String, String, String, String, String) -> String = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 } val curriedAdd = add.curried() @@ -587,7 +642,7 @@ class CurryingTest : StringSpec({ } } - /* Waiting for Kotest 5.6.0 to be released + /* "A 13-arity curried effect returns the same result as the effect after being uncurried" { checkAll(PropTestConfig(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb(), arb()) { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 -> @@ -672,4 +727,4 @@ class CurryingTest : StringSpec({ */ // endregion -}) +} diff --git a/build.gradle.kts b/build.gradle.kts index cc6ea0d8f1c..072f06ed65f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -68,6 +68,7 @@ dependencies { kover(projects.arrowCore) kover(projects.arrowCoreRetrofit) kover(projects.arrowCoreSerialization) + kover(projects.arrowFunctions) kover(projects.arrowFxCoroutines) kover(projects.arrowFxStm) kover(projects.arrowOptics)