Say I have a single list of strings, and I want to...
# kotest
s
Say I have a single list of strings, and I want to perform testing on all pairs of strings except if both strings point to the same instance. Would property testing with an Exhausive be the best way to go here, or is there something simpler?
s
By strings point to the same instance, do you mean if they are equal ?
s
I really only want to skip the assertion if the strings point to the same instance. I do want to perform the check if string happend to be textually equivalent, but come from different strings instances.
Basically I just want to ensure to not compare a string to itself in the matrix of all combinations.
s
I think in the JVM all equal strings share the same instance
maybe that's only the case for literals actually
Something like this might work for you:
Copy code
val mystrings = listOf("a", "a", "b", "c")
   checkAll(Exhaustive.collection(mystrings), Exhaustive.collection(mystrings)) { a, b ->
      if (a !== b) {
         // test here
      }
   }
s
ah, crap, due to string pooling, might be. then that was a bad example.
so, if it wasn't strings, but other objects, would it then be preferable to use
cartesian(myobjects, myobjects)
?
s
cartesian is better if you want all combinations to be tested
s
so, there's no easy helper function yet to test all x-tuple permutations of a collection where it's ensured that no tuple members point to the same instance, correct?
s
Copy code
checkAll(Exhaustive.cartesian(mystrings.exhaustive(), mystrings.exhaustive()) { a, b -> Pair(a, b) }
   .filter { it.first != it.second }) { pairs ->

}
correct
I'll add some helpers now
❤️ 1
but they won't surface til 5.0
s
ok, thanks for confirming, i just wanted to verify i'm not doing something too complicated in my code (which looks similar to yours).
s
I'll add
Copy code
cartesianPairs
❤️ 1