diff options
author | aleksandar <aleksandar@lampmac14.epfl.ch> | 2012-01-12 15:28:25 +0100 |
---|---|---|
committer | aleksandar <aleksandar@lampmac14.epfl.ch> | 2012-01-12 15:30:42 +0100 |
commit | 51ddeb372b3f0b22041d9a51f3faee17acd7b749 (patch) | |
tree | 5f1156ed34f7cc429189e18cc88782f13a3bfc86 /test/files/scalacheck | |
parent | 178d49df450904330c06cfea9955f120ba04d34c (diff) | |
download | scala-51ddeb372b3f0b22041d9a51f3faee17acd7b749.tar.gz scala-51ddeb372b3f0b22041d9a51f3faee17acd7b749.tar.bz2 scala-51ddeb372b3f0b22041d9a51f3faee17acd7b749.zip |
Add mutable tree sets to the standard library.
This implementation is based on AVL trees.
The current implementation is contributed by Lucien Pereira.
Fixes #4147.
Diffstat (limited to 'test/files/scalacheck')
-rw-r--r-- | test/files/scalacheck/si4147.scala | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/files/scalacheck/si4147.scala b/test/files/scalacheck/si4147.scala new file mode 100644 index 0000000000..1453440ef1 --- /dev/null +++ b/test/files/scalacheck/si4147.scala @@ -0,0 +1,67 @@ +import org.scalacheck.Prop.forAll +import org.scalacheck.Properties +import org.scalacheck.ConsoleReporter.testStatsEx +import org.scalacheck.Gen +import org.scalacheck.ConsoleReporter + + +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]() + } + } +} |