From bb37eb067be49ed9f7b070a7cab354801c38f9ad Mon Sep 17 00:00:00 2001 From: michelou Date: Fri, 22 Feb 2008 15:23:15 +0000 Subject: fixed #468 --- test/files/run/lists.check | 12 ---- test/files/run/lists.scala | 138 +++++++++++++++++++++------------------------ 2 files changed, 65 insertions(+), 85 deletions(-) delete mode 100644 test/files/run/lists.check (limited to 'test/files') diff --git a/test/files/run/lists.check b/test/files/run/lists.check deleted file mode 100644 index 1da0075273..0000000000 --- a/test/files/run/lists.check +++ /dev/null @@ -1,12 +0,0 @@ -test check_count was successful -test check_diff was successful -test check_exists was successful -test check_filter was successful -test check_foldLeft was successful -test check_forall was successful -test check_intersect was successful -test check_remove was successful -test check_union was successful -test check_zip was successful -test check_zipAll was successful - diff --git a/test/files/run/lists.scala b/test/files/run/lists.scala index 947433d6a6..fc0fec466e 100644 --- a/test/files/run/lists.scala +++ b/test/files/run/lists.scala @@ -5,111 +5,103 @@ //############################################################################ -object Test { +import testing.SUnit._ + +/** Test the Scala implementation of class scala.List. + * + * @author Stephane Micheloud + */ +object Test extends TestConsoleMain { + def suite = new TestSuite( + Test1, //count, exists, filter, .. + Test2 //#468 + ) +} - val xs1 = List(1, 2, 3) - val xs2 = List('a', 'b') - val xs3 = List(List(1, 2), List(4, 5)) - val xs4 = List(2, 4, 6, 8) - val xs5 = List(List(3, 4), List(3), List(4, 5)) +object Test1 extends TestCase("ctor") with Assert { + override def enableStackTrace = false + override def runTest { + val xs1 = List(1, 2, 3) + val xs2 = List('a', 'b') + val xs3 = List(List(1, 2), List(4, 5)) + val xs4 = List(2, 4, 6, 8) + val xs5 = List(List(3, 4), List(3), List(4, 5)) - def check_count: Int = { + { val n1 = xs1 count { e => e % 2 != 0 } val n2 = xs4 count { e => e < 5 } - n1 + n2 + assertEquals("check_count", 4, n1 + n2) } - - def check_diff: Int = { + /* deprecated + { val ys1 = xs1 diff xs4 val ys2 = xs3 diff xs5 - ys1.length + ys2.length - } - - def check_exists: Boolean = { + assertEquals("check_diff", 3, ys1.length + ys2.length) + }*/ + { val b1 = xs1 exists { e => e % 2 == 0 } val b2 = xs4 exists { e => e == 5 } - b1 & b2 + assertEquals("check_exists", false , b1 & b2) } - - def check_filter: Int = { + { val ys1 = xs1 filter { e => e % 2 == 0 } val ys2 = xs4 filter { e => e < 5 } - ys1.length + ys2.length + assertEquals("check_filter", 3, ys1.length + ys2.length) } - - def check_foldLeft: Int = { + { val n1 = xs1.foldLeft(0)((e1, e2) => e1 + e2) val ys1 = xs4.foldLeft(List[Int]())((e1, e2) => e2 :: e1) - n1 + ys1.length + assertEquals("check_foldLeft", 10, n1 + ys1.length) } - - def check_forall: Boolean = { + { val b1 = xs1 forall { e => e < 10} val b2 = xs4 forall { e => e % 2 == 0 } - b1 & b2 + assertEquals("check_forall", true, b1 & b2) } - - def check_intersect: Int = { + { val ys1 = xs1 intersect xs4 val ys2 = xs3 intersect xs5 - ys1.length + ys2.length + assertEquals("check_intersect", 2, ys1.length + ys2.length) } - - def check_remove: Int = { + { val ys1 = xs1 remove { e => e % 2 != 0 } val ys2 = xs4 remove { e => e < 5 } - ys1.length + ys2.length + assertEquals("check_remove", 3, ys1.length + ys2.length) } - - def check_union: Int = { - val ys1 = xs1 union xs4; - val ys2 = xs3 union xs5; - ys1.length + ys2.length + { + val ys1 = xs1 union xs4 + val ys2 = xs3 union xs5 + assertEquals("check_union", 10, ys1.length + ys2.length) } - - def check_zip: Int = { - val ys1 = xs1 zip xs2; - val ys2 = xs1 zip xs3; - ys1.length + ys2.length + { + val ys1 = xs1 zip xs2 + val ys2 = xs1 zip xs3 + assertEquals("check_zip", 4, ys1.length + ys2.length) } - - def check_zipAll: Int = { + { val ys1 = xs1.zipAll(xs2, 0, '_') val ys2 = xs2.zipAll(xs1, '_', 0) val ys3 = xs1.zipAll(xs3, 0, List(-1)) - ys1.length + ys2.length + ys3.length + assertEquals("check_zipAll", 9, ys1.length + ys2.length + ys3.length) } - - def check_success[A](name: String, closure: => A, expected: A) { - print("test " + name) - try { - val actual: A = closure - if (actual == expected) - print(" was successful") - else - print(" failed: expected "+ expected +", found "+ actual) - } - catch { - case exception: Throwable => - print(" raised exception " + exception) - } - println } +} + +object Test2 extends TestCase("t0468") with Assert { + override def enableStackTrace = false + override def runTest { + val xs1 = List(1, 2, 3) + val xs2 = List(0) - def main(args: Array[String]) { - check_success("check_count", check_count, 4) - check_success("check_diff", check_diff, 3) - check_success("check_exists", check_exists, false) - check_success("check_filter", check_filter, 3) - check_success("check_foldLeft", check_foldLeft, 10) - check_success("check_forall", check_forall, true) - check_success("check_intersect", check_intersect, 2) - check_success("check_remove", check_remove, 3) - check_success("check_union", check_union, 10) - check_success("check_zip", check_zip, 4) - check_success("check_zipAll", check_zipAll, 9) - println + val ys1 = xs1 + 4 + assertEquals("check_+", List(1, 2, 3, 4), ys1) + + val ys2 = ys1 - 4 + assertEquals("check_-", xs1, ys2) + + val n2 = (xs1 ++ ys1).length + val n3 = (xs1 ++ Nil).length + val n4 = (xs1 ++ ((new collection.mutable.ArrayBuffer[Int]) + 0)).length + assertEquals("check_++", 14, n2 + n3 + n4) } } - -//############################################################################ -- cgit v1.2.3