aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala
blob: 9618eedfb602325eab0d006640af1803e3550ee3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package xyz.driver.pdsuidomain.fakes.entities.rep

import xyz.driver.core.generators
import xyz.driver.core.generators._
import xyz.driver.pdsuicommon.domain.FuzzyValue

private[rep] 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 nextFuzzyValue(): FuzzyValue = {
    generators.oneOf[FuzzyValue](FuzzyValue.All)
  }

  def nextStartAndEndPages: (Option[Double], Option[Double]) = {
    genBoundedRangeOption[Double](nextDouble(), nextDouble())
  }

}