001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: CollectionTest.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
008:
009: package org.ozoneDB.DxLib.test;
010:
011: import java.lang.*;
012: import java.util.*;
013: import org.ozoneDB.DxLib.*;
014:
015: /**
016: *
017: *
018: * @author <a href="http://www.softwarebuero.de/">SMB</a>
019: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
020: */
021: public class CollectionTest extends AbstractTest {
022:
023: final static int SIZE = Test.SIZE;
024:
025: /**
026: */
027: public static Object[] newStrings() {
028: Object[] objs = new Object[SIZE];
029: for (int i = 0; i < SIZE; i++) {
030: objs[i] = String.valueOf(i);
031: }
032: return objs;
033: }
034:
035: /**
036: */
037: public static Object[] newIntegers() {
038: Object[] objs = new Object[SIZE];
039: for (int i = 0; i < SIZE; i++) {
040: objs[i] = new Integer(i);
041: }
042: return objs;
043: }
044:
045: /**
046: */
047: public static Object[] newDxStrings() {
048: Object[] objs = new Object[SIZE];
049: for (int i = 0; i < SIZE; i++) {
050: objs[i] = new DxString(String.valueOf(i));
051: }
052: return objs;
053: }
054:
055: /**
056: */
057: public void add_iterate(DxCollection coll, Object[] objs)
058: throws Exception {
059: startTimer(coll.getClass().getName(), "add_iterate");
060: for (int i = 0; i < objs.length; i++) {
061: coll.add(objs[i]);
062: }
063: stopTimer();
064:
065: DxIterator it = coll.iterator();
066: while (it.next() != null) {
067: boolean found = false;
068: Object obj = it.object();
069: for (int j = 0; j < SIZE; j++) {
070: if (obj == objs[j]) {
071: found = true;
072: }
073: }
074: if (!found) {
075: error();
076: }
077: }
078: stopTimer();
079: }
080:
081: /**
082: */
083: public void contains(DxCollection coll, Object[] objs)
084: throws Exception {
085: for (int i = 0; i < objs.length; i++) {
086: coll.add(objs[i]);
087: }
088: startTimer(coll.getClass().getName(), "contains");
089:
090: for (int i = 0; i < SIZE; i++) {
091: if (!coll.contains(objs[i])) {
092: error();
093: }
094: }
095: stopTimer();
096: }
097:
098: /**
099: */
100: public void containsAll(DxCollection coll, Object[] objs)
101: throws Exception {
102: for (int i = 0; i < objs.length; i++) {
103: coll.add(objs[i]);
104: }
105: DxBag bag = new DxArrayBag();
106: bag.addAll(objs);
107: startTimer(coll.getClass().getName(), "containsAll");
108:
109: if (!coll.containsAll(bag)) {
110: error();
111: }
112:
113: if (!coll.containsAll(new DxArrayBag())) {
114: error();
115: }
116:
117: DxBag emptyBag = new DxArrayBag();
118: if (emptyBag.containsAll(coll)) {
119: error();
120: }
121:
122: stopTimer();
123: }
124:
125: /**
126: */
127: public void removeAll(DxCollection coll, Object[] objs)
128: throws Exception {
129: coll.addAll(objs);
130: startTimer(coll.getClass().getName(), "removeAll");
131:
132: DxBag bag = new DxArrayBag();
133: bag.addAll(objs);
134:
135: coll.removeAll(bag);
136:
137: if (coll.contains(objs[0]) || !coll.isEmpty()
138: || coll.count() != 0) {
139: error();
140: }
141:
142: stopTimer();
143: }
144:
145: /**
146: */
147: public void remove_count_isEmpty(DxCollection coll, Object[] objs)
148: throws Exception {
149: startTimer(coll.getClass().getName(), "remove_count_isEmpty");
150: if (!coll.isEmpty()) {
151: error();
152: }
153: if (coll.count() != 0) {
154: error();
155: }
156:
157: coll.addAll(objs);
158:
159: coll.remove(objs[0]);
160: coll.remove(objs[2]);
161: // coll.remove (objs[50].clone());
162:
163: if (coll.count() != (SIZE - 3)) {
164: error();
165: }
166: if (coll.isEmpty()) {
167: error();
168: }
169:
170: if (coll.contains(objs[0])) {
171: error();
172: }
173: if (coll.contains(objs[2])) {
174: error();
175: }
176: if (coll.contains(objs[50])) {
177: error();
178: }
179: if (!coll.contains(objs[1])) {
180: error();
181: }
182: stopTimer();
183: }
184:
185: /**
186: */
187: public void equals(DxCollection coll1, DxCollection coll2,
188: Object[] objs) throws Exception {
189: coll1.addAll(objs);
190: if (coll1.equals(coll2)) {
191: error();
192: }
193:
194: coll2.addAll(objs);
195: startTimer(coll1.getClass().getName(), "equals");
196:
197: if (!coll1.equals(coll2)) {
198: error();
199: }
200:
201: coll2.remove(objs[0]);
202: if (coll1.equals(coll2)) {
203: error();
204: }
205:
206: stopTimer();
207: }
208:
209: /**
210: */
211: public void toArray_clone_clear(DxCollection coll, Object[] objs) {
212: coll.addAll(objs);
213: DxCollection clone = (DxCollection) coll.clone();
214: if (!coll.equals(clone)) {
215: error();
216: }
217:
218: startTimer(coll.getClass().getName(), "toArray");
219:
220: Object[] array = coll.toArray();
221: stopTimer();
222:
223: coll.clear();
224: if (coll.equals(clone)) {
225: error();
226: }
227:
228: coll.addAll(array);
229: if (!coll.equals(clone)) {
230: error();
231: }
232: }
233:
234: }
|