diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-16 18:20:15 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-16 18:20:15 +0000 |
commit | 17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3 (patch) | |
tree | bb804b4038eb6d0dee58b77cea8bd2dcc6f42dc4 /test/files/pos/viewtest2.scala | |
parent | e70a1a24ef7a7b596a92e1853fd44e96f36ad245 (diff) | |
download | scala-17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3.tar.gz scala-17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3.tar.bz2 scala-17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3.zip |
Removed old scala tests from new Scala core mod...
Removed old scala tests from new Scala core module.
Diffstat (limited to 'test/files/pos/viewtest2.scala')
-rw-r--r-- | test/files/pos/viewtest2.scala | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/test/files/pos/viewtest2.scala b/test/files/pos/viewtest2.scala deleted file mode 100644 index 0d580418d0..0000000000 --- a/test/files/pos/viewtest2.scala +++ /dev/null @@ -1,115 +0,0 @@ -package test; - -/** A trait for totally ordered data. - */ -trait Ordered[+a] { - - /** Result of comparing `this' with operand `that'. - * returns `x' where - * x < 0 iff this < that - * x == 0 iff this == that - * x > 0 iff this > that - */ - def compareTo [b >: a <% Ordered[b]](that: b): int; - - def < [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) < 0; - - def > [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) > 0; - - def <= [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) <= 0; - - def >= [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) >= 0; -} - - -object O { - - def view (x: String): Ordered[String] = new Ordered[String] { - def compareTo [b >: String <% Ordered[b]](y: b): int = y match { - case y1: String => x compareTo y1; - case _ => -(y compareTo x) - } - } - def view (x: char): Ordered[char] = new Ordered[char] { - def compareTo [b >: char <% Ordered[b]](y: b): int = y match { - case y1: char => x - y1; - case _ => -(y compareTo x) - } - } - - def view[a <% Ordered[a]](x: List[a]): Ordered[List[a]] = - new Ordered[List[a]] { - def compareTo [b >: List[a] <% Ordered[b]](y: b): int = y match { - case y1: List[a] => compareLists(x, y1); - case _ => -(y compareTo x) - } - private def compareLists(xs: List[a], ys: List[a]): int = { - if (xs.isEmpty && ys.isEmpty) 0 - else if (xs.isEmpty) -1 - else if (ys.isEmpty) 1 - else { - val s = xs.head compareTo ys.head; - if (s != 0) s - else compareLists(xs.tail, ys.tail) - } - } - } -} - -trait Tree[+a <% Ordered[a]] { - def insert[b >: a <% Ordered[b]](x: b): Tree[b]; - def elements: List[a] -} - -object Empty extends Tree[All] { - def insert[b >: All <% Ordered[b]](x: b): Tree[b] = new Node(x, Empty, Empty); - def elements: List[All] = List(); -} - -class Node[+a <% Ordered[a]](elem: a, l: Tree[a], r: Tree[a]) extends Tree[a] { - def insert[b >: a <% Ordered[b]](x: b): Tree[b] = - if (x == elem) this - else if (x < elem) new Node(elem, l insert x, r) - else new Node(elem, l, r insert x); - def elements: List[a] = - l.elements ::: List(elem) ::: r.elements -} - -case class Str(elem: String) extends Ordered[Str] { - def compareTo[b >: Str <% Ordered[b]](that: b): int = that match { - case that1: Str => this.elem compareTo that1.elem - case _ => -(that compareTo this) - } -} - -object Test { - import O.view; - - private def toCharList(s: String): List[Char] = - if (s.length() == 0) List() - else s.charAt(0) :: toCharList(s.substring(1)); - - def main(args: Array[String]) = { - { - var t: Tree[String] = Empty; - for (val s <- args) { - t = t insert s - } - System.out.println(t.elements) - } - { - var t: Tree[Str] = Empty; - for (val s <- args) { - t = t insert Str(s) - } - System.out.println(t.elements) - } - { - var t: Tree[List[char]] = Empty; - for (val s <- args) { - t = t insert toCharList(s) - } - System.out.println(t.elements) - } - } -} |