summaryrefslogtreecommitdiff
path: root/test/files/run/iq.scala
diff options
context:
space:
mode:
authorstenman <stenman@epfl.ch>2003-07-09 14:43:30 +0000
committerstenman <stenman@epfl.ch>2003-07-09 14:43:30 +0000
commit720e381fd86214e972f47d2c608e8bba0691b9e3 (patch)
treec8bd75982bcf252bed6b3b2916bb6d7e4b790066 /test/files/run/iq.scala
parent428dce2175302ef5fcb20599525454a64ca7613c (diff)
downloadscala-720e381fd86214e972f47d2c608e8bba0691b9e3.tar.gz
scala-720e381fd86214e972f47d2c608e8bba0691b9e3.tar.bz2
scala-720e381fd86214e972f47d2c608e8bba0691b9e3.zip
Functional Queues, take 3
Diffstat (limited to 'test/files/run/iq.scala')
-rw-r--r--test/files/run/iq.scala76
1 files changed, 72 insertions, 4 deletions
diff --git a/test/files/run/iq.scala b/test/files/run/iq.scala
index e6c571227c..a7f87409f3 100644
--- a/test/files/run/iq.scala
+++ b/test/files/run/iq.scala
@@ -1,15 +1,27 @@
-/* $Id$ */
+/* $Id$
+ * Test file for immutable queues.
+ */
+
+import scala.collection.immutable.Queue;
object iq {
def main = {
- val q:scala.collection.immutable.Queue[Int] =
- scala.collection.immutable.Queue.Empty;
+ /* Create an empty queue. */
+ val q:Queue[Int] = Queue.Empty;
+
+ /* Test isEmpty.
+ * Expected: Empty
+ */
if(q.isEmpty) {
java.lang.System.out.println("Empty");
}
+ /* Test infix enqueing. */
val q2 = q + 42 + 0;
+ /* Test is empty and dequeue.
+ * Expected: Head: 42
+ */
val q4 =
if(q2.isEmpty) {
java.lang.System.out.println("Empty");
@@ -20,8 +32,64 @@ object iq {
q3;
};
- val q5 = q4.enqueue(1,2,3,4,5,6,7,8,9);
+ /* Test sequence enqueing. */
+ val q5:Queue[Any] = q4.enqueue(1,2,3,4,5,6,7,8,9);
+ /* Test toString.
+ * Expected: Head: q5: Queue(0,1,2,3,4,5,6,7,8,9)
+ */
java.lang.System.out.println("q5: " + q5);
+ /* Test apply
+ * Expected: q5[5]: 5
+ */
+ java.lang.System.out.println("q5[5]: " + q5.apply(5));
+
+ val q5c:Queue[char] = Queue.Empty.enqueue(0 as char, 1 as char,
+ 2 as char, 3 as char,
+ 4 as char, 5 as char,
+ 6 as char, 7 as char,
+ 8 as char, 9 as char);
+ /* Testing ==
+ * Expected: q5 == q9: true
+ * q9 == q5: true
+ */
+ java.lang.System.out.println("q5 == q5c: " + (q5 == q5c));
+ java.lang.System.out.println("q5c == q5: " + (q5c == q5));
+
+ val Pair(_,q6) = q5.dequeue;
+ val Pair(_,q7) = q6.dequeue;
+ val q8 = q7 + 10 + 11;
+ /* Test dequeu
+ * Expected: q8: Queue(2,3,4,5,6,7,8,9,10,11)
+ */
+ java.lang.System.out.println("q8: " + q8);
+ val q9 = Queue.Empty.enqueue(2,3,4,5,6,7,8,9,10,11);
+
+ /* Testing ==
+ * Expected: q8 == q9: true
+ */
+ java.lang.System.out.println("q8 == q9: " + (q8 == q9));
+
+ /* Testing elements
+ * Expected: Elements: 1 2 3 4 5 6 7 8 9
+ */
+ java.lang.System.out.print("Elements: ");
+ q6.elements.foreach(e => java.lang.System.out.print(" "+ e + " "));
+ java.lang.System.out.println();
+
+ /* Testing mkString
+ * Expected: String: <1-2-3-4-5-6-7-8-9>
+ */
+ java.lang.System.out.println("String: " + q6.mkString("<","-",">"));
+
+ /* Testing length
+ * Expected: Length: 9
+ */
+ java.lang.System.out.println("Length: " + q6.length);
+
+ /* Testing front
+ * Expected: Front: 1
+ */
+ java.lang.System.out.println("Front: " + q6.front);
}
}