Hi I've decided to take a deep dive into kotest pr...
# kotest
i
Hi I've decided to take a deep dive into kotest property-testing and stuck a little bit. I want to write a simple property test for Two Sum problem, so I need to generate random
IntArray
and
Int
that will be sum of two random elements of the generated array. I had no problems with the first Arb:
Arb.list(<http://Arb.int|Arb.int>()).map { it.toIntArray() }
but couldn't find a solution for the second one. Could someone advise something or I choose the wrong direction?
s
What is the property that you are looking to test ?
i
I'm testing that sum of elements by indices returned by a given function is equal to passed one As an example:
Copy code
forAll (Arb.???) { array, sum ->
    val (first, second) = twoSum.find(array, sum)
    array[first] + array[second] == sum
}
I expect Arbs that will generate a random array and sum of two random unequal values from a given array, like array = [1, 2, 3, 5, 7] and sum = 9 as sum of 2 and 7, my function'll return [1, 4] indices then
s
the problem is, the sum needs to appear in the array right, so you need your 2nd arb to know about the possible values in the first arb ?
i
yep