summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/treemap.scala
diff options
context:
space:
mode:
authorErik Rozendaal <erik@deler.org>2012-01-15 13:48:00 +0100
committerErik Rozendaal <erik@deler.org>2012-01-15 14:41:30 +0100
commit00b5cb84df493aace270674054d2f6ddf3721131 (patch)
tree2568b2913408feca58cb970b9b1402a4153eeffd /test/files/scalacheck/treemap.scala
parentf26f610278887b842de3a4e4fdafb866dd1afb62 (diff)
downloadscala-00b5cb84df493aace270674054d2f6ddf3721131.tar.gz
scala-00b5cb84df493aace270674054d2f6ddf3721131.tar.bz2
scala-00b5cb84df493aace270674054d2f6ddf3721131.zip
Optimized implementation of TreeMap/TreeSet#to method.
Performance of `to` and `until` is now the same.
Diffstat (limited to 'test/files/scalacheck/treemap.scala')
-rw-r--r--test/files/scalacheck/treemap.scala18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/files/scalacheck/treemap.scala b/test/files/scalacheck/treemap.scala
index 7d5f94d58b..ba6d117fd4 100644
--- a/test/files/scalacheck/treemap.scala
+++ b/test/files/scalacheck/treemap.scala
@@ -111,6 +111,24 @@ object Test extends Properties("TreeMap") {
prefix.forall(_._1 < 0) && suffix.forall(_._1 >= 0) && subject == prefix ++ suffix
}
+ property("from is inclusive") = forAll { (subject: TreeMap[Int, String]) => subject.nonEmpty ==> {
+ val n = choose(0, subject.size - 1).sample.get
+ val from = subject.drop(n).firstKey
+ subject.from(from).firstKey == from && subject.from(from).forall(_._1 >= from)
+ }}
+
+ property("to is inclusive") = forAll { (subject: TreeMap[Int, String]) => subject.nonEmpty ==> {
+ val n = choose(0, subject.size - 1).sample.get
+ val to = subject.drop(n).firstKey
+ subject.to(to).lastKey == to && subject.to(to).forall(_._1 <= to)
+ }}
+
+ property("until is exclusive") = forAll { (subject: TreeMap[Int, String]) => subject.size > 1 ==> {
+ val n = choose(1, subject.size - 1).sample.get
+ val until = subject.drop(n).firstKey
+ subject.until(until).lastKey == subject.take(n).lastKey && subject.until(until).forall(_._1 <= until)
+ }}
+
property("remove single") = forAll { (subject: TreeMap[Int, String]) => subject.nonEmpty ==> {
val key = oneOf(subject.keys.toSeq).sample.get
val removed = subject - key