001: /*
002: * Copyright 2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.set;
017:
018: import java.util.Iterator;
019: import java.util.Set;
020:
021: import junit.framework.Test;
022: import junit.framework.TestSuite;
023:
024: import org.apache.commons.collections.map.LinkedMap;
025:
026: /**
027: * JUnit test.
028: *
029: * @since Commons Collections 3.1
030: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
031: *
032: * @author Stephen Colebourne
033: */
034: public class TestMapBackedSet2 extends AbstractTestSet {
035:
036: public TestMapBackedSet2(String testName) {
037: super (testName);
038: }
039:
040: public static Test suite() {
041: return new TestSuite(TestMapBackedSet2.class);
042: }
043:
044: public static void main(String args[]) {
045: String[] testCaseName = { TestMapBackedSet2.class.getName() };
046: junit.textui.TestRunner.main(testCaseName);
047: }
048:
049: public Set makeEmptySet() {
050: return MapBackedSet.decorate(new LinkedMap());
051: }
052:
053: protected Set setupSet() {
054: Set set = makeEmptySet();
055:
056: for (int i = 0; i < 10; i++) {
057: set.add(Integer.toString(i));
058: }
059: return set;
060: }
061:
062: public void testOrdering() {
063: Set set = setupSet();
064: Iterator it = set.iterator();
065:
066: for (int i = 0; i < 10; i++) {
067: assertEquals("Sequence is wrong", Integer.toString(i), it
068: .next());
069: }
070:
071: for (int i = 0; i < 10; i += 2) {
072: assertTrue("Must be able to remove int", set.remove(Integer
073: .toString(i)));
074: }
075:
076: it = set.iterator();
077: for (int i = 1; i < 10; i += 2) {
078: assertEquals("Sequence is wrong after remove ", Integer
079: .toString(i), it.next());
080: }
081:
082: for (int i = 0; i < 10; i++) {
083: set.add(Integer.toString(i));
084: }
085:
086: assertEquals("Size of set is wrong!", 10, set.size());
087:
088: it = set.iterator();
089: for (int i = 1; i < 10; i += 2) {
090: assertEquals("Sequence is wrong", Integer.toString(i), it
091: .next());
092: }
093: for (int i = 0; i < 10; i += 2) {
094: assertEquals("Sequence is wrong", Integer.toString(i), it
095: .next());
096: }
097: }
098:
099: public void testCanonicalEmptyCollectionExists() {
100: }
101:
102: public void testCanonicalFullCollectionExists() {
103: }
104:
105: }
|