0

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
johanneslink
  • 4,877
  • 1
  • 20
  • 37
Akhha8
  • 418
  • 3
  • 10
  • What is runTest doing? In a standard jqwik property Tests it wouldn’t be there, but you’d have a normal function body instead. Moreover, the Positive annotation has no effect in this position. – johanneslink Feb 06 '23 at 21:10

1 Answers1

0

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?

johanneslink
  • 4,877
  • 1
  • 20
  • 37