-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #941 from adelbertc/moar-tests
Journey to >= 90% test coverage
- Loading branch information
Showing
8 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.data.Xor | ||
import cats.laws.discipline.{BifoldableTests, SerializableTests} | ||
import cats.laws.discipline.arbitrary._ | ||
|
||
class BifoldableTest extends CatsSuite { | ||
type EitherXor[A, B] = Either[Xor[A, B], Xor[A, B]] | ||
val eitherComposeXor: Bifoldable[EitherXor] = | ||
Bifoldable[Either].compose[Xor] | ||
|
||
checkAll("Either compose Xor", BifoldableTests(eitherComposeXor).bifoldable[Int, Int, Int]) | ||
checkAll("Bifoldable[Either compose Xor]", SerializableTests.serializable(eitherComposeXor)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.data.Xor | ||
import cats.laws.discipline.{BitraverseTests, SerializableTests} | ||
import cats.laws.discipline.arbitrary._ | ||
import cats.laws.discipline.eq.tuple2Eq | ||
|
||
class BitraverseTest extends CatsSuite { | ||
type XorTuple2[A, B] = Xor[(A, B), (A, B)] | ||
val xorComposeTuple2: Bitraverse[XorTuple2] = | ||
Bitraverse[Xor].compose[Tuple2] | ||
|
||
checkAll("Xor compose Tuple2", BitraverseTests(xorComposeTuple2).bitraverse[Option, Int, Int, Int, String, String, String]) | ||
checkAll("Bitraverse[Xor compose Tuple2]", SerializableTests.serializable(xorComposeTuple2)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cats | ||
package tests | ||
|
||
import algebra.laws.GroupLaws | ||
|
||
import cats.arrow.Category | ||
import cats.laws.discipline.{MonoidKTests, SerializableTests} | ||
import cats.laws.discipline.eq.function1Eq | ||
|
||
class CategoryTest extends CatsSuite { | ||
val functionCategory = Category[Function1] | ||
type Endo[A] = Function1[A, A] | ||
|
||
checkAll("Category[Function1].algebraK", MonoidKTests[Endo](functionCategory.algebraK).monoidK[Int]) | ||
checkAll("Category[Function1].algebraK", SerializableTests.serializable(functionCategory.algebraK)) | ||
|
||
val functionAlgebra = functionCategory.algebra[Int] | ||
checkAll("Category[Function1].algebra[Int]", GroupLaws[Endo[Int]].monoid(functionAlgebra)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cats | ||
package tests | ||
|
||
import algebra.laws.GroupLaws | ||
|
||
import cats.arrow.Compose | ||
import cats.laws.discipline.{SemigroupKTests, SerializableTests} | ||
import cats.laws.discipline.eq.function1Eq | ||
|
||
class ComposeTest extends CatsSuite { | ||
val functionCompose = Compose[Function1] | ||
type Endo[A] = Function1[A, A] | ||
|
||
checkAll("Compose[Function1].algebraK", SemigroupKTests[Endo](functionCompose.algebraK).semigroupK[Int]) | ||
checkAll("Compose[Function1].algebraK", SerializableTests.serializable(functionCompose.algebraK)) | ||
|
||
val functionAlgebra = functionCompose.algebra[Int] | ||
checkAll("Compose[Function1].algebra[Int]", GroupLaws[Endo[Int]].semigroup(functionAlgebra)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.data.Xor | ||
import cats.functor.Contravariant | ||
import cats.laws.discipline.{ContravariantTests, FunctorTests, SerializableTests} | ||
import cats.laws.discipline.arbitrary._ | ||
import cats.laws.discipline.eq.showEq | ||
|
||
class FunctorTest extends CatsSuite { | ||
type OptionXor[A] = Option[Xor[String, A]] | ||
|
||
val optionXorFunctor: Functor[OptionXor] = | ||
Functor[Option].compose[Xor[String, ?]] | ||
checkAll("Option compose Xor", FunctorTests(optionXorFunctor).functor[Int, Int, Int]) | ||
checkAll("Functor[Option compose Xor]", SerializableTests.serializable(optionXorFunctor)) | ||
|
||
type OptionShow[A] = Option[Show[A]] | ||
val optionShowContravariant: Contravariant[OptionShow] = | ||
Functor[Option].composeWithContravariant[Show] | ||
checkAll("Option composeWithContravariant Show", ContravariantTests(optionShowContravariant).contravariant[Int, Int, Int]) | ||
checkAll("Contravariant[Option composeWithContravariant Show]", SerializableTests.serializable(optionShowContravariant)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.data.State | ||
|
||
class MonadStateTest extends CatsSuite { | ||
val testInstance = MonadState[State[Int, ?], Int] | ||
|
||
test("MonadState#modify identity does not modify the state") { | ||
forAll { (i: Int) => | ||
val x = testInstance.modify(identity).runS(i).value | ||
x should === (i) | ||
} | ||
} | ||
|
||
test("MonadState#inspect identity does not modify the state") { | ||
forAll { (i: Int) => | ||
val x = testInstance.inspect(identity).runA(i).value | ||
x should === (i) | ||
} | ||
} | ||
} |