Permalink
Browse files

fix IsoExercises

  • Loading branch information...
AdrianRaFo committed Mar 27, 2017
1 parent fa82b39 commit 62c7f8618915d3cdc6b636844a453debc93efb2d
Showing with 22 additions and 9 deletions.
  1. +14 −8 src/main/scala/monocle/IsoExercises.scala
  2. +8 −1 src/test/scala/monocle/IsoSpec.scala
@@ -146,15 +146,21 @@ object IsoExercises extends FlatSpec with Matchers with Section {
*
* In particular, an Iso must verify that `get` and `reverseGet` are inverse. This is done via `roundTripOneWay` and `roundTripOtherWay` laws:
*
* {{{
* def roundTripOneWay[S, A](i: Iso[S, A], s: S): Boolean =
* i.reverseGet(i.get(s)) == s
*
* def roundTripOtherWay[S, A](i: Iso[S, A], a: A): Boolean =
* i.get(i.reverseGet(a)) == a
* }}}
*/
def conclusion(): Unit = ()
def exerciseLaws(res0 : Boolean, res1 : Boolean) =
{
personToTuple.get(Person("Zoe", 25))
def roundTripOneWay[S, A](i: Iso[Person, (String, Int)], s: Person): Boolean =
i.reverseGet(i.get(s)) == s
def roundTripOtherWay[S, A](i: Iso[Person, (String, Int)], a: (String,Int)): Boolean =
i.get(i.reverseGet(a)) == a
roundTripOneWay(personToTuple, Person("Zoey",25)) should be res0
roundTripOtherWay(personToTuple,("Zoe",52)) should be res1
}
}
@@ -63,5 +63,12 @@ class IsoSpec extends FunSuite with Checkers {
)
)
}
test("exercise laws") {
check(
Test.testSuccess(
IsoExercises.exerciseLaws _,
true :: true:: HNil
)
)
}
}

0 comments on commit 62c7f86

Please sign in to comment.