KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > bag > TestTreeBag


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.bag;
17
18 import junit.framework.Test;
19 import junit.framework.TestSuite;
20
21 import org.apache.commons.collections.Bag;
22 import org.apache.commons.collections.SortedBag;
23
24 /**
25  * Extension of {@link TestBag} for exercising the {@link TreeBag}
26  * implementation.
27  *
28  * @version $Revision: 1.4 $ $Date: 2004/02/18 01:20:39 $
29  *
30  * @author Chuck Burdick
31  */

32 public class TestTreeBag extends AbstractTestBag {
33     
34    public TestTreeBag(String JavaDoc testName) {
35       super(testName);
36    }
37
38    public static Test suite() {
39       return new TestSuite(TestTreeBag.class);
40    }
41
42    public static void main(String JavaDoc args[]) {
43       String JavaDoc[] testCaseName = { TestTreeBag.class.getName() };
44       junit.textui.TestRunner.main(testCaseName);
45    }
46
47    public Bag makeBag() {
48       return new TreeBag();
49    }
50
51    public SortedBag setupBag() {
52       SortedBag bag = (SortedBag)makeBag();
53       bag.add("C");
54       bag.add("A");
55       bag.add("B");
56       bag.add("D");
57       return bag;
58    }
59
60    public void testOrdering() {
61       Bag bag = setupBag();
62       assertEquals("Should get elements in correct order",
63                    "A", bag.toArray()[0]);
64       assertEquals("Should get elements in correct order",
65                    "B", bag.toArray()[1]);
66       assertEquals("Should get elements in correct order",
67                    "C", bag.toArray()[2]);
68       assertEquals("Should get first key",
69                    "A", ((SortedBag)bag).first());
70       assertEquals("Should get last key",
71                    "D", ((SortedBag)bag).last());
72    }
73    
74    public String JavaDoc getCompatibilityVersion() {
75        return "3";
76    }
77     
78 // public void testCreate() throws Exception {
79
// Bag bag = makeBag();
80
// writeExternalFormToDisk((Serializable) bag, "D:/dev/collections/data/test/TreeBag.emptyCollection.version3.obj");
81
// bag = makeBag();
82
// bag.add("A");
83
// bag.add("A");
84
// bag.add("B");
85
// bag.add("B");
86
// bag.add("C");
87
// writeExternalFormToDisk((Serializable) bag, "D:/dev/collections/data/test/TreeBag.fullCollection.version3.obj");
88
// }
89
}
90
Popular Tags