1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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)
}
}
}
|