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

commonMain.io.kotest.matchers.doubles.Exactly.kt Maven / Gradle / Ivy

package io.kotest.matchers.doubles

import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe

/**
 * Asserts that this [Double] is exactly [other]
 *
 * Verifies that this [Double] has the same value as [other].
 *
 * Opposite of [Double.shouldNotBeExactly]
 *
 * ```
 * 0.1 shouldBeExactly 0.1   // Assertion passes
 * 0.1 shouldBeExactly 0.2   // Assertion fails
 * ```
 */
infix fun Double.shouldBeExactly(other: Double): Double {
   this shouldBe exactly(other)
   return this
}

/**
 * Asserts that this [Double] is not exactly [other]
 *
 * Verifies that this [Double] does not have the same value as [other].
 *
 * Opposite of [Double.shouldBeExactly]
 *
 * ```
 * 0.1 shouldNotBeExactly 0.2   // Assertion passes
 * 0.1 shouldNotBeExactly 0.1   // Assertion fails
 * ```
 */
infix fun Double.shouldNotBeExactly(other: Double): Double {
   this shouldNotBe exactly(other)
   return this
}

fun exactly(d: Double): Matcher = object : Matcher {
  override fun test(value: Double) =
     MatcherResult(
        value == d,
        { "$value is not equal to expected value $d" },
        { "$value should not equal $d" })
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy