From 5a00f16a4b56cc94724c7a1033b8887206f4e3f4 Mon Sep 17 00:00:00 2001 From: Nathaniel May Date: Sun, 21 Apr 2019 21:05:26 -0400 Subject: [PATCH] rudimentary inheritance property added --- src/test/scala/util/Generators.scala | 16 ++++++++++++++-- .../scala/zipper/BufferedZipperProperties.scala | 11 ++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/test/scala/util/Generators.scala b/src/test/scala/util/Generators.scala index 8a8817d..0480e8c 100644 --- a/src/test/scala/util/Generators.scala +++ b/src/test/scala/util/Generators.scala @@ -6,8 +6,7 @@ import zipper.BufferedZipper // Scala import cats.Monad -import cats.data.OptionT -import cats.implicits.{toFunctorOps, toFlatMapOps} +//import cats.implicits.{toFunctorOps, toFlatMapOps} import scala.language.higherKinds // Project @@ -26,6 +25,19 @@ object Generators { val noLimitGen: Gen[Limit] = Gen.const(Unlimited) val noBuffer: Gen[SizeLimit] = Gen.const(SizeLimit(0)) + class Inheritance + class Subtype1 extends Inheritance + class Subtype2 extends Subtype1 + class SubtypeA extends Inheritance + class SubtypeB extends SubtypeA + + val inheritanceGen: Gen[Inheritance] = Gen.choose(0, 50).flatMap { n => + if (n < 10) Gen.const(new Inheritance) + else if (n < 20) Gen.const(new Subtype1) + else if (n < 30) Gen.const(new Subtype2) + else if (n < 40) Gen.const(new SubtypeA) + else Gen.const(new SubtypeB) } + /** * 10% Unlimited * 45% Size(size) diff --git a/src/test/scala/zipper/BufferedZipperProperties.scala b/src/test/scala/zipper/BufferedZipperProperties.scala index 6b3e9c2..e94b417 100644 --- a/src/test/scala/zipper/BufferedZipperProperties.scala +++ b/src/test/scala/zipper/BufferedZipperProperties.scala @@ -16,16 +16,21 @@ object BufferedZipperProperties extends Properties("BufferedZipper") { implicit val aPath: Arbitrary[Path] = Arbitrary(pathGen) implicit val aBufferSize: Arbitrary[Limit] = Arbitrary(limitGen) + implicit val anInheritance: Arbitrary[Inheritance] = Arbitrary(inheritanceGen) property("toStream is the same as the streamInput regardless of starting point and buffer size") = forAll { - (inStream: Stream[String], limits: Limit, path: Path) => - BufferedZipper[Id, String](inStream, limits) + (inStream: Stream[String], limits: Limit, path: Path) => BufferedZipper[Id, String](inStream, limits) .fold[Stream[String]](Stream()) { move[Id, String](path, _).toStream } == inStream } property("toStream is the same as the streamInput regardless of starting point and buffer size with monad transformers") = forAll { + (inStream: Stream[Inheritance], limits: Limit, path: Path) => BufferedZipper[Id, Inheritance](inStream, limits) + .fold[Stream[Inheritance]](Stream()) { moveT[Id, Inheritance](path, _).value.get.toStream } == inStream + } + + property("toStream is the same as the streamInput with subtypes regardless of starting point and buffer size") = forAll { (inStream: Stream[String], limits: Limit, path: Path) => BufferedZipper[Id, String](inStream, limits) - .fold[Stream[String]](Stream()) { moveT[Id, String](path, _).value.get.toStream } == inStream + .fold[Stream[String]](Stream()) { move[Id, String](path, _).toStream } == inStream } property("toStream uses buffer to minimize effectful calls") =