Skip to content

Commit

Permalink
Added samples for BigDecimal in api-infix which were missing (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
VarunEnishetty authored Aug 22, 2023
1 parent 170982e commit a6bcc64
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ infix fun <T : BigDecimal> Expect<T?>.notToEqual(expected: Nothing?): Expect<T>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.BigDecimalExpectationSamples.toEqualNumerically
*
* @since 0.17.0
*/
infix fun <T : BigDecimal> Expect<T>.toEqualNumerically(expected: T): Expect<T> =
Expand All @@ -143,6 +145,8 @@ infix fun <T : BigDecimal> Expect<T>.toEqualNumerically(expected: T): Expect<T>
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.BigDecimalExpectationSamples.notToEqualNumerically
*
* @since 0.17.0
*/
infix fun <T : BigDecimal> Expect<T>.notToEqualNumerically(expected: T): Expect<T> =
Expand All @@ -160,6 +164,8 @@ infix fun <T : BigDecimal> Expect<T>.notToEqualNumerically(expected: T): Expect<
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.BigDecimalExpectationSamples.toEqualIncludingScale
*
* @since 0.17.0
*/
infix fun <T : BigDecimal> Expect<T>.toEqualIncludingScale(expected: T): Expect<T> =
Expand All @@ -176,6 +182,8 @@ infix fun <T : BigDecimal> Expect<T>.toEqualIncludingScale(expected: T): Expect<
*
* @return an [Expect] for the subject of `this` expectation.
*
* @sample ch.tutteli.atrium.api.infix.en_GB.samples.BigDecimalExpectationSamples.notToEqualIncludingScale
*
* @since 0.17.0
*/
infix fun <T : BigDecimal> Expect<T>.notToEqualIncludingScale(expected: T): Expect<T> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ch.tutteli.atrium.api.infix.en_GB.samples
import ch.tutteli.atrium.api.infix.en_GB.*
import ch.tutteli.atrium.api.verbs.expect
import java.math.BigDecimal
import java.math.MathContext
import kotlin.test.Test

class BigDecimalExpectationSamples {
Expand All @@ -28,4 +29,44 @@ class BigDecimalExpectationSamples {
expect(null as BigDecimal?) notToEqual null
}
}

@Test
fun toEqualNumerically(){
// Use toEqualNumerically to compare subject and target are numerically equal
expect(BigDecimal("-12345.67890")) toEqualNumerically BigDecimal("-12345.6789")

fails{
expect(BigDecimal("-12345.678")) toEqualNumerically BigDecimal("-12345.6789")
}
}

@Test
fun notToEqualNumerically(){
// Use notToEqualNumerically to compare subject and target are not numerically equal
expect(BigDecimal("-12345.678")) notToEqualNumerically BigDecimal("-12345.6789")

fails{
expect(BigDecimal("-12345.67890")) notToEqualNumerically BigDecimal("-12345.6789")
}
}

@Test
fun toEqualIncludingScale(){
// Use toEqualIncludingScale to compare subject and target are numerically equal including scale
expect(BigDecimal("-12345.678912", MathContext(9))) toEqualIncludingScale BigDecimal("-12345.6789")

fails{
expect(BigDecimal("-12345.67890")) toEqualIncludingScale BigDecimal("-12345.6789")
}
}

@Test
fun notToEqualIncludingScale(){
// Use notToEqualIncludingScale to compare subject and target are not numerically and scaling equal
expect(BigDecimal("-12345.67890")) notToEqualIncludingScale BigDecimal("-12345.6789")

fails{
expect(BigDecimal("-12345.678912", MathContext(9))) notToEqualIncludingScale BigDecimal("-12345.6789")
}
}
}

0 comments on commit a6bcc64

Please sign in to comment.