Skip to content

Commit

Permalink
Re-encode relationships to avoid implicit conversion functions (typel…
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown authored Feb 27, 2020
1 parent 2573961 commit f987903
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import cats.laws.discipline.{AlignTests, BimonadTests, NonEmptyTraverseTests, Se
import cats.laws.discipline.arbitrary._

class NonEmptyLazyListSuite extends NonEmptyCollectionSuite[LazyList, NonEmptyLazyList, NonEmptyLazyListOps] {
def toList[A](value: NonEmptyLazyList[A]): List[A] = value.toList
def underlyingToList[A](underlying: LazyList[A]): List[A] = underlying.toList
protected def toList[A](value: NonEmptyLazyList[A]): List[A] = value.toList
protected def underlyingToList[A](underlying: LazyList[A]): List[A] = underlying.toList
protected def toNonEmptyCollection[A](nea: NonEmptyLazyList[A]): NonEmptyLazyListOps[A] = nea

checkAll("NonEmptyLazyList[Int]", SemigroupTests[NonEmptyLazyList[Int]].semigroup)
checkAll(s"Semigroup[NonEmptyLazyList]", SerializableTests.serializable(Semigroup[NonEmptyLazyList[Int]]))
Expand Down
5 changes: 3 additions & 2 deletions tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import cats.laws.discipline.{AlignTests, BimonadTests, NonEmptyTraverseTests, Se
import cats.laws.discipline.arbitrary._

class NonEmptyChainSuite extends NonEmptyCollectionSuite[Chain, NonEmptyChain, NonEmptyChainOps] {
def toList[A](value: NonEmptyChain[A]): List[A] = value.toChain.toList
def underlyingToList[A](underlying: Chain[A]): List[A] = underlying.toList
protected def toList[A](value: NonEmptyChain[A]): List[A] = value.toChain.toList
protected def underlyingToList[A](underlying: Chain[A]): List[A] = underlying.toList
protected def toNonEmptyCollection[A](nea: NonEmptyChain[A]): NonEmptyChainOps[A] = nea

checkAll("NonEmptyChain[Int]", SemigroupKTests[NonEmptyChain].semigroupK[Int])
checkAll("SemigroupK[NonEmptyChain]", SerializableTests.serializable(SemigroupK[NonEmptyChain]))
Expand Down
12 changes: 7 additions & 5 deletions tests/src/test/scala/cats/tests/NonEmptyCollectionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import org.scalacheck.Arbitrary

abstract class NonEmptyCollectionSuite[U[+_], NE[+_], NEC[x] <: NonEmptyCollection[x, U, NE]](
implicit arbitraryU: Arbitrary[U[Int]],
arbitraryNE: Arbitrary[NE[Int]],
ev: NE[Int] => NEC[Int],
evPair: NE[(Int, Int)] => NEC[(Int, Int)]
arbitraryNE: Arbitrary[NE[Int]]
) extends CatsSuite {
def toList[A](value: NE[A]): List[A]
def underlyingToList[A](underlying: U[A]): List[A]
protected def toList[A](value: NE[A]): List[A]
protected def underlyingToList[A](underlying: U[A]): List[A]

// Necessary because of the non-inheritance-based encoding of some non-empty collections.
protected def toNonEmptyCollection[A](nea: NE[A]): NEC[A]
implicit private def convertToNonEmptyCollection[A](nea: NE[A]): NEC[A] = toNonEmptyCollection(nea)

test("head is consistent with iterator.toList.head") {
forAll { (is: NE[Int]) =>
Expand Down
5 changes: 3 additions & 2 deletions tests/src/test/scala/cats/tests/NonEmptyListSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import scala.collection.immutable.SortedMap
import scala.collection.immutable.SortedSet

class NonEmptyListSuite extends NonEmptyCollectionSuite[List, NonEmptyList, NonEmptyList] {
def toList[A](value: NonEmptyList[A]): List[A] = value.toList
def underlyingToList[A](underlying: List[A]): List[A] = underlying
protected def toList[A](value: NonEmptyList[A]): List[A] = value.toList
protected def underlyingToList[A](underlying: List[A]): List[A] = underlying
protected def toNonEmptyCollection[A](nea: NonEmptyList[A]): NonEmptyList[A] = nea

// Lots of collections here.. telling ScalaCheck to calm down a bit
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
Expand Down
5 changes: 3 additions & 2 deletions tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import cats.platform.Platform
import scala.util.Properties

class NonEmptyVectorSuite extends NonEmptyCollectionSuite[Vector, NonEmptyVector, NonEmptyVector] {
def toList[A](value: NonEmptyVector[A]): List[A] = value.toList
def underlyingToList[A](underlying: Vector[A]): List[A] = underlying.toList
protected def toList[A](value: NonEmptyVector[A]): List[A] = value.toList
protected def underlyingToList[A](underlying: Vector[A]): List[A] = underlying.toList
protected def toNonEmptyCollection[A](nea: NonEmptyVector[A]): NonEmptyVector[A] = nea

// Lots of collections here.. telling ScalaCheck to calm down a bit
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
Expand Down

0 comments on commit f987903

Please sign in to comment.