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

Comparing jsr166/src/test/extra166y/ParallelArrayAsListTest.java (file contents):
Revision 1.2 by jsr166, Mon Nov 16 04:16:43 2009 UTC vs.
Revision 1.4 by jsr166, Wed Sep 1 07:20:36 2010 UTC

# Line 16 | Line 16 | import java.io.*;
16   public class ParallelArrayAsListTest extends JSR166TestCase{
17  
18      public static void main(String[] args) {
19 <        junit.textui.TestRunner.run (suite());
19 >        junit.textui.TestRunner.run (suite());
20      }
21  
22      public static Test suite() {
23 <        return new TestSuite(ParallelArrayAsListTest.class);
23 >        return new TestSuite(ParallelArrayAsListTest.class);
24      }
25  
26      static List populatedArray(int n){
27 <        List a = ParallelArray.createEmpty(n, Object.class, ParallelArray.defaultExecutor()).asList();
27 >        List a = ParallelArray.createEmpty(n, Object.class, ParallelArray.defaultExecutor()).asList();
28          assertTrue(a.isEmpty());
29          for (int i = 0; i < n; ++i)
30              a.add(new Integer(i));
# Line 35 | Line 35 | public class ParallelArrayAsListTest ext
35  
36  
37      static List emptyArray(){
38 <        List a = ParallelArray.createEmpty(1, Object.class, ParallelArray.defaultExecutor()).asList();
38 >        List a = ParallelArray.createEmpty(1, Object.class, ParallelArray.defaultExecutor()).asList();
39          return a;
40      }
41  
# Line 44 | Line 44 | public class ParallelArrayAsListTest ext
44       * a new list is empty
45       */
46      public void testConstructor() {
47 <        List a = ParallelArray.createEmpty(1, Object.class, ParallelArray.defaultExecutor()).asList();
47 >        List a = ParallelArray.createEmpty(1, Object.class, ParallelArray.defaultExecutor()).asList();
48          assertTrue(a.isEmpty());
49      }
50  
# Line 55 | Line 55 | public class ParallelArrayAsListTest ext
55          Integer[] ints = new Integer[SIZE];
56          for (int i = 0; i < SIZE-1; ++i)
57              ints[i] = new Integer(i);
58 <        List a = ParallelArray.createUsingHandoff(ints, ParallelArray.defaultExecutor()).asList();
58 >        List a = ParallelArray.createUsingHandoff(ints, ParallelArray.defaultExecutor()).asList();
59          for (int i = 0; i < SIZE; ++i)
60              assertEquals(ints[i], a.get(i));
61      }
# Line 65 | Line 65 | public class ParallelArrayAsListTest ext
65       *   addAll  adds each element from the given collection
66       */
67      public void testAddAll() {
68 <        List full = populatedArray(3);
69 <        Vector v = new Vector();
70 <        v.add(three);
71 <        v.add(four);
72 <        v.add(five);
73 <        full.addAll(v);
74 <        assertEquals(6, full.size());
68 >        List full = populatedArray(3);
69 >        Vector v = new Vector();
70 >        v.add(three);
71 >        v.add(four);
72 >        v.add(five);
73 >        full.addAll(v);
74 >        assertEquals(6, full.size());
75      }
76  
77      /**
78       *   clear removes all elements from the list
79       */
80      public void testClear() {
81 <        List full = populatedArray(SIZE);
82 <        full.clear();
83 <        assertEquals(0, full.size());
81 >        List full = populatedArray(SIZE);
82 >        full.clear();
83 >        assertEquals(0, full.size());
84      }
85  
86  
# Line 89 | Line 89 | public class ParallelArrayAsListTest ext
89       *   contains is true for added elements
90       */
91      public void testContains() {
92 <        List full = populatedArray(3);
93 <        assertTrue(full.contains(one));
94 <        assertFalse(full.contains(five));
92 >        List full = populatedArray(3);
93 >        assertTrue(full.contains(one));
94 >        assertFalse(full.contains(five));
95      }
96  
97      /**
98       * adding at an index places it in the indicated index
99       */
100      public void testAddIndex() {
101 <        List full = populatedArray(3);
101 >        List full = populatedArray(3);
102          full.add(0, m1);
103          assertEquals(4, full.size());
104          assertEquals(m1, full.get(0));
# Line 114 | Line 114 | public class ParallelArrayAsListTest ext
114       * lists with same elements are equal and have same hashCode
115       */
116      public void testEquals() {
117 <        List a = populatedArray(3);
118 <        List b = populatedArray(3);
117 >        List a = populatedArray(3);
118 >        List b = populatedArray(3);
119          assertTrue(a.equals(b));
120          assertTrue(b.equals(a));
121          assertEquals(a.hashCode(), b.hashCode());
# Line 133 | Line 133 | public class ParallelArrayAsListTest ext
133       *   containsAll returns true for collection with subset of elements
134       */
135      public void testContainsAll() {
136 <        List full = populatedArray(3);
137 <        Vector v = new Vector();
138 <        v.add(one);
139 <        v.add(two);
140 <        assertTrue(full.containsAll(v));
141 <        v.add(six);
142 <        assertFalse(full.containsAll(v));
136 >        List full = populatedArray(3);
137 >        Vector v = new Vector();
138 >        v.add(one);
139 >        v.add(two);
140 >        assertTrue(full.containsAll(v));
141 >        v.add(six);
142 >        assertFalse(full.containsAll(v));
143      }
144  
145      /**
146       *   get returns the  value at the given index
147       */
148      public void testGet() {
149 <        List full = populatedArray(3);
150 <        assertEquals(0, ((Integer)full.get(0)).intValue());
149 >        List full = populatedArray(3);
150 >        assertEquals(0, ((Integer)full.get(0)).intValue());
151      }
152  
153      /**
154       *   indexOf gives the index for the given object
155       */
156      public void testIndexOf() {
157 <        List full = populatedArray(3);
158 <        assertEquals(1, full.indexOf(one));
159 <        assertEquals(-1, full.indexOf("puppies"));
157 >        List full = populatedArray(3);
158 >        assertEquals(1, full.indexOf(one));
159 >        assertEquals(-1, full.indexOf("puppies"));
160      }
161  
162      /**
163       *   isEmpty returns true when empty, else false
164       */
165      public void testIsEmpty() {
166 <        List empty = emptyArray();
167 <        List full = populatedArray(SIZE);
168 <        assertTrue(empty.isEmpty());
169 <        assertFalse(full.isEmpty());
166 >        List empty = emptyArray();
167 >        List full = populatedArray(SIZE);
168 >        assertTrue(empty.isEmpty());
169 >        assertFalse(full.isEmpty());
170      }
171  
172      /**
173       *   iterator() returns an iterator containing the elements of the list
174       */
175      public void testIterator() {
176 <        List full = populatedArray(SIZE);
177 <        Iterator i = full.iterator();
178 <        int j;
179 <        for(j = 0; i.hasNext(); j++)
180 <            assertEquals(j, ((Integer)i.next()).intValue());
181 <        assertEquals(SIZE, j);
176 >        List full = populatedArray(SIZE);
177 >        Iterator i = full.iterator();
178 >        int j;
179 >        for (j = 0; i.hasNext(); j++)
180 >            assertEquals(j, ((Integer)i.next()).intValue());
181 >        assertEquals(SIZE, j);
182      }
183  
184      /**
185       * iterator.remove removes element
186       */
187      public void testIteratorRemove () {
188 <        List full = populatedArray(SIZE);
188 >        List full = populatedArray(SIZE);
189          Iterator it = full.iterator();
190          Object first = full.get(0);
191          it.next();
# Line 197 | Line 197 | public class ParallelArrayAsListTest ext
197       * toString contains toString of elements
198       */
199      public void testToString() {
200 <        List full = populatedArray(3);
200 >        List full = populatedArray(3);
201          String s = full.toString();
202          for (int i = 0; i < 3; ++i) {
203              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
# Line 208 | Line 208 | public class ParallelArrayAsListTest ext
208       *   lastIndexOf returns the index for the given object
209       */
210      public void testLastIndexOf1() {
211 <        List full = populatedArray(3);
212 <        full.add(one);
213 <        full.add(three);
214 <        assertEquals(3, full.lastIndexOf(one));
215 <        assertEquals(-1, full.lastIndexOf(six));
211 >        List full = populatedArray(3);
212 >        full.add(one);
213 >        full.add(three);
214 >        assertEquals(3, full.lastIndexOf(one));
215 >        assertEquals(-1, full.lastIndexOf(six));
216      }
217  
218      /**
219       *  listIterator traverses all elements
220       */
221      public void testListIterator1() {
222 <        List full = populatedArray(SIZE);
223 <        ListIterator i = full.listIterator();
224 <        int j;
225 <        for(j = 0; i.hasNext(); j++)
226 <            assertEquals(j, ((Integer)i.next()).intValue());
227 <        assertEquals(SIZE, j);
222 >        List full = populatedArray(SIZE);
223 >        ListIterator i = full.listIterator();
224 >        int j;
225 >        for (j = 0; i.hasNext(); j++)
226 >            assertEquals(j, ((Integer)i.next()).intValue());
227 >        assertEquals(SIZE, j);
228      }
229  
230      /**
231       *  listIterator only returns those elements after the given index
232       */
233      public void testListIterator2() {
234 <        List full = populatedArray(3);
235 <        ListIterator i = full.listIterator(1);
236 <        int j;
237 <        for(j = 0; i.hasNext(); j++)
238 <            assertEquals(j+1, ((Integer)i.next()).intValue());
239 <        assertEquals(2, j);
234 >        List full = populatedArray(3);
235 >        ListIterator i = full.listIterator(1);
236 >        int j;
237 >        for (j = 0; i.hasNext(); j++)
238 >            assertEquals(j+1, ((Integer)i.next()).intValue());
239 >        assertEquals(2, j);
240      }
241  
242      /**
243       *   remove  removes and returns the object at the given index
244       */
245      public void testRemove() {
246 <        List full = populatedArray(3);
247 <        assertEquals(two, full.remove(2));
248 <        assertEquals(2, full.size());
246 >        List full = populatedArray(3);
247 >        assertEquals(two, full.remove(2));
248 >        assertEquals(2, full.size());
249      }
250  
251      /**
252       *   removeAll  removes all elements from the given collection
253       */
254      public void testRemoveAll() {
255 <        List full = populatedArray(3);
256 <        Vector v = new Vector();
257 <        v.add(one);
258 <        v.add(two);
259 <        full.removeAll(v);
260 <        assertEquals(1, full.size());
255 >        List full = populatedArray(3);
256 >        Vector v = new Vector();
257 >        v.add(one);
258 >        v.add(two);
259 >        full.removeAll(v);
260 >        assertEquals(1, full.size());
261      }
262  
263      /**
264       *   set  changes the element at the given index
265       */
266      public void testSet() {
267 <        List full = populatedArray(3);
268 <        assertEquals(two, full.set(2, four));
269 <        assertEquals(4, ((Integer)full.get(2)).intValue());
267 >        List full = populatedArray(3);
268 >        assertEquals(two, full.set(2, four));
269 >        assertEquals(4, ((Integer)full.get(2)).intValue());
270      }
271  
272      /**
273       *   size returns the number of elements
274       */
275      public void testSize() {
276 <        List empty = emptyArray();
277 <        List full = populatedArray(SIZE);
278 <        assertEquals(SIZE, full.size());
279 <        assertEquals(0, empty.size());
276 >        List empty = emptyArray();
277 >        List full = populatedArray(SIZE);
278 >        assertEquals(SIZE, full.size());
279 >        assertEquals(0, empty.size());
280      }
281  
282      /**
283       *   toArray returns an Object array containing all elements from the list
284       */
285      public void testToArray() {
286 <        List full = populatedArray(3);
287 <        Object[] o = full.toArray();
288 <        assertEquals(3, o.length);
289 <        assertEquals(0, ((Integer)o[0]).intValue());
290 <        assertEquals(1, ((Integer)o[1]).intValue());
291 <        assertEquals(2, ((Integer)o[2]).intValue());
286 >        List full = populatedArray(3);
287 >        Object[] o = full.toArray();
288 >        assertEquals(3, o.length);
289 >        assertEquals(0, ((Integer)o[0]).intValue());
290 >        assertEquals(1, ((Integer)o[1]).intValue());
291 >        assertEquals(2, ((Integer)o[2]).intValue());
292      }
293  
294      /**
# Line 296 | Line 296 | public class ParallelArrayAsListTest ext
296       *   the list
297       */
298      public void testToArray2() {
299 <        List full = populatedArray(3);
300 <        Integer[] i = new Integer[3];
301 <        i = (Integer[])full.toArray(i);
302 <        assertEquals(3, i.length);
303 <        assertEquals(0, i[0].intValue());
304 <        assertEquals(1, i[1].intValue());
305 <        assertEquals(2, i[2].intValue());
299 >        List full = populatedArray(3);
300 >        Integer[] i = new Integer[3];
301 >        i = (Integer[])full.toArray(i);
302 >        assertEquals(3, i.length);
303 >        assertEquals(0, i[0].intValue());
304 >        assertEquals(1, i[1].intValue());
305 >        assertEquals(2, i[2].intValue());
306      }
307  
308  
# Line 310 | Line 310 | public class ParallelArrayAsListTest ext
310       * sublists contains elements at indexes offset from their base
311       */
312      public void testSubList() {
313 <        List a = populatedArray(10);
313 >        List a = populatedArray(10);
314          assertTrue(a.subList(1,1).isEmpty());
315 <        for(int j = 0; j < 9; ++j) {
316 <            for(int i = j ; i < 10; ++i) {
317 <                List b = a.subList(j,i);
318 <                for(int k = j; k < i; ++k) {
319 <                    assertEquals(new Integer(k), b.get(k-j));
320 <                }
321 <            }
322 <        }
315 >        for (int j = 0; j < 9; ++j) {
316 >            for (int i = j ; i < 10; ++i) {
317 >                List b = a.subList(j,i);
318 >                for (int k = j; k < i; ++k) {
319 >                    assertEquals(new Integer(k), b.get(k-j));
320 >                }
321 >            }
322 >        }
323  
324 <        List s = a.subList(2, 5);
324 >        List s = a.subList(2, 5);
325          assertEquals(s.size(), 3);
326          s.set(2, m1);
327          assertEquals(a.get(4), m1);
328 <        s.clear();
328 >        s.clear();
329          assertEquals(a.size(), 7);
330      }
331  
# Line 341 | Line 341 | public class ParallelArrayAsListTest ext
341              c.add("zfasdfsdf");
342              c.add("asdadasd");
343              c.toArray(new Long[5]);
344 <            shouldThrow();
345 <        } catch(ArrayStoreException e){}
344 >            shouldThrow();
345 >        } catch (ArrayStoreException e){}
346      }
347  
348      /**
# Line 353 | Line 353 | public class ParallelArrayAsListTest ext
353              List c = emptyArray();
354              c.get(-1);
355              shouldThrow();
356 <        } catch(IndexOutOfBoundsException e){}
356 >        } catch (IndexOutOfBoundsException e){}
357      }
358  
359      /**
# Line 366 | Line 366 | public class ParallelArrayAsListTest ext
366              c.add("asdad");
367              c.get(100);
368              shouldThrow();
369 <        } catch(IndexOutOfBoundsException e){}
369 >        } catch (IndexOutOfBoundsException e){}
370      }
371  
372      /**
# Line 377 | Line 377 | public class ParallelArrayAsListTest ext
377              List c = emptyArray();
378              c.set(-1,"qwerty");
379              shouldThrow();
380 <        } catch(IndexOutOfBoundsException e){}
380 >        } catch (IndexOutOfBoundsException e){}
381      }
382  
383      /**
# Line 390 | Line 390 | public class ParallelArrayAsListTest ext
390              c.add("asdad");
391              c.set(100, "qwerty");
392              shouldThrow();
393 <        } catch(IndexOutOfBoundsException e){}
393 >        } catch (IndexOutOfBoundsException e){}
394      }
395  
396      /**
# Line 401 | Line 401 | public class ParallelArrayAsListTest ext
401              List c = emptyArray();
402              c.add(-1,"qwerty");
403              shouldThrow();
404 <        } catch(IndexOutOfBoundsException e){}
404 >        } catch (IndexOutOfBoundsException e){}
405      }
406  
407      /**
# Line 414 | Line 414 | public class ParallelArrayAsListTest ext
414              c.add("asdasdasd");
415              c.add(100, "qwerty");
416              shouldThrow();
417 <        } catch(IndexOutOfBoundsException e){}
417 >        } catch (IndexOutOfBoundsException e){}
418      }
419  
420      /**
# Line 425 | Line 425 | public class ParallelArrayAsListTest ext
425              List c = emptyArray();
426              c.remove(-1);
427              shouldThrow();
428 <        } catch(IndexOutOfBoundsException e){}
428 >        } catch (IndexOutOfBoundsException e){}
429      }
430  
431      /**
# Line 438 | Line 438 | public class ParallelArrayAsListTest ext
438              c.add("adasdasd");
439              c.remove(100);
440              shouldThrow();
441 <        } catch(IndexOutOfBoundsException e){}
441 >        } catch (IndexOutOfBoundsException e){}
442      }
443  
444      /**
# Line 449 | Line 449 | public class ParallelArrayAsListTest ext
449              List c = emptyArray();
450              c.addAll(-1,new LinkedList());
451              shouldThrow();
452 <        } catch(IndexOutOfBoundsException e){}
452 >        } catch (IndexOutOfBoundsException e){}
453      }
454  
455      /**
# Line 462 | Line 462 | public class ParallelArrayAsListTest ext
462              c.add("asdasdasd");
463              c.addAll(100, new LinkedList());
464              shouldThrow();
465 <        } catch(IndexOutOfBoundsException e){}
465 >        } catch (IndexOutOfBoundsException e){}
466      }
467  
468      /**
# Line 473 | Line 473 | public class ParallelArrayAsListTest ext
473              List c = emptyArray();
474              c.listIterator(-1);
475              shouldThrow();
476 <        } catch(IndexOutOfBoundsException e){}
476 >        } catch (IndexOutOfBoundsException e){}
477      }
478  
479      /**
# Line 486 | Line 486 | public class ParallelArrayAsListTest ext
486              c.add("asdasdas");
487              c.listIterator(100);
488              shouldThrow();
489 <        } catch(IndexOutOfBoundsException e){}
489 >        } catch (IndexOutOfBoundsException e){}
490      }
491  
492      /**
# Line 498 | Line 498 | public class ParallelArrayAsListTest ext
498              c.subList(-1,100);
499  
500              shouldThrow();
501 <        } catch(IndexOutOfBoundsException e){}
501 >        } catch (IndexOutOfBoundsException e){}
502      }
503  
504      /**
# Line 510 | Line 510 | public class ParallelArrayAsListTest ext
510              c.add("asdasd");
511              c.subList(1,100);
512              shouldThrow();
513 <        } catch(IndexOutOfBoundsException e){}
513 >        } catch (IndexOutOfBoundsException e){}
514      }
515  
516      /**
# Line 523 | Line 523 | public class ParallelArrayAsListTest ext
523              c.subList(3,1);
524  
525              shouldThrow();
526 <        } catch(IndexOutOfBoundsException e){}
526 >        } catch (IndexOutOfBoundsException e){}
527      }
528  
529  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines