Skip to content

Commit afba8a6

Browse files
author
Ronald Holshausen
committedJan 25, 2020
fix: BigDecimal comparison should use scale and include BigDecimal.ZERO #1001
1 parent e70525b commit afba8a6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

‎core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/MatcherExecutor.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ fun matchDecimal(actual: Any?): Boolean {
239239
actual == 0 -> true
240240
actual is Float -> true
241241
actual is Double -> true
242-
actual is BigDecimal && actual.precision() > 0 -> true
242+
actual is BigDecimal && (actual == BigDecimal.ZERO || actual.scale() > 0) -> true
243243
actual is JsonPrimitive && actual.isNumber -> decimalRegex.matches(actual.toString())
244244
else -> false
245245
}
@@ -252,7 +252,7 @@ fun matchInteger(actual: Any?): Boolean {
252252
actual is Int -> true
253253
actual is Long -> true
254254
actual is BigInteger -> true
255-
actual is BigDecimal && actual.precision() == 0 -> true
255+
actual is BigDecimal && actual.scale() == 0 -> true
256256
actual is JsonPrimitive && actual.isNumber -> integerRegex.matches(actual.toString())
257257
else -> false
258258
}

‎core/matchers/src/test/groovy/au/com/dius/pact/core/matchers/MatcherExecutorSpec.groovy

+5-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ class MatcherExecutorSpec extends Specification {
212212
100 as int | true
213213
100 as long | true
214214
100 as BigInteger | true
215-
215+
100 as BigDecimal | true
216+
BigInteger.ZERO | true
217+
BigDecimal.ZERO | true
216218
}
217219

218220
@Unroll
@@ -232,7 +234,8 @@ class MatcherExecutorSpec extends Specification {
232234
100 as int | false
233235
100 as long | false
234236
100 as BigInteger | false
235-
237+
BigInteger.ZERO | false
238+
BigDecimal.ZERO | true
236239
}
237240

238241
}

0 commit comments

Comments
 (0)
Please sign in to comment.