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.4 by dl, Sat Sep 20 18:20:07 2003 UTC vs.
Revision 1.8 by jsr166, Mon Nov 2 20:28:31 2009 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 11 | Line 12 | import java.util.concurrent.*;
12   import java.io.*;
13  
14   public class CopyOnWriteArraySetTest extends JSR166TestCase {
14    
15      public static void main(String[] args) {
16 <        junit.textui.TestRunner.run (suite());  
16 >        junit.textui.TestRunner.run (suite());
17      }
18
18      public static Test suite() {
19          return new TestSuite(CopyOnWriteArraySetTest.class);
20      }
# Line 23 | Line 22 | public class CopyOnWriteArraySetTest ext
22      static CopyOnWriteArraySet populatedSet(int n){
23          CopyOnWriteArraySet a = new CopyOnWriteArraySet();
24          assertTrue(a.isEmpty());
25 <        for (int i = 0; i < n; ++i)
25 >        for (int i = 0; i < n; ++i)
26              a.add(new Integer(i));
27          assertFalse(a.isEmpty());
28          assertEquals(n, a.size());
# Line 39 | Line 38 | public class CopyOnWriteArraySetTest ext
38      }
39  
40      /**
41 <     * Collection-constructed list holds all of its elements
41 >     * Collection-constructed set holds all of its elements
42       */
43      public void testConstructor3() {
44          Integer[] ints = new Integer[SIZE];
45          for (int i = 0; i < SIZE-1; ++i)
46              ints[i] = new Integer(i);
47          CopyOnWriteArraySet a = new CopyOnWriteArraySet(Arrays.asList(ints));
48 <        for (int i = 0; i < SIZE; ++i)
48 >        for (int i = 0; i < SIZE; ++i)
49              assertTrue(a.contains(ints[i]));
50      }
51 <        
51 >
52  
53      /**
54 <     *   addAll correctly adds each element from the given collection
54 >     *   addAll  adds each element from the given collection
55       */
56      public void testAddAll() {
57          CopyOnWriteArraySet full = populatedSet(3);
# Line 65 | Line 64 | public class CopyOnWriteArraySetTest ext
64      }
65  
66      /**
67 <     *   addAllAbsent adds each element from the given collection that did not
68 <     *  already exist in the List
67 >     *   addAll adds each element from the given collection that did not
68 >     *  already exist in the set
69       */
70      public void testAddAll2() {
71          CopyOnWriteArraySet full = populatedSet(3);
# Line 79 | Line 78 | public class CopyOnWriteArraySetTest ext
78      }
79  
80      /**
81 <     *   addIfAbsent will not add the element if it already exists in the list
81 >     *   add will not add the element if it already exists in the set
82       */
83      public void testAdd2() {
84          CopyOnWriteArraySet full = populatedSet(3);
# Line 88 | Line 87 | public class CopyOnWriteArraySetTest ext
87      }
88  
89      /**
90 <     *   addIfAbsent correctly adds the element when it does not exist
91 <     *   in the list
90 >     *   add  adds the element when it does not exist
91 >     *   in the set
92       */
93      public void testAdd3() {
94          CopyOnWriteArraySet full = populatedSet(3);
# Line 98 | Line 97 | public class CopyOnWriteArraySetTest ext
97      }
98  
99      /**
100 <     *   clear correctly removes all elements from the list
100 >     *   clear  removes all elements from the set
101       */
102      public void testClear() {
103          CopyOnWriteArraySet full = populatedSet(3);
# Line 107 | Line 106 | public class CopyOnWriteArraySetTest ext
106      }
107  
108      /**
109 <     *   contains returns the correct values
109 >     *   contains returns true for added elements
110       */
111      public void testContains() {
112          CopyOnWriteArraySet full = populatedSet(3);
# Line 133 | Line 132 | public class CopyOnWriteArraySetTest ext
132          assertEquals(a.hashCode(), b.hashCode());
133      }
134  
135 <    
135 >
136      /**
137 <     *   containsAll returns the correct values
137 >     *   containsAll returns true for collections with subset of elements
138       */
139      public void testContainsAll() {
140          CopyOnWriteArraySet full = populatedSet(3);
# Line 148 | Line 147 | public class CopyOnWriteArraySetTest ext
147      }
148  
149      /**
150 <     *   isEmpty returns the correct values
150 >     *   isEmpty is true when empty, else false
151       */
152      public void testIsEmpty() {
153          CopyOnWriteArraySet empty = new CopyOnWriteArraySet();
# Line 158 | Line 157 | public class CopyOnWriteArraySetTest ext
157      }
158  
159      /**
160 <     *   iterator() returns an iterator containing the elements of the list
160 >     *   iterator() returns an iterator containing the elements of the set
161       */
162      public void testIterator() {
163          CopyOnWriteArraySet full = populatedSet(3);
# Line 192 | Line 191 | public class CopyOnWriteArraySetTest ext
191          for (int i = 0; i < 3; ++i) {
192              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
193          }
194 <    }        
194 >    }
195  
196  
197      /**
198 <     *   removeAll correctly removes all elements from the given collection
198 >     *   removeAll  removes all elements from the given collection
199       */
200      public void testRemoveAll() {
201          CopyOnWriteArraySet full = populatedSet(3);
# Line 219 | Line 218 | public class CopyOnWriteArraySetTest ext
218      }
219  
220      /**
221 <     *   size returns the correct values
221 >     *   size returns the number of elements
222       */
223      public void testSize() {
224          CopyOnWriteArraySet empty = new CopyOnWriteArraySet();
# Line 229 | Line 228 | public class CopyOnWriteArraySetTest ext
228      }
229  
230      /**
231 <     *   toArray returns an Object array containing all elements from the list
231 >     *   toArray returns an Object array containing all elements from the set
232       */
233      public void testToArray() {
234          CopyOnWriteArraySet full = populatedSet(3);
# Line 242 | Line 241 | public class CopyOnWriteArraySetTest ext
241  
242      /**
243       *   toArray returns an Integer array containing all elements from
244 <     *   the list
244 >     *   the set
245       */
246      public void testToArray2() {
247          CopyOnWriteArraySet full = populatedSet(3);
# Line 257 | Line 256 | public class CopyOnWriteArraySetTest ext
256  
257      /**
258       *  toArray throws an ArrayStoreException when the given array can
259 <     *  not store the objects inside the list
259 >     *  not store the objects inside the set
260       */
261      public void testToArray_ArrayStoreException() {
262          try {
# Line 270 | Line 269 | public class CopyOnWriteArraySetTest ext
269      }
270  
271      /**
272 <     *
272 >     * A deserialized serialized set is equal
273       */
274      public void testSerialization() {
275          CopyOnWriteArraySet q = populatedSet(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines