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:
but couldn't find a solution for the second one. Could someone advise something or I choose the wrong direction?
s
sam
05/01/2020, 3:07 PM
What is the property that you are looking to test ?
i
Ignat Simonenko
05/01/2020, 6:10 PM
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
sam
05/01/2020, 6:39 PM
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 ?