1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
import org.scalacheck.Prop.{forAll, throws}
import org.scalacheck.Properties
import org.scalacheck.Gen
import collection.mutable
object Test extends Properties("Mutable TreeSet") {
val generator = Gen.listOfN(1000, Gen.chooseNum(0, 1000))
val denseGenerator = Gen.listOfN(1000, Gen.chooseNum(0, 200))
property("Insertion doesn't allow duplicates values.") = forAll(generator) { (s: List[Int]) =>
{
val t = mutable.TreeSet[Int](s: _*)
t == s.toSet
}
}
property("Verification of size method validity") = forAll(generator) { (s: List[Int]) =>
{
val t = mutable.TreeSet[Int](s: _*)
for (a <- s) {
t -= a
}
t.size == 0
}
}
property("All inserted elements are removed") = forAll(generator) { (s: List[Int]) =>
{
val t = mutable.TreeSet[Int](s: _*)
for (a <- s) {
t -= a
}
t == Set()
}
}
property("Elements are sorted.") = forAll(generator) { (s: List[Int]) =>
{
val t = mutable.TreeSet[Int](s: _*)
t.toList == s.distinct.sorted
}
}
property("Implicit CanBuildFrom resolution succeeds as well as the \"same-result-type\" principle.") =
forAll(generator) { (s: List[Int]) =>
{
val t = mutable.TreeSet[Int](s: _*)
val t2 = t.map(_ * 2)
t2.isInstanceOf[collection.mutable.TreeSet[Int]]
}
}
property("A view doesn't expose off bounds elements") = forAll(denseGenerator) { (s: List[Int]) =>
{
val t = mutable.TreeSet[Int](s: _*)
val view = t.rangeImpl(Some(50), Some(150))
view.filter(_ < 50) == Set[Int]() && view.filter(_ >= 150) == Set[Int]()
}
}
property("ordering must not be null") =
throws(classOf[NullPointerException])(mutable.TreeSet.empty[Int](null))
}
|