DoubleRangeSource

@SourceProvider(value = DoubleRangeDataProvider::class)
annotation class DoubleRangeSource(val min: Double, val max: Double, val increment: Double = 0.5, val ascending: Boolean = true)

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

Samples

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

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

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

Properties

Link copied to clipboard
val ascending: Boolean = true

Whether the range should be ascending or descending.

Link copied to clipboard
val increment: Double = 0.5

The increment value for the range. The default value is 0.5

Link copied to clipboard
val max: Double

The maximum value for the range.

Link copied to clipboard
val min: Double

The minimum value for the range.