aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala
diff options
context:
space:
mode:
authorVlad Uspensky <v.uspenskiy@icloud.com>2017-09-29 12:42:35 -0700
committerGitHub <noreply@github.com>2017-09-29 12:42:35 -0700
commit46b354b6a49c0843fefc5794f2351f52b98102bd (patch)
tree20e9a10e87f0859c5c0342f3eee45d04aa214c64 /src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/Common.scala
parentdeba20326e3269fee3ef51f8e6841f17453b4155 (diff)
parent642f98c2ddd8af6c83d3de5a51c643ba93b23f96 (diff)
downloadrest-query-46b354b6a49c0843fefc5794f2351f52b98102bd.tar.gz
rest-query-46b354b6a49c0843fefc5794f2351f52b98102bd.tar.bz2
rest-query-46b354b6a49c0843fefc5794f2351f52b98102bd.zip
Merge pull request #32 from drivergroup/PDSUI-rep-fixtures
Implemented generators of entities for ReP; Implemented json objects for swagger model
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.scala35
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..9618eed
--- /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
+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())
+ }
+
+}