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

Improving test coverage #962

Merged
merged 1 commit into from
Mar 29, 2016
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
7 changes: 7 additions & 0 deletions jvm/src/test/scala/cats/tests/FutureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package tests

import cats.data.Xor
import cats.laws.discipline._
import cats.laws.discipline.arbitrary.evalArbitrary
import cats.laws.discipline.eq.tuple3Eq
import cats.jvm.std.future.futureComonad
import cats.tests.CatsSuite
Expand Down Expand Up @@ -40,4 +41,10 @@ class FutureTests extends CatsSuite {

checkAll("Future[Int]", MonadErrorTests[Future, Throwable].monadError[Int, Int, Int])
checkAll("Future[Int]", ComonadTests[Future].comonad[Int, Int, Int])

test("pureEval lifts a potentially lazy value into Future") {
forAll { e: Eval[Int] =>
e.pureEval[Future].extract should === (e.value)
}
}
}
22 changes: 22 additions & 0 deletions tests/src/test/scala/cats/tests/FunctorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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._
import cats.laws.discipline.eq.showEq

class FunctorTest extends CatsSuite {
Expand All @@ -15,9 +16,30 @@ class FunctorTest extends CatsSuite {
checkAll("Option compose Xor", FunctorTests(optionXorFunctor).functor[Int, Int, Int])
checkAll("Functor[Option compose Xor]", SerializableTests.serializable(optionXorFunctor))

val optionComposeWithFunctorXor: Functor[OptionXor] =
Functor[Option].composeWithFunctor[Xor[String, ?]]
checkAll("Option composeWithFunctor Xor", FunctorTests(optionComposeWithFunctorXor).functor[Int, Int, Int])
checkAll("Functor[Option composeWithFunctor Xor]", SerializableTests.serializable(optionComposeWithFunctorXor))

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))

test("void replaces values with unit preserving structure") {
forAll { (l: List[Int], o: Option[Int], m: Map[String, Int]) =>
l.void should === (List.fill(l.length)(()))
o.void should === (if (o.nonEmpty) Some(()) else None)
m.void should === (m.keys.map(k => (k, ())).toMap)
}
}

test("as replaces values with a constant value preserving structure") {
forAll { (l: List[Int], o: Option[Int], m: Map[String, Int], i: Int) =>
l.as(i) should === (List.fill(l.length)(i))
o.as(i) should === (if (o.nonEmpty) Some(i) else None)
m.as(i) should === (m.keys.map(k => (k, i)).toMap)
}
}
}