diff options
author | Burak Emir <emir@epfl.ch> | 2006-10-04 15:44:42 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2006-10-04 15:44:42 +0000 |
commit | 93275f2d34ec534049baf529493dc6f2836a85ea (patch) | |
tree | 146f98f9953acf406c3b1e2c9bb2e28bca789440 /test/files | |
parent | 7d72618b375a21387e18fc42b07a834cee3f2616 (diff) | |
download | scala-93275f2d34ec534049baf529493dc6f2836a85ea.tar.gz scala-93275f2d34ec534049baf529493dc6f2836a85ea.tar.bz2 scala-93275f2d34ec534049baf529493dc6f2836a85ea.zip |
fixed bugs in ListBuffer and ArrayBuffer, added...
fixed bugs in ListBuffer and ArrayBuffer, added unit test
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/unittest_collection.scala | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/test/files/run/unittest_collection.scala b/test/files/run/unittest_collection.scala new file mode 100644 index 0000000000..6d2a34cfb9 --- /dev/null +++ b/test/files/run/unittest_collection.scala @@ -0,0 +1,95 @@ + +object Test { + + import scala.testing.SUnit._ + import scala.collection.mutable.{ArrayBuffer, Buffer, BufferProxy, ListBuffer} + + trait BufferTest extends Assert { + def doTest(x:Buffer[String]) = { + // testing method += + x += "one" + assertEquals("retrieving 'one'", x(0), "one") + assertEquals("length A ", x.length, 1) + x += "two" + assertEquals("retrieving 'two'", x(1), "two") + assertEquals("length B ", x.length, 2) + + // testing method -= (removing last element) + x -= "two" + + assertEquals("length C ", x.length, 1) + + try { x(1); fail("no exception for removed element") } + catch { case i:IndexOutOfBoundsException => } + + try { x.remove(1); fail("no exception for removed element") } + catch { case i:IndexOutOfBoundsException => } + + x += "two2" + assertEquals("length D ", x.length, 2) + + // removing first element + x.remove(0) + assertEquals("length E ", x.length, 1) + + // toList + assertEquals("toList ", x.toList, List("two2")) + + // clear + x.clear + assertEquals("length F ", x.length, 0) + } + } + + class TArrayBuffer extends TestCase("collection.mutable.ArrayBuffer") with Assert with BufferTest { + + var x: ArrayBuffer[String] = _ + + override def runTest = { setUp; doTest(x); tearDown } + + override def setUp = { x = new scala.collection.mutable.ArrayBuffer } + + override def tearDown = { x.clear; x = null } + } + + class TListBuffer extends TestCase("collection.mutable.ListBuffer") with Assert with BufferTest { + + var x: ListBuffer[String] = _ + + override def runTest = { setUp; doTest(x); tearDown } + + override def setUp = { x = new scala.collection.mutable.ListBuffer } + + override def tearDown = { x.clear; x = null } + + } + + class TBufferProxy extends TestCase("collection.mutable.BufferProxy") with Assert with BufferTest { + + class BBuf(z:ListBuffer[String]) extends BufferProxy[String] { + def self = z + } + + var x: BufferProxy[String] = _ + + override def runTest = { setUp; doTest(x); tearDown } + + override def setUp = { x = new BBuf(new scala.collection.mutable.ListBuffer) } + + override def tearDown = { x.clear; x = null } + + } + + def main(args:Array[String]) = { + val ts = new TestSuite( + //new TArrayBuffer, + new TListBuffer//, + //new TBufferProxy + ) + val tr = new TestResult() + ts.run(tr) + for(val failure <- tr.failures) { + Console.println(failure) + } + } +} |