All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.serenitybdd.screenplay.ensure.FloatEnsure.kt Maven / Gradle / Ivy

There is a newer version: 4.2.9
Show newest version
package net.serenitybdd.screenplay.ensure

import net.serenitybdd.screenplay.Actor


class FloatEnsure(override val value: KnowableValue, comparator: Comparator) : ComparableEnsure(value, comparator) {

    constructor(value: Float?) : this(KnownValue(value, value.toString()), naturalOrder())

    companion object {
        fun fromKnowable(value: KnowableValue) : FloatEnsure = FloatEnsure(value, naturalOrder())
    }

    /**
     * Verifies that the actual {@code LocalDate} is before a specified date
     */
    fun isCloseTo(expected: Float, margin: Float) = PerformableExpectation(value, within(margin), expected, isNegated())
    override fun not(): FloatEnsure = negate() as FloatEnsure
    override fun silently(): FloatEnsure = super.silently() as FloatEnsure

    private fun within(margin: Float) = expectThatActualIs("close to (within a margin of " + margin + ")",
            fun(actor: Actor?, actual: KnowableValue?, expected: Float): Boolean {
                CommonPreconditions.ensureActualNotNull(actual)
                val actualValue = actual!!(actor!!) ?: return false
                return actualValue >= (expected - margin) && actualValue <= (expected + margin)
            })
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy