28 lines
837 B
Scala
28 lines
837 B
Scala
package green.thisfieldwas.embracingnondeterminism.stdlib
|
|
|
|
import org.scalatest.matchers.must.Matchers
|
|
import org.scalatest.propspec.AnyPropSpec
|
|
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
|
|
import org.scalacheck.Arbitrary.arbitrary
|
|
|
|
/** Proves that Scala's List is a functor by definition.
|
|
*/
|
|
class ListSpec extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers {
|
|
|
|
property("List.map() preserves identity functions") {
|
|
forAll(arbitrary[List[Int]]) { fa =>
|
|
fa.map(identity) mustBe identity(fa)
|
|
}
|
|
}
|
|
|
|
property("List.map() preserves function composition") {
|
|
forAll(for {
|
|
fa <- arbitrary[List[Double]]
|
|
f <- arbitrary[Double => String]
|
|
g <- arbitrary[String => Int]
|
|
} yield (fa, f, g)) { case (fa, f, g) =>
|
|
fa.map(g compose f) mustBe fa.map(f).map(g)
|
|
}
|
|
}
|
|
}
|