diff options
author | Aleksandr <ognelisar@gmail.com> | 2017-09-28 13:31:21 +0700 |
---|---|---|
committer | Aleksandr <ognelisar@gmail.com> | 2017-09-28 13:31:21 +0700 |
commit | d8e71e0a9ee7db58032384d059403bc227a35138 (patch) | |
tree | 4803503379c4e71f2e6ed1c8c50a8914186a5798 /src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala | |
parent | c24679f1ae7d7ccc4e6693535b0aa3ac0e1ca225 (diff) | |
download | rest-query-d8e71e0a9ee7db58032384d059403bc227a35138.tar.gz rest-query-d8e71e0a9ee7db58032384d059403bc227a35138.tar.bz2 rest-query-d8e71e0a9ee7db58032384d059403bc227a35138.zip |
Implemented some REP entities objects generators
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()) + } + +} |