Skip to content

Commit

Permalink
rudimentary inheritance property added
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-may committed Apr 22, 2019
1 parent d0e6175 commit 5a00f16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/test/scala/util/Generators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions src/test/scala/zipper/BufferedZipperProperties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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") =
Expand Down

0 comments on commit 5a00f16

Please sign in to comment.