net.serenitybdd.screenplay.ensure.DoubleEnsure.kt Maven / Gradle / Ivy
package net.serenitybdd.screenplay.ensure
import net.serenitybdd.screenplay.Actor
class DoubleEnsure(override val value: KnowableValue, comparator: Comparator) : ComparableEnsure(value, comparator) {
companion object {
fun fromKnowable(value: KnowableValue) : DoubleEnsure = DoubleEnsure(value, naturalOrder())
}
constructor(value: Double?) : this(KnownValue(value, value.toString()), naturalOrder())
/**
* Verifies that the actual {@code LocalDate} is before a specified date
*/
fun isCloseTo(expected: Double, margin: Double) = PerformableExpectation(value, within(margin), expected, isNegated())
override fun not(): DoubleEnsure = negate() as DoubleEnsure
override fun silently(): DoubleEnsure = super.silently() as DoubleEnsure
fun within(margin: Double) = expectThatActualIs("close to(within a margin of " + margin + ")",
fun(actor: Actor?, actual: KnowableValue?, expected: Double): Boolean {
CommonPreconditions.ensureActualNotNull(actual)
val actualValue = actual!!(actor!!) ?: return false
return actualValue >= (expected - margin) && actualValue <= (expected + margin)
})
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy