FloatRangeSource

@SourceProvider(value = FloatRangeDataProvider::class)
annotation class FloatRangeSource(val min: Float, val max: Float, val increment: Float = 0.5f, val ascending: Boolean = true)

Annotation to indicate that the annotated float parameter should be populated with a float range from min to max with an increment step in the ascending direction.

Samples

import assertk.Assert
import assertk.all
import assertk.assertThat
import assertk.assertions.isBetween
import assertk.assertions.isIn
import assertk.assertions.isLessThan
import assertk.assertions.support.expected
import com.wesleyhome.test.jupiter.annotations.GeneratedParametersTest
import com.wesleyhome.test.jupiter.annotations.StringSource
import com.wesleyhome.test.jupiter.annotations.datetime.InstantRangeSource
import com.wesleyhome.test.jupiter.annotations.datetime.InstantSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalDateRangeSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalDateSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalDateTimeRangeSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalDateTimeSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalTimeRangeSource
import com.wesleyhome.test.jupiter.annotations.datetime.LocalTimeSource
import com.wesleyhome.test.jupiter.annotations.datetime.RandomInstantSource
import com.wesleyhome.test.jupiter.annotations.number.DoubleRangeSource
import com.wesleyhome.test.jupiter.annotations.number.DoubleSource
import com.wesleyhome.test.jupiter.annotations.number.FloatRangeSource
import com.wesleyhome.test.jupiter.annotations.number.FloatSource
import com.wesleyhome.test.jupiter.annotations.number.IntRangeSource
import com.wesleyhome.test.jupiter.annotations.number.IntSource
import com.wesleyhome.test.jupiter.annotations.number.LongRangeSource
import com.wesleyhome.test.jupiter.annotations.number.LongSource
import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.temporal.ChronoUnit

fun main() { 
   //sampleStart 
   /**
 * This will generate 600 tests with the values 1.0 to 300.0
 * incrementing by 0.5. The values will be in ascending order
 */
@GeneratedParametersTest
fun testFloatRangeSource(@FloatRangeSource(min = 1.0F, max = 300.0F) value: Int) {
    assertThat(value).isBetween(1, 300)
}

/**
 * This will generate 300 tests with the values 1 to 300 with an increment of 1
 * The values will be in ascending order
 */
@GeneratedParametersTest
fun testFloatRangeSourceWithIncrement(
    @FloatRangeSource(
        min = 1.0F,
        max = 300.0F,
        increment = 1.0F
    ) value: Int
) {
    assertThat(value).all {
        isBetween(1, 300)
    }
}

/**
 * This will generate 300 tests with the values 1 to 300 with an increment of 1
 * The values will be in ascending order
 */
@GeneratedParametersTest
fun testFloatRangeSourceWithIncrementDescending(
    @FloatRangeSource(
        min = 1.0F,
        max = 300.0F,
        increment = 1.0F,
        ascending = false
    ) value: Int
) {
    assertThat(value).all {
        isBetween(1, 300)
    }
} 
   //sampleEnd
}

Properties

Link copied to clipboard
val ascending: Boolean = true

Whether the range should be in ascending or descending order. The default value true

Link copied to clipboard
val increment: Float = 0.5f

The increment step between values in the range. The default value 0.5f

Link copied to clipboard
val max: Float

The maximum value of the range.

Link copied to clipboard
val min: Float

The minimum value of the range.