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

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

package io.kotest.matchers.doubles

import io.kotest.common.ExperimentalKotest
import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.should
import kotlin.math.abs

/**
 * Beware, has no tolerance handling so will fail for numbers where the orders of magnitude vary greatly.
 */
@ExperimentalKotest
infix fun Double?.shouldBeMultipleOf(other: Double) = this should beMultipleOf(other)

/**
 * Beware, has no tolerance handling so will fail for numbers where the orders of magnitude vary greatly.
 */
@ExperimentalKotest
fun beMultipleOf(other: Double) = Matcher { value ->
   MatcherResult(
      value != null && value % other == 0.0,
      { "${value} should be multiple of ${other}" },
      { "${value} should not be multiple of ${other}" }
   )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy