DoubleRangeSource
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()
}
}Content copied to clipboard