How do I generate a positive list of integers in jqwik and Kotlin?

198 Views Asked by At

I have tried something like this, but seems like it's not working since I can see negatives in the generated list:

@Property
fun <testMethodName>(
  @ForAll @Size(min = 0, max = 1_500) 
  @Positive 
  @UniqueElements partials: List<@IntRange(min = 1, max = 10000) Int>
) = runTest { ... }

I wanted to generate the following:

  1. An array of ints
  2. a list with lenght between 0 to 1500
  3. values of every elements should be unique
  4. values of list elements must be between 1 to 10000
1

There are 1 best solutions below

0
On

The following code works using jqwik 1.7.2 on my machine:

import net.jqwik.api.ForAll
import net.jqwik.api.Property
import net.jqwik.api.constraints.Size
import net.jqwik.api.constraints.UniqueElements
import net.jqwik.kotlin.api.JqwikIntRange

class KotlinExperiments {
    @Property
    fun testMethodName(
        @ForAll @Size(min = 0, max = 1_500)
        @UniqueElements partials: List<@JqwikIntRange(min = 1, max = 10000) Int>
    ) {
        println(partials)
    }
}

JqwikIntRange is an alias for net.jqwik.api.constraints.IntRange since the Kotlin library has its own IntRange class.

If this doesn't work for you, check if you've done the necessary configuration for Kotlin?