ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArraySetTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CopyOnWriteArraySetTest.java (file contents):
Revision 1.21 by jsr166, Tue Nov 29 05:09:05 2011 UTC vs.
Revision 1.24 by jsr166, Tue Nov 29 20:59:24 2011 UTC

# Line 8 | Line 8
8  
9   import junit.framework.*;
10   import java.util.Arrays;
11 + import java.util.Collection;
12   import java.util.Collections;
13   import java.util.Iterator;
14 + import java.util.NoSuchElementException;
15   import java.util.Set;
16   import java.util.Vector;
17   import java.util.concurrent.CopyOnWriteArraySet;
# Line 25 | Line 27 | public class CopyOnWriteArraySetTest ext
27      static CopyOnWriteArraySet<Integer> populatedSet(int n) {
28          CopyOnWriteArraySet<Integer> a = new CopyOnWriteArraySet<Integer>();
29          assertTrue(a.isEmpty());
30 <        for (int i = 0; i < n; ++i)
30 >        for (int i = 0; i < n; i++)
31              a.add(i);
32          assertFalse(a.isEmpty());
33          assertEquals(n, a.size());
# Line 167 | Line 169 | public class CopyOnWriteArraySetTest ext
169      }
170  
171      /**
172 <     * iterator() returns an iterator containing the elements of the set
172 >     * iterator() returns an iterator containing the elements of the
173 >     * set in insertion order
174       */
175      public void testIterator() {
176 <        CopyOnWriteArraySet full = populatedSet(3);
177 <        Iterator i = full.iterator();
178 <        int j;
179 <        for (j = 0; i.hasNext(); j++)
180 <            assertEquals(j, i.next());
181 <        assertEquals(3, j);
176 >        Set empty = new CopyOnWriteArraySet();
177 >        assertFalse(empty.iterator().hasNext());
178 >        try {
179 >            empty.iterator().next();
180 >            shouldThrow();
181 >        } catch (NoSuchElementException success) {}
182 >
183 >        Integer[] elements = new Integer[SIZE];
184 >        for (int i = 0; i < SIZE; i++)
185 >            elements[i] = i;
186 >        Collections.shuffle(Arrays.asList(elements));
187 >        Collection<Integer> full = populatedSet(elements);
188 >
189 >        Iterator it = full.iterator();
190 >        for (int j = 0; j < SIZE; j++) {
191 >            assertTrue(it.hasNext());
192 >            assertEquals(elements[j], it.next());
193 >        }
194 >        assertFalse(it.hasNext());
195 >        try {
196 >            it.next();
197 >            shouldThrow();
198 >        } catch (NoSuchElementException success) {}
199      }
200  
201      /**
# Line 247 | Line 267 | public class CopyOnWriteArraySetTest ext
267          for (int i = 0; i < SIZE; i++)
268              elements[i] = i;
269          Collections.shuffle(Arrays.asList(elements));
270 <        CopyOnWriteArraySet<Integer> full = populatedSet(elements);
270 >        Collection<Integer> full = populatedSet(elements);
271  
272          assertTrue(Arrays.equals(elements, full.toArray()));
273          assertSame(Object[].class, full.toArray().getClass());
# Line 258 | Line 278 | public class CopyOnWriteArraySetTest ext
278       * elements from the set in insertion order
279       */
280      public void testToArray2() {
281 <        CopyOnWriteArraySet empty = new CopyOnWriteArraySet();
281 >        Collection empty = new CopyOnWriteArraySet();
282          Integer[] a;
283  
284          a = new Integer[0];
# Line 275 | Line 295 | public class CopyOnWriteArraySetTest ext
295          for (int i = 0; i < SIZE; i++)
296              elements[i] = i;
297          Collections.shuffle(Arrays.asList(elements));
298 <        CopyOnWriteArraySet<Integer> full = populatedSet(elements);
298 >        Collection<Integer> full = populatedSet(elements);
299  
300          Arrays.fill(a, 42);
301          assertTrue(Arrays.equals(elements, full.toArray(a)));
# Line 320 | Line 340 | public class CopyOnWriteArraySetTest ext
340  
341          assertTrue(x != y);
342          assertEquals(x.size(), y.size());
343 +        assertEquals(x.toString(), y.toString());
344 +        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
345          assertEquals(x, y);
346          assertEquals(y, x);
347      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines