Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook Eq up to scalactic/scalatest's equality #522

Merged
merged 4 commits into from
Sep 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions free/src/test/scala/cats/free/CoyonedaTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ class CoyonedaTests extends CatsSuite {
})

test("transform and run is same as applying natural trans") {
assert {
val nt =
new NaturalTransformation[Option, List] {
def apply[A](fa: Option[A]): List[A] = fa.toList
}
val o = Option("hello")
val c = Coyoneda.lift(o)
c.transform(nt).run === nt(o)
}
c.transform(nt).run should === (nt(o))
}
}
10 changes: 5 additions & 5 deletions state/src/test/scala/cats/state/StateTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ class StateTTests extends CatsSuite {
import StateTTests._

test("basic state usage"){
assert(add1.run(1).run == (2 -> 1))
add1.run(1).run should === (2 -> 1)
}

test("traversing state is stack-safe"){
val ns = (0 to 100000).toList
val x = ns.traverseU(_ => add1)
assert(x.runS(0).run == 100001)
x.runS(0).run should === (100001)
}

test("State.pure and StateT.pure are consistent")(check {
forAll { (s: String, i: Int) =>
val state: State[String, Int] = State.pure(i)
val stateT: State[String, Int] = StateT.pure(i)
state.run(s).run == stateT.run(s).run
state.run(s).run === stateT.run(s).run
}
})

test("Apply syntax is usable on State") {
val x = add1 *> add1
assert(x.runS(0).run == 2)
x.runS(0).run should === (2)
}

test("Singleton and instance inspect are consistent")(check {
forAll { (s: String, i: Int) =>
State.inspect[Int, String](_.toString).run(i).run ==
State.inspect[Int, String](_.toString).run(i).run ===
State.pure[Int, Unit](()).inspect(_.toString).run(i).run
}
})
Expand Down
29 changes: 29 additions & 0 deletions tests/src/test/scala/cats/tests/CatsEquality.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cats
package tests

import org.scalactic._
import TripleEqualsSupport.AToBEquivalenceConstraint
import TripleEqualsSupport.BToAEquivalenceConstraint

// The code in this file was taken and only slightly modified from
// https://github.com/bvenners/equality-integration-demo
// Thanks for the great examples, Bill!

final class CatsEquivalence[T](T: Eq[T]) extends Equivalence[T] {
def areEquivalent(a: T, b: T): Boolean = T.eqv(a, b)
}

trait LowPriorityStrictCatsConstraints extends TripleEquals {
implicit def lowPriorityCatsCanEqual[A, B](implicit B: Eq[B], ev: A <:< B): CanEqual[A, B] =
new AToBEquivalenceConstraint[A, B](new CatsEquivalence(B), ev)
}

trait StrictCatsEquality extends LowPriorityStrictCatsConstraints {
override def convertToEqualizer[T](left: T): Equalizer[T] = super.convertToEqualizer[T](left)
implicit override def convertToCheckingEqualizer[T](left: T): CheckingEqualizer[T] = new CheckingEqualizer(left)
override def unconstrainedEquality[A, B](implicit equalityOfA: Equality[A]): CanEqual[A, B] = super.unconstrainedEquality[A, B]
implicit def catsCanEqual[A, B](implicit A: Eq[A], ev: B <:< A): CanEqual[A, B] =
new BToAEquivalenceConstraint[A, B](new CatsEquivalence(A), ev)
}

object StrictCatsEquality extends StrictCatsEquality
9 changes: 5 additions & 4 deletions tests/src/test/scala/cats/tests/CatsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tests
import bricks.Platform

import cats.std.AllInstances
import cats.syntax.AllSyntax
import cats.syntax.{AllSyntax, EqOps}

import org.scalactic.anyvals.{PosZDouble, PosInt}
import org.scalatest.{FunSuite, PropSpec, Matchers}
Expand Down Expand Up @@ -32,12 +32,13 @@ trait TestSettings extends Configuration with Matchers {
* An opinionated stack of traits to improve consistency and reduce
* boilerplate in Cats tests.
*/
trait CatsSuite extends FunSuite with Discipline with TestSettings with AllInstances with AllSyntax with TestInstances {
trait CatsSuite extends FunSuite with Matchers with Discipline with TestSettings with AllInstances with AllSyntax with TestInstances with StrictCatsEquality {
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
checkConfiguration

// disable scalatest's ===
override def convertToEqualizer[T](left: T): Equalizer[T] = ???
// disable Eq syntax (by making `eqSyntax` not implicit), since it collides
// with scalactic's equality
override def eqSyntax[A: Eq](a: A): EqOps[A] = new EqOps[A](a)
}

trait CatsProps extends PropSpec with PropertyChecks with TestSettings with TestInstances {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/EvalTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class EvalTests extends CatsSuite {
val (spooky, lz) = init(value)
(0 until n).foreach { _ =>
val result = lz.value
assert(result === value)
result should === (value)
spin ^= result.##
}
assert(spooky.counter == numEvals)
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/StreamingTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ class SpecificStreamingTTests extends CatsSuite {

val x = fa.flatMap(f).flatMap(g)
val y = fa.flatMap(a => f(a).flatMap(g))
assert(x === y)
x should === (y)
}
}
4 changes: 3 additions & 1 deletion tests/src/test/scala/cats/tests/SyntaxTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cats
package tests

import cats.std.AllInstances
import cats.syntax.AllSyntax
import algebra.laws.GroupLaws
import cats.functor.{Invariant, Contravariant}
import cats.laws.discipline.SerializableTests
Expand All @@ -27,7 +29,7 @@ import scala.reflect.runtime.universe.TypeTag
*
* None of these tests should ever run, or do any runtime checks.
*/
class SyntaxTests extends CatsSuite with PropertyChecks {
class SyntaxTests extends AllInstances with AllSyntax {

// pretend we have a value of type A
def mock[A]: A = ???
Expand Down