aboutsummaryrefslogtreecommitdiff
path: root/tests/run/mutable-treeset.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2015-05-22 16:07:23 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-05-22 16:07:23 +0200
commit6965b470d433f501203c4e3d77b0919f826691ba (patch)
tree413446f1af3f40bb69499a60066609af6bc38d9f /tests/run/mutable-treeset.scala
parent91bb668c5f1b6e5c51dad9b373c9398521508bc3 (diff)
downloaddotty-6965b470d433f501203c4e3d77b0919f826691ba.tar.gz
dotty-6965b470d433f501203c4e3d77b0919f826691ba.tar.bz2
dotty-6965b470d433f501203c4e3d77b0919f826691ba.zip
Enable 440 run tests that pass.
Note that some of them may pass due to several bugs that interfere.
Diffstat (limited to 'tests/run/mutable-treeset.scala')
-rw-r--r--tests/run/mutable-treeset.scala145
1 files changed, 145 insertions, 0 deletions
diff --git a/tests/run/mutable-treeset.scala b/tests/run/mutable-treeset.scala
new file mode 100644
index 000000000..97dda6531
--- /dev/null
+++ b/tests/run/mutable-treeset.scala
@@ -0,0 +1,145 @@
+import scala.collection.mutable.TreeSet
+
+object Test extends dotty.runtime.LegacyApp {
+ val list = List(6,5,4,3,2,1,1,2,3,4,5,6,6,5,4,3,2,1)
+ val distinct = list.distinct
+ val sorted = distinct.sorted
+
+ // sublist stuff for a single level of slicing
+ val min = list.min
+ val max = list.max
+ val nonlist = ((min - 10) until (max + 20) filterNot list.contains).toList
+ val sublist = list filter {x => x >=(min + 1) && x < max}
+ val distinctSublist = sublist.distinct
+ val subnonlist = min :: max :: nonlist
+ val subsorted = distinctSublist.sorted
+
+ // subsublist for a 2nd level of slicing
+ val almostmin = sublist.min
+ val almostmax = sublist.max
+ val subsublist = sublist filter {x => x >=(almostmin + 1) && x < almostmax}
+ val distinctSubsublist = subsublist.distinct
+ val subsubnonlist = almostmin :: almostmax :: subnonlist
+ val subsubsorted = distinctSubsublist.sorted
+
+ def testSize: Unit = {
+ def check(set : TreeSet[Int], list: List[Int]): Unit = {
+ assert(set.size == list.size, s"$set had size ${set.size} while $list had size ${list.size}")
+ }
+
+ check(TreeSet[Int](), List[Int]())
+ val set = TreeSet(list:_*)
+ check(set, distinct)
+ check(set.clone, distinct)
+
+ val subset = set from (min + 1) until max
+ check(subset, distinctSublist)
+ check(subset.clone, distinctSublist)
+
+ val subsubset = subset from (almostmin + 1) until almostmax
+ check(subsubset, distinctSubsublist)
+ check(subsubset.clone, distinctSubsublist)
+ }
+
+ def testContains: Unit = {
+ def check(set : TreeSet[Int], list: List[Int], nonlist: List[Int]): Unit = {
+ assert(list forall set.apply, s"$set did not contain all elements of $list using apply")
+ assert(list forall set.contains, s"$set did not contain all elements of $list using contains")
+ assert(!(nonlist exists set.apply), s"$set had an element from $nonlist using apply")
+ assert(!(nonlist exists set.contains), s"$set had an element from $nonlist using contains")
+ }
+
+ val set = TreeSet(list:_*)
+ check(set, list, nonlist)
+ check(set.clone, list, nonlist)
+
+ val subset = set from (min + 1) until max
+ check(subset, sublist, subnonlist)
+ check(subset.clone, sublist, subnonlist)
+
+ val subsubset = subset from (almostmin + 1) until almostmax
+ check(subsubset, subsublist, subsubnonlist)
+ check(subsubset.clone, subsublist, subsubnonlist)
+ }
+
+ def testAdd: Unit = {
+ def check(set : TreeSet[Int], list: List[Int], nonlist: List[Int]): Unit = {
+ var builtList = List[Int]()
+ for (x <- list) {
+ set += x
+ builtList = (builtList :+ x).distinct.sorted filterNot nonlist.contains
+ assert(builtList forall set.apply, s"$set did not contain all elements of $builtList using apply")
+ assert(builtList.size == set.size, s"$set had size ${set.size} while $builtList had size ${builtList.size}")
+ }
+ assert(!(nonlist exists set.apply), s"$set had an element from $nonlist using apply")
+ assert(!(nonlist exists set.contains), s"$set had an element from $nonlist using contains")
+ }
+
+ val set = TreeSet[Int]()
+ val clone = set.clone
+ val subset = set.clone from (min + 1) until max
+ val subclone = subset.clone
+ val subsubset = subset.clone from (almostmin + 1) until almostmax
+ val subsubclone = subsubset.clone
+
+ check(set, list, nonlist)
+ check(clone, list, nonlist)
+
+ check(subset, list, subnonlist)
+ check(subclone, list, subnonlist)
+
+ check(subsubset, list, subsubnonlist)
+ check(subsubclone, list, subsubnonlist)
+ }
+
+ def testRemove: Unit = {
+ def check(set: TreeSet[Int], sorted: List[Int]): Unit = {
+ var builtList = sorted
+ for (x <- list) {
+ set remove x
+ builtList = builtList filterNot (_ == x)
+ assert(builtList forall set.apply, s"$set did not contain all elements of $builtList using apply")
+ assert(builtList.size == set.size, s"$set had size $set.size while $builtList had size $builtList.size")
+ }
+ }
+ val set = TreeSet(list:_*)
+ val clone = set.clone
+ val subset = set.clone from (min + 1) until max
+ val subclone = subset.clone
+ val subsubset = subset.clone from (almostmin + 1) until almostmax
+ val subsubclone = subsubset.clone
+
+ check(set, sorted)
+ check(clone, sorted)
+
+ check(subset, subsorted)
+ check(subclone, subsorted)
+
+ check(subsubset, subsubsorted)
+ check(subsubclone, subsubsorted)
+ }
+
+ def testIterator: Unit = {
+ def check(set: TreeSet[Int], list: List[Int]): Unit = {
+ val it = set.iterator.toList
+ assert(it == list, s"$it did not equal $list")
+ }
+ val set = TreeSet(list: _*)
+ check(set, sorted)
+ check(set.clone, sorted)
+
+ val subset = set from (min + 1) until max
+ check(subset, subsorted)
+ check(subset.clone, subsorted)
+
+ val subsubset = subset from (almostmin + 1) until almostmax
+ check(subsubset, subsubsorted)
+ check(subsubset.clone, subsubsorted)
+ }
+
+ testSize
+ testContains
+ testAdd
+ testRemove
+ testIterator
+}