01: /*
02: * Copyright 2001-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
29: *
30: * @author Chuck Burdick
31: */
32: public class TestTreeBag extends AbstractTestBag {
33:
34: public TestTreeBag(String 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 args[]) {
43: String[] 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", "A", bag
63: .toArray()[0]);
64: assertEquals("Should get elements in correct order", "B", bag
65: .toArray()[1]);
66: assertEquals("Should get elements in correct order", "C", bag
67: .toArray()[2]);
68: assertEquals("Should get first key", "A", ((SortedBag) bag)
69: .first());
70: assertEquals("Should get last key", "D", ((SortedBag) bag)
71: .last());
72: }
73:
74: public String 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: }
|