Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a couple tests and prefer underlying for consistency #689

Merged
merged 1 commit into from Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -38,13 +38,13 @@ class BiggerDecimalSuite extends FlatSpec with GeneratorDrivenPropertyChecks {
}

"signum" should "agree with BigInteger" in forAll { (value: BigInt) =>
val d = BiggerDecimal.fromBigInteger(value.bigInteger)
val d = BiggerDecimal.fromBigInteger(value.underlying)

assert(d.signum == value.signum)
}

it should "agree with BigDecimal" in forAll { (value: SBigDecimal) =>
val d = BiggerDecimal.fromBigDecimal(value.bigDecimal)
val d = BiggerDecimal.fromBigDecimal(value.underlying)

assert(d.signum == value.signum)
}
Expand Down Expand Up @@ -166,10 +166,17 @@ class BiggerDecimalSuite extends FlatSpec with GeneratorDrivenPropertyChecks {
whenever (!isBadJsBigDecimal(value)) {
val expected = BiggerDecimal.parseBiggerDecimalUnsafe(value.toString)

assert(BiggerDecimal.fromBigDecimal(value.bigDecimal) === expected)
assert(BiggerDecimal.fromBigDecimal(value.underlying) === expected)
}
}

it should "agree with parseBiggerDecimalUnsafe on 0.000" in {
val value = "0.000"
val expected = BiggerDecimal.parseBiggerDecimalUnsafe(value)

assert(BiggerDecimal.fromBigDecimal(new BigDecimal(value)) === expected)
}

it should "agree with parseBiggerDecimalUnsafe on multiples of ten with trailing zeros" in {
val bigDecimal = new BigDecimal("10.0")
val fromBigDecimal = BiggerDecimal.fromBigDecimal(bigDecimal)
Expand Down Expand Up @@ -232,6 +239,10 @@ class BiggerDecimalSuite extends FlatSpec with GeneratorDrivenPropertyChecks {
assert(BiggerDecimal.parseBiggerDecimal(jns.value).nonEmpty)
}

it should "parse integral JSON numbers" in forAll { (is: IntegralString) =>
assert(BiggerDecimal.parseBiggerDecimal(is.value) === Some(BiggerDecimal.fromBigInteger(new BigInteger(is.value))))
}

it should "fail on bad input" in {
val badNumbers = List("", "x", "01", "1x", "1ex", "1.0x", "1.x", "1e-x", "1e-0x", "1.", "1e", "1e-")

Expand Down
Expand Up @@ -29,8 +29,8 @@ trait ArbitraryInstances extends ArbitraryJsonNumberTransformer with CogenInstan
Arbitrary.arbitrary[JsonNumberString].map(s => BiggerDecimal.parseBiggerDecimalUnsafe(s.value)),
Arbitrary.arbitrary[Long].map(BiggerDecimal.fromLong),
Arbitrary.arbitrary[Double].map(BiggerDecimal.fromDoubleUnsafe),
Arbitrary.arbitrary[BigInt].map(_.bigInteger).map(BiggerDecimal.fromBigInteger),
Arbitrary.arbitrary[BigDecimal].map(_.bigDecimal).map(BiggerDecimal.fromBigDecimal),
Arbitrary.arbitrary[BigInt].map(_.underlying).map(BiggerDecimal.fromBigInteger),
Arbitrary.arbitrary[BigDecimal].map(_.underlying).map(BiggerDecimal.fromBigDecimal),
Gen.const(BiggerDecimal.NegativeZero)
)
)
Expand Down