aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala
diff options
context:
space:
mode:
authorMarvin Bertin <marvin.bertin@gmail.com>2017-10-03 13:08:00 -0700
committerMarvin Bertin <marvin.bertin@gmail.com>2017-10-03 13:08:00 -0700
commit0653b90dddc294fddb0e81059aef00b202113d78 (patch)
tree3d8abb424b0f0495f1cbb18849184dd20d6897fc /src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala
parent5750f2f3633e75f2f96d6a36264ab4b8f3fec7d2 (diff)
parenta321a978353439fc516b0f2016c28fb32ba1b7ae (diff)
downloadrest-query-0653b90dddc294fddb0e81059aef00b202113d78.tar.gz
rest-query-0653b90dddc294fddb0e81059aef00b202113d78.tar.bz2
rest-query-0653b90dddc294fddb0e81059aef00b202113d78.zip
Merge branch 'master' into add-slot-eligibility-arms
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala')
-rw-r--r--src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala
index b259b07..7318ff6 100644
--- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala
+++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/common.scala
@@ -2,26 +2,28 @@ package xyz.driver.pdsuidomain.fakes.entities
import java.time.{LocalDate, LocalDateTime, LocalTime}
-import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
+import xyz.driver.core.generators.{nextDouble, nextOption}
+import xyz.driver.pdsuicommon.domain.{FuzzyValue, LongId, StringId, UuidId}
import xyz.driver.pdsuidomain.entities.{Trial, TrialHistory}
+
import scala.util.Random
object common {
import xyz.driver.core.generators
- def nextUuidId[T] = UuidId[T](generators.nextUuid())
+ def nextUuidId[T]: UuidId[T] = UuidId[T](generators.nextUuid())
- def nextLongId[T] = LongId[T](generators.nextInt(Int.MaxValue).toLong)
+ def nextLongId[T]: LongId[T] = LongId[T](generators.nextInt(Int.MaxValue).toLong)
- def nextStringId[T] = StringId[T](generators.nextString(maxLength = 20))
+ def nextStringId[T]: StringId[T] = StringId[T](generators.nextString(maxLength = 20))
- def nextTrialStatus = generators.oneOf[Trial.Status](Trial.Status.All)
+ def nextTrialStatus: Trial.Status = generators.oneOf[Trial.Status](Trial.Status.All)
- def nextPreviousTrialStatus = generators.oneOf[Trial.Status](Trial.Status.AllPrevious)
+ def nextPreviousTrialStatus: Trial.Status = generators.oneOf[Trial.Status](Trial.Status.AllPrevious)
- def nextLocalDateTime = LocalDateTime.of(nextLocalDate, LocalTime.MIDNIGHT)
+ def nextLocalDateTime: LocalDateTime = LocalDateTime.of(nextLocalDate, LocalTime.MIDNIGHT)
- def nextLocalDate = LocalDate.of(
+ def nextLocalDate: LocalDate = LocalDate.of(
1970 + Random.nextInt(68),
1 + Random.nextInt(12),
1 + Random.nextInt(28) // all months have at least 28 days
@@ -33,4 +35,27 @@ object common {
def nextTrialState = generators.oneOf[TrialHistory.State](TrialHistory.State.All)
+ 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 =>
+ val range = genBoundedRange(left, to)
+ range._1 -> nextOption(range._2)
+ }
+
+ ranges.map(_._1) -> ranges.flatMap(_._2)
+ }
+
+ def nextFuzzyValue(): FuzzyValue =
+ generators.oneOf[FuzzyValue](FuzzyValue.All)
+
+ def nextStartAndEndPages: (Option[Double], Option[Double]) =
+ genBoundedRangeOption[Double](nextDouble(), nextDouble())
+
}