-
-
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 #751 from milessabin/master
SemigroupK consistency and fix; added compose tests.
- Loading branch information
Showing
2 changed files
with
60 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.data.{ NonEmptyList, NonEmptyVector, OneAnd } | ||
import cats.laws.discipline.{ ApplicativeTests, FoldableTests, MonoidalTests, SemigroupKTests, arbitrary, eq }, arbitrary._, eq._ | ||
import org.scalacheck.Arbitrary | ||
|
||
class ComposeTests extends CatsSuite { | ||
// we have a lot of generated lists of lists in these tests. We have to tell | ||
// Scalacheck to calm down a bit so we don't hit memory and test duration | ||
// issues. | ||
implicit override val generatorDrivenConfig: PropertyCheckConfiguration = | ||
PropertyCheckConfig(maxSize = 5, minSuccessful = 20) | ||
|
||
{ | ||
// Applicative composition | ||
|
||
implicit val applicativeListVector: Applicative[Lambda[A => List[Vector[A]]]] = Applicative[List] compose Applicative[Vector] | ||
implicit val iso = MonoidalTests.Isomorphisms.invariant[Lambda[A => List[Vector[A]]]] | ||
|
||
checkAll("Applicative[Lambda[A => List[Vector[A]]]]", ApplicativeTests[Lambda[A => List[Vector[A]]]].applicative[Int, Int, Int]) | ||
} | ||
|
||
{ | ||
// Foldable composition | ||
|
||
implicit val foldableListVector: Foldable[Lambda[A => List[Vector[A]]]] = Foldable[List] compose Foldable[Vector] | ||
|
||
checkAll("Foldable[Lambda[A => List[Vector[A]]]]", FoldableTests[Lambda[A => List[Vector[A]]]].foldable[Int, Int]) | ||
} | ||
|
||
{ | ||
// Reducible composition | ||
|
||
val nelReducible = | ||
new NonEmptyReducible[NonEmptyList, List] { | ||
def split[A](fa: NonEmptyList[A]): (A, List[A]) = (fa.head, fa.tail) | ||
} | ||
|
||
val nevReducible = | ||
new NonEmptyReducible[NonEmptyVector, Vector] { | ||
def split[A](fa: NonEmptyVector[A]): (A, Vector[A]) = (fa.head, fa.tail) | ||
} | ||
|
||
implicit val reducibleListVector: Reducible[Lambda[A => NonEmptyList[NonEmptyVector[A]]]] = nelReducible compose nevReducible | ||
|
||
// No Reducible-specific laws, so check the Foldable laws are satisfied | ||
checkAll("Reducible[Lambda[A => List[Vector[A]]]]", FoldableTests[Lambda[A => NonEmptyList[NonEmptyVector[A]]]].foldable[Int, Int]) | ||
} | ||
|
||
{ | ||
// SemigroupK composition | ||
|
||
implicit val semigroupKListVector: SemigroupK[Lambda[A => List[Vector[A]]]] = SemigroupK[List] compose SemigroupK[Vector] | ||
|
||
checkAll("SemigroupK[Lambda[A => List[Vector[A]]]]", SemigroupKTests[Lambda[A => List[Vector[A]]]].semigroupK[Int]) | ||
} | ||
} |