Skip to content

Commit

Permalink
#624 BigDecimal expectations samples for api-fluent (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacosta authored Sep 24, 2021
1 parent 23849af commit 4e993d5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ fun <T : BigDecimal> Expect<T?>.toEqual(expected: Nothing?): Expect<T?> =
* ```
* However, if you expect it to be wrong (because `BigDecimal.scale` differ), then use [notToEqualIncludingScale].
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.BigDecimalExpectationSamples.notToEqual
*
* @since 0.17.0
*/
@Deprecated(
Expand Down Expand Up @@ -113,6 +115,8 @@ fun <T : BigDecimal> Expect<T>.notToEqual(expected: T): Nothing =
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.BigDecimalExpectationSamples.toEqualNumerically
*
* @since 0.17.0
*/
fun <T : BigDecimal> Expect<T>.toEqualNumerically(expected: T): Expect<T> =
Expand All @@ -132,6 +136,8 @@ fun <T : BigDecimal> Expect<T>.toEqualNumerically(expected: T): Expect<T> =
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.BigDecimalExpectationSamples.notToEqualNumerically
*
* @since 0.17.0
*/
fun <T : BigDecimal> Expect<T>.notToEqualNumerically(expected: T): Expect<T> =
Expand All @@ -148,6 +154,8 @@ fun <T : BigDecimal> Expect<T>.notToEqualNumerically(expected: T): Expect<T> =
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.BigDecimalExpectationSamples.toEqualIncludingScale
*
* @since 0.17.0
*/
fun <T : BigDecimal> Expect<T>.toEqualIncludingScale(expected: T): Expect<T> =
Expand All @@ -164,6 +172,8 @@ fun <T : BigDecimal> Expect<T>.toEqualIncludingScale(expected: T): Expect<T> =
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.BigDecimalExpectationSamples.notToEqualIncludingScale
*
* @since 0.17.0
*/
fun <T : BigDecimal> Expect<T>.notToEqualIncludingScale(expected: T): Expect<T> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ch.tutteli.atrium.api.fluent.en_GB.samples

import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.fluent.en_GB.*
import ch.tutteli.atrium.api.verbs.internal.expect
import java.math.BigDecimal
import kotlin.test.Test
Expand All @@ -12,4 +12,68 @@ class BigDecimalExpectationSamples {
// only use toEqual to check against null, otherwise use toEqualNumerically or toEqualIncludingScale
expect(null as BigDecimal?).toEqual(null)
}


@Test
fun notToEqual() {
// only use notToEqual to check against null, otherwise use notToEqualNumerically or notToEqualIncludingScale
expect(null as BigDecimal?).notToEqual(BigDecimal("-12345.6789"))
expect(null as BigDecimal?).notToEqual(BigDecimal("1.0"))
expect(null as BigDecimal?).notToEqual(BigDecimal("25.0"))


expect(null as BigDecimal?).notToEqual(BigDecimal(-12345.6789))
expect(null as BigDecimal?).notToEqual(BigDecimal(1.0))
expect(null as BigDecimal?).notToEqual(BigDecimal(25.0))
}


@Test
fun toEqualNumerically() {
expect(BigDecimal("10")).toEqualNumerically(BigDecimal("10.0"))
expect(BigDecimal("1213669989183")).toEqualNumerically(BigDecimal("1213669989183"))
expect(BigDecimal("1238126387123")).toEqualNumerically(BigDecimal("1238126387123"))


expect(BigDecimal(10)).toEqualNumerically(BigDecimal(10.0))
expect(BigDecimal(1213669989183)).toEqualNumerically(BigDecimal(1213669989183))
expect(BigDecimal(1238126387123)).toEqualNumerically(BigDecimal(1238126387123))
}


@Test
fun notToEqualNumerically() {
expect(BigDecimal("10")).notToEqualNumerically(BigDecimal("1213669989183"))
expect(BigDecimal("1213669989183")).notToEqualNumerically(BigDecimal("10"))
expect(BigDecimal("1238126387123")).notToEqualNumerically(BigDecimal("-1.0"))

expect(BigDecimal(10)).notToEqualNumerically(BigDecimal(1213669989183))
expect(BigDecimal(1213669989183)).notToEqualNumerically(BigDecimal(10))
expect(BigDecimal(1238126387123)).notToEqualNumerically(BigDecimal(-1.0))
}


@Test
fun toEqualIncludingScale() {
expect(BigDecimal("10.0")).toEqualIncludingScale(BigDecimal("10.0"))
expect(BigDecimal("456.0")).toEqualIncludingScale(BigDecimal("456.0"))
expect(BigDecimal("-1.456")).toEqualIncludingScale(BigDecimal("-1.456"))

expect(BigDecimal(10.0)).toEqualIncludingScale(BigDecimal(10.0))
expect(BigDecimal(456.0)).toEqualIncludingScale(BigDecimal(456.0))
}


@Test
fun notToEqualIncludingScale() {
expect(BigDecimal("10")).notToEqualIncludingScale(BigDecimal("10.0"))
expect(BigDecimal("456.0")).notToEqualIncludingScale(BigDecimal("456"))
expect(BigDecimal("-1.456")).notToEqualIncludingScale(BigDecimal("-1.45"))

expect(BigDecimal(10)).notToEqualIncludingScale(BigDecimal(10.01))
expect(BigDecimal(456.01)).notToEqualIncludingScale(BigDecimal(456))
expect(BigDecimal(-1.456)).notToEqualIncludingScale(BigDecimal(-1.45))
}


}

0 comments on commit 4e993d5

Please sign in to comment.