From 00efe4219cb4ea1d866e113195e35463a8a31234 Mon Sep 17 00:00:00 2001 From: Stojan Anastasov Date: Fri, 8 Mar 2019 19:28:13 +0100 Subject: [PATCH 1/4] Update kotlintest to version 3.3.1 Law updated because the function has to be suspended NumberMonoid updated because nesting is not supported and I had to create some generators Moore updated because the default toString implementation breaks kotlin-reflect --- build.gradle | 2 +- .../arrow/extensions/NumberMonoidTest.kt | 76 +++++++++---------- .../src/main/kotlin/arrow/data/Moore.kt | 2 + .../arrow/test/generators/Generators.kt | 6 ++ .../src/main/kotlin/arrow/test/laws/Law.kt | 2 +- 5 files changed, 48 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index 08e84d1cffd..e94f949b110 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ buildscript { javaVersion = JavaVersion.VERSION_1_7 jUnitVersion = '4.12' jUnitVintageVersion = '5.2.0' - kotlinTestVersion = '3.1.5' + kotlinTestVersion = '3.3.1' kotlinVersion = '1.3.11' daggerVersion = '2.17' kotlinxCoroutinesVersion = '1.1.0' diff --git a/modules/core/arrow-core-data/src/test/kotlin/arrow/extensions/NumberMonoidTest.kt b/modules/core/arrow-core-data/src/test/kotlin/arrow/extensions/NumberMonoidTest.kt index a7f3f86d2c4..b061833a5c1 100644 --- a/modules/core/arrow-core-data/src/test/kotlin/arrow/extensions/NumberMonoidTest.kt +++ b/modules/core/arrow-core-data/src/test/kotlin/arrow/extensions/NumberMonoidTest.kt @@ -2,6 +2,9 @@ package arrow.extensions import arrow.core.extensions.monoid import arrow.test.UnitSpec +import arrow.test.generators.byte +import arrow.test.generators.short +import io.kotlintest.properties.Gen import io.kotlintest.runner.junit4.KotlinTestRunner import io.kotlintest.properties.forAll import org.junit.runner.RunWith @@ -10,60 +13,57 @@ import org.junit.runner.RunWith class NumberMonoidTest : UnitSpec() { init { - "should semigroup with the instance passed" { - "int" { - forAll { value: Int -> - val seen = Int.monoid().run { value.combine(value) } - val expected = value + value + "should semigroup with the instance passed - int" { + forAll { value: Int -> + val seen = Int.monoid().run { value.combine(value) } + val expected = value + value - expected == seen - } + expected == seen } + } - "float" { - forAll { value: Float -> - val seen = Float.monoid().run { value.combine(value) } - val expected = value + value + "should semigroup with the instance passed - float" { + forAll(Gen.numericFloats()) { value: Float -> + val seen = Float.monoid().run { value.combine(value) } + val expected = value + value - expected == seen - } + expected == seen } + } - "double" { - forAll { value: Double -> - val seen = Double.monoid().run { value.combine(value) } - val expected = value + value + "should semigroup with the instance passed - double" { + forAll(Gen.numericDoubles()) { value: Double -> + val seen = Double.monoid().run { value.combine(value) } + val expected = value + value - expected == seen - } + expected == seen } + } - "long" { - - forAll { value: Long -> - val seen = Long.monoid().run { value.combine(value) } - val expected = value + value + "should semigroup with the instance passed - long" { + forAll { value: Long -> + val seen = Long.monoid().run { value.combine(value) } + val expected = value + value - expected == seen - } + expected == seen } + } - "short" { - forAll { value: Short -> - val seen = Short.monoid().run { value.combine(value) } - val expected = (value + value).toShort() + "should semigroup with the instance passed - short" { + forAll(Gen.short()) { value: Short -> + val seen = Short.monoid().run { value.combine(value) } + val expected = (value + value).toShort() - expected == seen - } + expected == seen } + } - "byte" { - forAll { value: Byte -> - val seen = Byte.monoid().run { value.combine(value) } - val expected = (value + value).toByte() + "should semigroup with the instance passed - byte" { + forAll(Gen.byte()) { value: Byte -> + val seen = Byte.monoid().run { value.combine(value) } + val expected = (value + value).toByte() - expected == seen - } + expected == seen } } } diff --git a/modules/core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt b/modules/core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt index b488c136ccf..66d28bc2b12 100644 --- a/modules/core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt +++ b/modules/core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt @@ -13,5 +13,7 @@ data class Moore(val view: V, val handle: (E) -> Moore) : MooreOf = + Gen.int().filter { it >= Short.MIN_VALUE && it <= Short.MAX_VALUE }.map { it.toShort() } + +fun Gen.Companion.byte(): Gen = + Gen.int().filter { it >= Byte.MIN_VALUE && it <= Byte.MAX_VALUE }.map { it.toByte() } + fun Gen.applicative(AP: Applicative): Gen> = map { AP.just(it) } diff --git a/modules/core/arrow-test/src/main/kotlin/arrow/test/laws/Law.kt b/modules/core/arrow-test/src/main/kotlin/arrow/test/laws/Law.kt index 78bd8427490..05b77e4cd60 100644 --- a/modules/core/arrow-test/src/main/kotlin/arrow/test/laws/Law.kt +++ b/modules/core/arrow-test/src/main/kotlin/arrow/test/laws/Law.kt @@ -13,7 +13,7 @@ fun throwableEq() = Eq { a: Throwable, b -> a::class == b::class && a.message == b.message } -data class Law(val name: String, val test: TestContext.() -> Unit) +data class Law (val name: String, val test: suspend TestContext.() -> Unit) fun A.equalUnderTheLaw(b: A, eq: Eq): Boolean = eq.run { eqv(b) } From a62e8a14006d6638ec7ca5255c1678d5725990da Mon Sep 17 00:00:00 2001 From: Stojan Anastasov Date: Fri, 8 Mar 2019 20:12:41 +0100 Subject: [PATCH 2/4] Speed up the generators for Short and Byte --- .../src/main/kotlin/arrow/test/generators/Generators.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/arrow-test/src/main/kotlin/arrow/test/generators/Generators.kt b/modules/core/arrow-test/src/main/kotlin/arrow/test/generators/Generators.kt index 52e7758cbe2..497e80b6367 100644 --- a/modules/core/arrow-test/src/main/kotlin/arrow/test/generators/Generators.kt +++ b/modules/core/arrow-test/src/main/kotlin/arrow/test/generators/Generators.kt @@ -15,10 +15,10 @@ import io.kotlintest.properties.Gen import java.util.concurrent.TimeUnit fun Gen.Companion.short(): Gen = - Gen.int().filter { it >= Short.MIN_VALUE && it <= Short.MAX_VALUE }.map { it.toShort() } + Gen.choose(Short.MIN_VALUE.toInt(), Short.MAX_VALUE.toInt()).map { it.toShort() } fun Gen.Companion.byte(): Gen = - Gen.int().filter { it >= Byte.MIN_VALUE && it <= Byte.MAX_VALUE }.map { it.toByte() } + Gen.choose(Byte.MIN_VALUE.toInt(), Byte.MAX_VALUE.toInt()).map { it.toByte() } fun Gen.applicative(AP: Applicative): Gen> = map { AP.just(it) } From 678529131b499f27f651847dec207d2b095433de Mon Sep 17 00:00:00 2001 From: Stojan Anastasov Date: Fri, 8 Mar 2019 20:12:59 +0100 Subject: [PATCH 3/4] Update toString for Moore --- .../core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt b/modules/core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt index 66d28bc2b12..93b6b4cd051 100644 --- a/modules/core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt +++ b/modules/core/arrow-extras-data/src/main/kotlin/arrow/data/Moore.kt @@ -13,7 +13,7 @@ data class Moore(val view: V, val handle: (E) -> Moore) : MooreOf Date: Sat, 9 Mar 2019 12:29:32 +0100 Subject: [PATCH 4/4] Fix import --- .../integrations/retrofit/adapter/CallKindAdapterFactoryTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/integrations/arrow-integrations-retrofit-adapter/src/test/kotlin/arrow/integrations/retrofit/adapter/CallKindAdapterFactoryTest.kt b/modules/integrations/arrow-integrations-retrofit-adapter/src/test/kotlin/arrow/integrations/retrofit/adapter/CallKindAdapterFactoryTest.kt index 6eb3465486f..2c1765b04d0 100644 --- a/modules/integrations/arrow-integrations-retrofit-adapter/src/test/kotlin/arrow/integrations/retrofit/adapter/CallKindAdapterFactoryTest.kt +++ b/modules/integrations/arrow-integrations-retrofit-adapter/src/test/kotlin/arrow/integrations/retrofit/adapter/CallKindAdapterFactoryTest.kt @@ -3,7 +3,7 @@ package arrow.integrations.retrofit.adapter import arrow.effects.IO import arrow.integrations.retrofit.adapter.retrofit.retrofit import arrow.test.UnitSpec -import com.google.common.reflect.TypeToken +import com.google.gson.reflect.TypeToken import io.kotlintest.runner.junit4.KotlinTestRunner import io.kotlintest.shouldBe import io.kotlintest.shouldThrow