-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #58 - Add more WriterT instances
- Loading branch information
Showing
8 changed files
with
210 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package just.fp | ||
|
||
import hedgehog._ | ||
import hedgehog.runner._ | ||
|
||
/** | ||
* @author Kevin Lee | ||
* @since 2019-09-19 | ||
*/ | ||
object WriterTSpec extends Properties { | ||
|
||
override def tests: List[Test] = List( | ||
property("testWriterTFunctorLaws", WriterTFunctorLaws.laws) | ||
, property("testWriterTApplicativeLaws", WriterTApplicativeLaws.laws) | ||
, property("testWriterTMonadLaws", WriterTMonadLaws.laws) | ||
, property("testWriterFunctorLaws", WriterFunctorLaws.laws) | ||
, property("testWriterApplicativeLaws", WriterApplicativeLaws.laws) | ||
, property("testWriterMonadLaws", WriterMonadLaws.laws) | ||
) | ||
|
||
object WriterTFunctorLaws { | ||
type WriterTOption[A] = WriterT[Option, String, A] | ||
|
||
def genWriterT: Gen[WriterTOption[Int]] = Gens.genWriterT(Gens.genUnicodeString, Gens.genIntFromMinToMax) | ||
|
||
def laws: Property = | ||
Specs.functorLaws.laws[WriterTOption]( | ||
genWriterT | ||
, Gens.genIntToInt | ||
) | ||
} | ||
|
||
object WriterTApplicativeLaws { | ||
type WriterTOption[A] = WriterT[Option, String, A] | ||
|
||
def genWriterT: Gen[WriterTOption[Int]] = Gens.genWriterT(Gens.genUnicodeString, Gens.genIntFromMinToMax) | ||
|
||
def laws: Property = | ||
Specs.applicativeLaws.laws[WriterTOption]( | ||
genWriterT | ||
, Gens.genIntFromMinToMax | ||
, Gens.genIntToInt | ||
) | ||
} | ||
|
||
object WriterTMonadLaws { | ||
type WriterTOption[A] = WriterT[Option, String, A] | ||
|
||
def genWriterT: Gen[WriterTOption[Int]] = Gens.genWriterT(Gens.genUnicodeString, Gens.genIntFromMinToMax) | ||
|
||
def laws: Property = | ||
Specs.monadLaws.laws[WriterTOption]( | ||
genWriterT | ||
, Gens.genIntFromMinToMax | ||
, Gens.genIntToInt | ||
, Gens.genAToMonadA(Gens.genIntToInt) | ||
) | ||
} | ||
|
||
import just.fp.testing.EqualUtil.TupleEqualInstance._ | ||
|
||
object WriterFunctorLaws { | ||
type WriterString[A] = Writer[String, A] | ||
|
||
def genWriter: Gen[WriterString[Int]] = Gens.genWriterT(Gens.genUnicodeString, Gens.genIntFromMinToMax) | ||
|
||
def laws: Property = | ||
Specs.functorLaws.laws[WriterString]( | ||
genWriter | ||
, Gens.genIntToInt | ||
) | ||
} | ||
|
||
object WriterApplicativeLaws { | ||
type WriterString[A] = Writer[String, A] | ||
|
||
def genWriter: Gen[WriterString[Int]] = Gens.genWriterT(Gens.genUnicodeString, Gens.genIntFromMinToMax) | ||
|
||
def laws: Property = | ||
Specs.applicativeLaws.laws[WriterString]( | ||
genWriter | ||
, Gens.genIntFromMinToMax | ||
, Gens.genIntToInt | ||
) | ||
} | ||
|
||
object WriterMonadLaws { | ||
|
||
type WriterString[A] = Writer[String, A] | ||
|
||
def genWriter: Gen[WriterString[Int]] = Gens.genWriterT(Gens.genUnicodeString, Gens.genIntFromMinToMax) | ||
|
||
def laws: Property = | ||
Specs.monadLaws.laws[WriterString]( | ||
genWriter | ||
, Gens.genIntFromMinToMax | ||
, Gens.genIntToInt | ||
, Gens.genAToMonadA(Gens.genIntToInt) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package just.fp.testing | ||
|
||
import just.fp.Equal | ||
|
||
/** | ||
* @author Kevin Lee | ||
* @since 2019-09-19 | ||
*/ | ||
object EqualUtil { | ||
|
||
object FutureEqualInstance { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.duration._ | ||
import scala.concurrent.{Await, Future} | ||
|
||
implicit def futureEqual[A](implicit EQ: Equal[A]): Equal[Future[A]] = new Equal[Future[A]] { | ||
override def equal(x: Future[A], y: Future[A]): Boolean = | ||
Await.result(x.flatMap(a => y.map(b => EQ.equal(a, b))), 1.second) | ||
} | ||
} | ||
|
||
object TupleEqualInstance { | ||
|
||
import just.fp.JustSyntax._ | ||
|
||
implicit def tupleEq[A: Equal, B: Equal]: Equal[(A, B)] = new Equal[(A, B)] { | ||
override def equal(x: (A, B), y: (A, B)): Boolean = | ||
x._1 === y._1 && x._2 === y._2 | ||
} | ||
|
||
} | ||
} |