diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala new file mode 100644 index 0000000..d09e09b --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala @@ -0,0 +1,35 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators._ + +object Common { + def genBoundedRange[T](from: T, + to: T) + (implicit ord: Ordering[T]): (T, T) = { + if (ord.compare(from, to) > 0) { + to -> from + } + else { + from -> to + } + } + + def genBoundedRangeOption[T](from: T, + to: T) + (implicit ord: Ordering[T]): (Option[T], Option[T]) = { + val ranges = nextOption(from) + .map(left => + genBoundedRange(left, to) + ) + .map { case (left, right) => + left -> nextOption(right) + } + + ranges.map(_._1) -> ranges.flatMap(_._2) + } + + def genStartAndEndPages: (Option[Double], Option[Double]) = { + genBoundedRangeOption[Double](nextDouble(), nextDouble()) + } + +} |