diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt index 3a0ebadb967..3e5212c7e58 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EitherTest.kt @@ -16,12 +16,10 @@ import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.boolean -import io.kotest.property.arbitrary.choice -import io.kotest.property.arbitrary.constant import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.long -import io.kotest.property.arbitrary.negativeInts import io.kotest.property.arbitrary.string +import io.kotest.property.arbitrary.nonPositiveInt class EitherTest : UnitSpec() { @@ -310,7 +308,7 @@ class EitherTest : UnitSpec() { "replicate should return Right(empty list) when n <= 0" { checkAll( - Arb.choice(Arb.negativeInts(), Arb.constant(0)), + Arb.nonPositiveInt(), Arb.int(0..100) ) { n: Int, a: Int -> val expected: Either> = Right(emptyList()) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EvalTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EvalTest.kt index 9bec9965fa8..fe4417e3b90 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EvalTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/EvalTest.kt @@ -1,16 +1,9 @@ package arrow.core -import arrow.core.computations.EvalEffect -import arrow.core.computations.RestrictedEvalEffect -import arrow.core.computations.eval import arrow.core.test.UnitSpec import arrow.core.test.concurrency.SideEffect -import arrow.core.test.laws.FxLaws import arrow.core.test.stackSafeIteration -import io.kotest.property.Arb import io.kotest.matchers.shouldBe -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.map class EvalTest : UnitSpec() { diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt index a705142bb63..3be29c3c0bf 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt @@ -165,7 +165,6 @@ class IterableTest : UnitSpec() { checkAll(Arb.list(Arb.int())) { ints -> val evens = ints.map { if (it % 2 == 0) it else null }.sequence() - val expected = ints.takeWhile { it % 2 == 0 } if (ints.any { it % 2 != 0 }) { evens.shouldBeNull() } else { diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt index 18b3333a4b1..d01efef505f 100755 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/OptionTest.kt @@ -64,8 +64,7 @@ class OptionTest : UnitSpec() { "short circuit null" { option { val number: Int = "s".length - val x = ensureNotNull(number.takeIf { it > 1 }) - x + ensureNotNull(number.takeIf { it > 1 }) throw IllegalStateException("This should not be executed") } shouldBe None } @@ -120,8 +119,8 @@ class OptionTest : UnitSpec() { } "map" { - some.map(String::toUpperCase) shouldBe Some("KOTLIN") - none.map(String::toUpperCase) shouldBe None + some.map(String::uppercase) shouldBe Some("KOTLIN") + none.map(String::uppercase) shouldBe None } "zip" { @@ -410,6 +409,10 @@ class OptionTest : UnitSpec() { Option.catch(recover) { 1 } shouldBe Some(1) } + "catch with default recover should return Some(result) when f does not throw" { + Option.catch { 1 } shouldBe Some(1) + } + "catch should return Some(recoverValue) when f throws" { val exception = Exception("Boom!") val recoverValue = 10 @@ -417,10 +420,6 @@ class OptionTest : UnitSpec() { Option.catch(recover) { throw exception } shouldBe Some(recoverValue) } - "catch should return Some(result) when f does not throw" { - Option.catch { 1 } shouldBe Some(1) - } - "catch should return None when f throws" { val exception = Exception("Boom!") Option.catch { throw exception } shouldBe None diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ValidatedTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ValidatedTest.kt index db8c178d79a..0dca116a255 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ValidatedTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/ValidatedTest.kt @@ -204,7 +204,7 @@ class ValidatedTest : UnitSpec() { ) { a, b -> a + b } }) else Invalid( - all.filterIsInstance>().map { it.value }.combineAll(nullableLongSemigroup) + all.filterIsInstance>().map { it.value }.fold(nullableLongSemigroup) ) res shouldBe expected @@ -458,15 +458,7 @@ class ValidatedTest : UnitSpec() { } } - "bitraverseNullable should wrap valid or invalid in a nullable" { - val valid = Valid("Who") - val invalid = Invalid("Nope") - - valid.bitraverseNullable({ it }, { it }) shouldBe Valid("Who") - invalid.bitraverseNullable({ it }, { it }) shouldBe Invalid("Nope") - } - - "bisequenceOption should yield consistent result with bitraverseOption" { + "bisequenceNullable should yield consistent result with bitraverseNullable" { checkAll(Arb.string().orNull(), Arb.string().orNull()) { a: String?, b: String? -> val valid: Validated = Valid(a) val invalid: Validated = Invalid(b) @@ -478,6 +470,14 @@ class ValidatedTest : UnitSpec() { } } + "bitraverseNullable should wrap valid or invalid in a nullable" { + val valid = Valid("Who") + val invalid = Invalid("Nope") + + valid.bitraverseNullable({ it }, { it }) shouldBe Valid("Who") + invalid.bitraverseNullable({ it }, { it }) shouldBe Invalid("Nope") + } + "bitraverseEither should wrap valid or invalid in an either" { val valid = Valid("Who") val invalid = Invalid("Nope") diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/OptionSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/OptionSpec.kt index 6408ebb784d..59d677ac9b7 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/OptionSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/continuations/OptionSpec.kt @@ -24,8 +24,7 @@ class OptionSpec : StringSpec({ "short circuit option" { option { val number: Int = "s".length - val x = ensureNotNull(number.takeIf { it > 1 }) - x + ensureNotNull(number.takeIf { it > 1 }) throw IllegalStateException("This should not be executed") } shouldBe None } @@ -44,8 +43,7 @@ class OptionSpec : StringSpec({ "eager short circuit null" { option.eager { val number: Int = "s".length - val x = ensureNotNull(number.takeIf { it > 1 }) - x + ensureNotNull(number.takeIf { it > 1 }) throw IllegalStateException("This should not be executed") } shouldBe None }