FloatRangeSource
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
/**
* 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)
}
}Content copied to clipboard