summaryrefslogtreecommitdiff
path: root/test/files/run/lists-run.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-05-19 20:06:19 +0000
committerPaul Phillips <paulp@improving.org>2011-05-19 20:06:19 +0000
commit4afa092314487c0095ff9fd5756d05340f6150b0 (patch)
treed3cf421e67192041f78858fe10735505f4891b3c /test/files/run/lists-run.scala
parent7595671ec3929aa4ac978826521300a900250214 (diff)
downloadscala-4afa092314487c0095ff9fd5756d05340f6150b0.tar.gz
scala-4afa092314487c0095ff9fd5756d05340f6150b0.tar.bz2
scala-4afa092314487c0095ff9fd5756d05340f6150b0.zip
Removes SUnit (long deprecated!) from the stand...
Removes SUnit (long deprecated!) from the standard library. the relatively small number of partest tests in Scala's suite that were still using SUnit now either just use regular asserts, or they print stuff that partest checks with a .check file. Also fixed some bad indentation, removed ancient useless-looking commented-out code, etc. Contributed by Seth Tisue (way to go seth) no review.
Diffstat (limited to 'test/files/run/lists-run.scala')
-rw-r--r--test/files/run/lists-run.scala171
1 files changed, 76 insertions, 95 deletions
diff --git a/test/files/run/lists-run.scala b/test/files/run/lists-run.scala
index 6871a96183..9e9e49e818 100644
--- a/test/files/run/lists-run.scala
+++ b/test/files/run/lists-run.scala
@@ -1,99 +1,84 @@
-//############################################################################
-// Lists
-//############################################################################
-
-//############################################################################
-
-import testing.SUnit._
-
/** Test the Scala implementation of class <code>scala.List</code>.
*
* @author Stephane Micheloud
*/
-object Test extends TestConsoleMain {
- def suite = new TestSuite(
- Test_multiset, // multiset operations: union, intersect, diff
- Test1, //count, exists, filter, ..
- Test2, //#468
- Test3, //#1691
- Test4, //#1721
- Test5
- )
+object Test {
+ def main(args: Array[String]) {
+ Test_multiset.run() // multiset operations: union, intersect, diff
+ Test1.run() //count, exists, filter, ..
+ Test2.run() //#468
+ Test3.run() //#1691
+ Test4.run() //#1721
+ Test5.run()
+ }
}
-object Test_multiset extends TestCase("multiset") with Assert {
- override def enableStackTrace = false
- override def runTest {
+object Test_multiset {
+ def run() {
def isSubListOf[A](thiz: List[A], that: List[A]): Boolean =
thiz forall (that contains _)
val xs = List(1, 1, 2)
val ys = List(1, 2, 2, 3)
- assertEquals("xs_union_ys", List(1, 1, 2, 1, 2, 2, 3), xs union ys)
- assertEquals("ys_union_xs", List(1, 2, 2, 3, 1, 1, 2), ys union xs)
- assertEquals("xs_intersect_ys", List(1, 2), xs intersect ys)
- assertEquals("ys_intersect_xs", List(1, 2), ys intersect xs)
- assertEquals("xs_diff_ys", List(1), xs diff ys)
- assertEquals("ys_diff_xs", List(2, 3), ys diff xs)
- assertTrue("xs_subset_ys", isSubListOf(xs -- ys, xs diff ys))
+ assert(List(1, 1, 2, 1, 2, 2, 3) == (xs union ys), "xs_union_ys")
+ assert(List(1, 2, 2, 3, 1, 1, 2) == (ys union xs), "ys_union_xs")
+ assert(List(1, 2) == (xs intersect ys), "xs_intersect_ys")
+ assert(List(1, 2) == (ys intersect xs), "ys_intersect_xs")
+ assert(List(1) == (xs diff ys), "xs_diff_ys")
+ assert(List(2, 3) == (ys diff xs), "ys_diff_xs")
+ assert(isSubListOf(xs -- ys, xs diff ys), "xs_subset_ys")
val zs = List(0, 1, 1, 2, 2, 2)
- assertEquals("zs_union_ys", List(0, 1, 1, 2, 2, 2, 1, 2, 2, 3), zs union ys)
- assertEquals("ys_union_zs", List(1, 2, 2, 3, 0, 1, 1, 2, 2, 2), ys union zs)
- assertEquals("zs_intersect_ys", List(1, 2, 2), zs intersect ys)
- assertEquals("ys_intersect_zs", List(1, 2, 2), ys intersect zs)
- assertEquals("zs_diff_ys", List(0, 1, 2), zs diff ys)
- assertEquals("ys_diff_zs", List(3), ys diff zs)
- assertTrue("xs_subset_ys", isSubListOf(zs -- ys, zs diff ys))
+ assert(List(0, 1, 1, 2, 2, 2, 1, 2, 2, 3) == (zs union ys), "zs_union_ys")
+ assert(List(1, 2, 2, 3, 0, 1, 1, 2, 2, 2) == (ys union zs), "ys_union_zs")
+ assert(List(1, 2, 2) == (zs intersect ys), "zs_intersect_ys")
+ assert(List(1, 2, 2) == (ys intersect zs), "ys_intersect_zs")
+ assert(List(0, 1, 2) == (zs diff ys), "zs_diff_ys")
+ assert(List(3) == (ys diff zs), "ys_diff_zs")
+ assert(isSubListOf(zs -- ys, zs diff ys), "xs_subset_ys")
val ws = List(2)
- assertEquals("ws_union_ys", List(2, 1, 2, 2, 3), ws union ys)
- assertEquals("ys_union_ws", List(1, 2, 2, 3, 2), ys union ws)
- assertEquals("ws_intersect_ys", List(2), ws intersect ys)
- assertEquals("ys_intersect_ws", List(2), ys intersect ws)
- assertEquals("ws_diff_ys", List(), ws diff ys)
- assertEquals("ys_diff_ws", List(1, 2, 3), ys diff ws)
- assertTrue("ws_subset_ys", isSubListOf(ws -- ys, ws diff ys))
+ assert(List(2, 1, 2, 2, 3) == (ws union ys), "ws_union_ys")
+ assert(List(1, 2, 2, 3, 2) == (ys union ws), "ys_union_ws")
+ assert(List(2) == (ws intersect ys), "ws_intersect_ys")
+ assert(List(2) == (ys intersect ws), "ys_intersect_ws")
+ assert(List() == (ws diff ys), "ws_diff_ys")
+ assert(List(1, 2, 3) == (ys diff ws), "ys_diff_ws")
+ assert(isSubListOf(ws -- ys, ws diff ys), "ws_subset_ys")
val vs = List(3, 2, 2, 1)
- assertEquals("xs_union_vs", List(1, 1, 2, 3, 2, 2, 1), xs union vs)
- assertEquals("vs_union_xs", List(3, 2, 2, 1, 1, 1, 2), vs union xs)
- assertEquals("xs_intersect_vs", List(1, 2), xs intersect vs)
- assertEquals("vs_intersect_xs", List(2, 1), vs intersect xs)
- assertEquals("xs_diff_vs", List(1), xs diff vs)
- assertEquals("vs_diff_xs", List(3, 2), vs diff xs)
- assertTrue("xs_subset_vs", isSubListOf(xs -- vs, xs diff vs))
+ assert(List(1, 1, 2, 3, 2, 2, 1) == (xs union vs), "xs_union_vs")
+ assert(List(3, 2, 2, 1, 1, 1, 2) == (vs union xs), "vs_union_xs")
+ assert(List(1, 2) == (xs intersect vs), "xs_intersect_vs")
+ assert(List(2, 1) == (vs intersect xs), "vs_intersect_xs")
+ assert(List(1) == (xs diff vs), "xs_diff_vs")
+ assert(List(3, 2) == (vs diff xs), "vs_diff_xs")
+ assert(isSubListOf(xs -- vs, xs diff vs), "xs_subset_vs")
// tests adapted from Thomas Jung
- assertTrue(
- "be symmetric after sorting", {
+ assert({
def sort(zs: List[Int]) = zs sort ( _ > _ )
sort(xs intersect ys) == sort(ys intersect xs)
- })
- assertTrue(
- "obey min cardinality", {
+ }, "be symmetric after sorting")
+ assert({
def cardinality[A](zs: List[A], e: A): Int = zs count (e == _)
val intersection = xs intersect ys
xs forall (e => cardinality(intersection, e) == (cardinality(xs, e)
min cardinality(ys, e)))
- })
- assertTrue(
- "maintain order", {
+ }, "obey min cardinality")
+ assert({
val intersection = xs intersect ys
val unconsumed = xs.foldLeft(intersection){(rest, e) =>
if (! rest.isEmpty && e == rest.head) rest.tail else rest
}
unconsumed.isEmpty
- })
- assertTrue(
- "has the list as again intersection",
- xs == (xs intersect xs)
- )
+ }, "maintain order")
+ assert(xs == (xs intersect xs),
+ "has the list as again intersection")
}
}
-object Test1 extends TestCase("ctor") with Assert {
- override def enableStackTrace = false
- override def runTest {
+object Test1 {
+ def run() {
val xs1 = List(1, 2, 3)
val xs2 = List('a', 'b')
val xs3 = List(List(1, 2), List(4, 5))
@@ -103,100 +88,96 @@ object Test1 extends TestCase("ctor") with Assert {
{
val n1 = xs1 count { e => e % 2 != 0 }
val n2 = xs4 count { e => e < 5 }
- assertEquals("check_count", 4, n1 + n2)
+ assert(4 == (n1 + n2), "check_count")
}
{
val b1 = xs1 exists { e => e % 2 == 0 }
val b2 = xs4 exists { e => e == 5 }
- assertEquals("check_exists", false , b1 & b2)
+ assert(!(b1 & b2), "check_exists")
}
{
val ys1 = xs1 filter { e => e % 2 == 0 }
val ys2 = xs4 filter { e => e < 5 }
- assertEquals("check_filter", 3, ys1.length + ys2.length)
+ assert(3 == ys1.length + ys2.length, "check_filter")
}
{
val n1 = xs1.foldLeft(0)((e1, e2) => e1 + e2)
val ys1 = xs4.foldLeft(List[Int]())((e1, e2) => e2 :: e1)
- assertEquals("check_foldLeft", 10, n1 + ys1.length)
+ assert(10 == n1 + ys1.length, "check_foldLeft")
}
{
val b1 = xs1 forall { e => e < 10}
val b2 = xs4 forall { e => e % 2 == 0 }
- assertEquals("check_forall", true, b1 & b2)
+ assert(b1 & b2, "check_forall")
}
{
val ys1 = xs1 filterNot { e => e % 2 != 0 }
val ys2 = xs4 filterNot { e => e < 5 }
- assertEquals("check_remove", 3, ys1.length + ys2.length)
+ assert(3 == ys1.length + ys2.length, "check_remove")
}
{
val ys1 = xs1 zip xs2
val ys2 = xs1 zip xs3
- assertEquals("check_zip", 4, ys1.length + ys2.length)
+ assert(4 == ys1.length + ys2.length, "check_zip")
}
{
val ys1 = xs1.zipAll(xs2, 0, '_')
val ys2 = xs2.zipAll(xs1, '_', 0)
val ys3 = xs1.zipAll(xs3, 0, List(-1))
- assertEquals("check_zipAll", 9, ys1.length + ys2.length + ys3.length)
+ assert(9 == ys1.length + ys2.length + ys3.length, "check_zipAll")
}
}
}
-object Test2 extends TestCase("t0468") with Assert {
- override def enableStackTrace = false
- override def runTest {
+object Test2 {
+ def run() {
val xs1 = List(1, 2, 3)
val xs2 = List(0)
val ys1 = xs1 ::: List(4)
- assertEquals("check_:::", List(1, 2, 3, 4), ys1)
+ assert(List(1, 2, 3, 4) == ys1, "check_:::")
val ys2 = ys1 - 4
- assertEquals("check_-", xs1, ys2)
+ assert(xs1 == ys2, "check_-")
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)
+ assert(14 == n2 + n3 + n4, "check_++")
}
}
-object Test3 extends TestCase("t1691") with Assert {
- override def enableStackTrace = false
- override def runTest {
+object Test3 {
+ def run() {
try {
List.range(1, 10, 0)
} catch {
case e: IllegalArgumentException => ()
case _ => throw new Error("List.range(1, 10, 0)")
}
- assertEquals(List.range(10, 0, -2),
- List(10, 8, 6, 4, 2))
+ assert(List.range(10, 0, -2) == List(10, 8, 6, 4, 2))
}
}
-object Test4 extends TestCase("t1721") with Assert {
- override def enableStackTrace = false
- override def runTest {
- assertTrue(List(1,2,3).endsWith(List(2,3)))
- assertFalse(List(1,2,3).endsWith(List(1,3)))
- assertTrue(List(1,2,3).endsWith(List()))
- assertFalse(List(1,2,3).endsWith(List(0,1,2,3)))
- assertTrue(List(1,2,3).endsWith(List(1,2,3)))
- assertFalse(List().endsWith(List(1,2,3)))
- assertTrue(List().endsWith(List()))
+object Test4 {
+ def run() {
+ assert(List(1,2,3).endsWith(List(2,3)))
+ assert(!List(1,2,3).endsWith(List(1,3)))
+ assert(List(1,2,3).endsWith(List()))
+ assert(!List(1,2,3).endsWith(List(0,1,2,3)))
+ assert(List(1,2,3).endsWith(List(1,2,3)))
+ assert(!List().endsWith(List(1,2,3)))
+ assert(List().endsWith(List()))
}
}
-object Test5 extends TestCase("list pattern matching") {
+object Test5 {
def show(xs: List[String]) = xs match {
case "foo" :: args => args.toString
case List(x) => x.toString
case Nil => "Nil"
}
- override def runTest {
+ def run() {
assert(show(List()) == "Nil")
assert(show(List("a")) == "a")
assert(show(List("foo", "b")) == "List(b)")