Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
modules/squants/src/test/scala/pureconfig/module/squants/arbitrary/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package pureconfig.module.squants | ||
|
||
import org.scalacheck.{ Arbitrary, Gen } | ||
import squants.market._ | ||
import squants.{ Dimension, Quantity } | ||
|
||
package object arbitrary { | ||
|
||
def quantityAbitrary[T <: Quantity[T]](dim: Dimension[T]): Arbitrary[T] = { | ||
Arbitrary( | ||
for { | ||
n <- Arbitrary.arbitrary[Double] | ||
u <- Gen.oneOf(dim.units.toList) | ||
} yield u(n)) | ||
} | ||
|
||
// Money.units is not implemented so we need an explicit Arbitrary | ||
implicit val moneyArbitrary: Arbitrary[Money] = { | ||
|
||
// BTC is not included: fails on input: 0E-15 | ||
val currencies = | ||
List(USD, ARS, AUD, BRL, CAD, CHF, CLP, CNY, CZK, DKK, EUR, GBP, | ||
HKD, INR, JPY, KRW, MXN, MYR, NOK, NZD, RUB, SEK, XAG, XAU) | ||
|
||
Arbitrary( | ||
for { | ||
n <- Arbitrary.arbitrary[Double] | ||
c <- Gen.oneOf(currencies) | ||
} yield Money(BigDecimal(n).setScale(c.formatDecimals, BigDecimal.RoundingMode.HALF_EVEN), c)) | ||
} | ||
} |