Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved Chunk generators to standalone trait and increased coverage of …
…constructors
- Loading branch information
Showing
2 changed files
with
34 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package fs2 | ||
|
||
import cats.data.Chain | ||
import cats.laws.discipline.arbitrary._ | ||
import org.scalacheck._ | ||
import Arbitrary.arbitrary | ||
import scala.reflect.ClassTag | ||
|
||
trait ChunkGen { | ||
|
||
implicit def arbChunk[A: ClassTag](implicit A: Arbitrary[A]): Arbitrary[Chunk[A]] = Arbitrary( | ||
Gen.frequency( | ||
1 -> Chunk.empty[A], | ||
5 -> A.arbitrary.map(a => Chunk.singleton(a)), | ||
10 -> Gen.listOf(A.arbitrary).map(as => Chunk.vector(as.toVector)), | ||
10 -> Gen.listOf(A.arbitrary).map(as => Chunk.indexedSeq(as.toIndexedSeq)), | ||
10 -> Gen.listOf(A.arbitrary).map(Chunk.seq), | ||
10 -> arbitrary[Chain[A]].map(Chunk.chain), | ||
10 -> Gen.listOf(A.arbitrary).map(as => Chunk.buffer(collection.mutable.Buffer.empty[A] ++ as)), | ||
10 -> Gen.listOf(A.arbitrary).map(as => Chunk.array(as.toArray)), | ||
10 -> (for { | ||
as <- Gen.listOf(A.arbitrary) | ||
offset <- Gen.chooseNum(0, as.size / 2) | ||
len <- Gen.chooseNum(0, as.size - offset) | ||
} yield Chunk.boxed(as.toArray, offset, len)) | ||
) | ||
) | ||
|
||
implicit def cogenChunk[A: Cogen]: Cogen[Chunk[A]] = | ||
Cogen[List[A]].contramap(_.toList) | ||
} | ||
|
||
object ChunkGen extends ChunkGen |
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