31 |
|
assertTrue(a.isEmpty()); |
32 |
|
for (int i = 0; i < n; i++) |
33 |
|
a.add(i); |
34 |
< |
assertFalse(a.isEmpty()); |
34 |
> |
assertEquals(n == 0, a.isEmpty()); |
35 |
|
assertEquals(n, a.size()); |
36 |
|
return a; |
37 |
|
} |
67 |
|
} |
68 |
|
|
69 |
|
/** |
70 |
< |
* addAll adds each element from the given collection |
70 |
> |
* addAll adds each non-duplicate element from the given collection |
71 |
|
*/ |
72 |
|
public void testAddAll() { |
73 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
73 |
> |
Set full = populatedSet(3); |
74 |
|
assertTrue(full.addAll(Arrays.asList(three, four, five))); |
75 |
|
assertEquals(6, full.size()); |
76 |
|
assertFalse(full.addAll(Arrays.asList(three, four, five))); |
78 |
|
} |
79 |
|
|
80 |
|
/** |
81 |
< |
* addAll adds each element from the given collection that did not |
82 |
< |
* already exist in the set |
81 |
> |
* addAll adds each non-duplicate element from the given collection |
82 |
|
*/ |
83 |
|
public void testAddAll2() { |
84 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
84 |
> |
Set full = populatedSet(3); |
85 |
|
// "one" is duplicate and will not be added |
86 |
|
assertTrue(full.addAll(Arrays.asList(three, four, one))); |
87 |
|
assertEquals(5, full.size()); |
93 |
|
* add will not add the element if it already exists in the set |
94 |
|
*/ |
95 |
|
public void testAdd2() { |
96 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
96 |
> |
Set full = populatedSet(3); |
97 |
|
full.add(one); |
98 |
|
assertEquals(3, full.size()); |
99 |
|
} |
102 |
|
* add adds the element when it does not exist in the set |
103 |
|
*/ |
104 |
|
public void testAdd3() { |
105 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
105 |
> |
Set full = populatedSet(3); |
106 |
|
full.add(three); |
107 |
|
assertTrue(full.contains(three)); |
108 |
|
} |
111 |
|
* clear removes all elements from the set |
112 |
|
*/ |
113 |
|
public void testClear() { |
114 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
114 |
> |
Collection full = populatedSet(3); |
115 |
|
full.clear(); |
116 |
|
assertEquals(0, full.size()); |
117 |
+ |
assertTrue(full.isEmpty()); |
118 |
|
} |
119 |
|
|
120 |
|
/** |
121 |
|
* contains returns true for added elements |
122 |
|
*/ |
123 |
|
public void testContains() { |
124 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
124 |
> |
Collection full = populatedSet(3); |
125 |
|
assertTrue(full.contains(one)); |
126 |
|
assertFalse(full.contains(five)); |
127 |
|
} |
148 |
|
* containsAll returns true for collections with subset of elements |
149 |
|
*/ |
150 |
|
public void testContainsAll() { |
151 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
151 |
> |
Collection full = populatedSet(3); |
152 |
|
assertTrue(full.containsAll(Arrays.asList())); |
153 |
|
assertTrue(full.containsAll(Arrays.asList(one))); |
154 |
|
assertTrue(full.containsAll(Arrays.asList(one, two))); |
160 |
|
* isEmpty is true when empty, else false |
161 |
|
*/ |
162 |
|
public void testIsEmpty() { |
163 |
< |
CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); |
164 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
165 |
< |
assertTrue(empty.isEmpty()); |
166 |
< |
assertFalse(full.isEmpty()); |
163 |
> |
assertTrue(populatedSet(0).isEmpty()); |
164 |
> |
assertFalse(populatedSet(3).isEmpty()); |
165 |
|
} |
166 |
|
|
167 |
|
/** |
201 |
|
* iterator remove is unsupported |
202 |
|
*/ |
203 |
|
public void testIteratorRemove() { |
204 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
204 |
> |
Collection full = populatedSet(3); |
205 |
|
Iterator it = full.iterator(); |
206 |
|
it.next(); |
207 |
|
try { |
215 |
|
*/ |
216 |
|
public void testToString() { |
217 |
|
assertEquals("[]", new CopyOnWriteArraySet().toString()); |
218 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
218 |
> |
Collection full = populatedSet(3); |
219 |
|
String s = full.toString(); |
220 |
|
for (int i = 0; i < 3; ++i) |
221 |
|
assertTrue(s.contains(String.valueOf(i))); |
227 |
|
* removeAll removes all elements from the given collection |
228 |
|
*/ |
229 |
|
public void testRemoveAll() { |
230 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
230 |
> |
Set full = populatedSet(3); |
231 |
|
assertTrue(full.removeAll(Arrays.asList(one, two))); |
232 |
|
assertEquals(1, full.size()); |
233 |
|
assertFalse(full.removeAll(Arrays.asList(one, two))); |
238 |
|
* remove removes an element |
239 |
|
*/ |
240 |
|
public void testRemove() { |
241 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
241 |
> |
Collection full = populatedSet(3); |
242 |
|
full.remove(one); |
243 |
|
assertFalse(full.contains(one)); |
244 |
|
assertEquals(2, full.size()); |
248 |
|
* size returns the number of elements |
249 |
|
*/ |
250 |
|
public void testSize() { |
251 |
< |
CopyOnWriteArraySet empty = new CopyOnWriteArraySet(); |
252 |
< |
CopyOnWriteArraySet full = populatedSet(3); |
251 |
> |
Collection empty = new CopyOnWriteArraySet(); |
252 |
> |
Collection full = populatedSet(3); |
253 |
|
assertEquals(3, full.size()); |
254 |
|
assertEquals(0, empty.size()); |
255 |
|
} |