I am writing a collection class, and created elaborate property definitions comparing the results of operations on it, and a standard Scala collection. My Properies object has the following:
var prideCounter = 0
property(":++(Seq[Int]))") = forAll { (prefix :C[Int], suffix :Seq[Int]) =>
System.err.println(f"$prideCounter%10d: $prefix ++: $suffix")
prideCounter += 1
validate(List.from(prefix) ++ suffix, (prefix :++ suffix) to C)
}
var shameCounter = 0
property("(Seq[Int]))++:") = forAll { (prefix :Seq[Int], suffix :C[Int]) =>
System.err.println(f"$shameCounter%10d: $prefix ++: $suffix")
shameCounter += 1
validate(prefix ++ List.from(suffix), (prefix ++: suffix) to C)
}
The first property runs 500 times (I have increased the minimum number of successful tests), while the second fails with an exception (my bug somewhere) after 310791 attempts. It is most likely an issue with the collection implementation, because I ran the same Properties class for another Seq implementation (the only things differing are implementations of an abstract property returning a SeqFactory), and it works. Still, I have no idea what to look for, because, as you see, the difference between the sane test and the insane one is as small as it gets.
It is also the reason why extracting it is impossible; validate runs a lot of forAll under the scenes (though exactly the same for the two cases).
If anybody wants to have a closer look, the concrete class is here [https://github.com/noresttherein/sugar/blob/master/src/test/scala/net/noresttherein/sugar/collections/BTreeSeqSpec.scala]
However, the actual implementation with the definition of the two properties is inherited from: [https://github.com/noresttherein/sugar/blob/master/src/test/scala/net/noresttherein/sugar/collections/IterableProps.scala]
Link to the malfunctioning commit, with all other test properties commented out (it introduces the whole new collection and some tangential changes, but the tests existed before, and worked on other collections): [https://github.com/noresttherein/sugar/commit/431b6bd07b5f109073e4cf4653872534addbce99]