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

commonMain.io.kotest.properties.PropertyContext.kt Maven / Gradle / Ivy

package io.kotest.properties

/**
 * A [PropertyContext] is used when executing a propery test.
 * It allows feedback and tracking of the state of the property test.
 */
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
class PropertyContext {

  private var values = mutableListOf()
  private var attempts = 0
  private val counts = mutableMapOf()

  internal fun inc() {
    attempts++
  }

  fun attempts(): Int = attempts

  fun addValue(any: Any?) = values.add(any)

  fun values() = values.toList()

  fun classificationCounts(): Map = counts.toMap()

  fun classify(condition: Boolean, trueLabel: String) {
    if (condition) {
      val current = counts.getOrElse(trueLabel) { 0 }
      counts[trueLabel] = current + 1
    }
  }

  fun classify(condition: Boolean, trueLabel: String, falseLabel: String) {
    if (condition) {
      classify(condition, trueLabel)
    } else {
      classify(!condition, falseLabel)
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy