[cvs] / jsr166 / src / test / tck / LinkedListTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/LinkedListTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.22, Wed Nov 3 16:46:34 2010 UTC revision 1.27, Fri May 27 19:14:39 2011 UTC
# Line 1  Line 1 
1  /*  /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/licenses/publicdomain   * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.   * Pat Fisher, Mike Judd.
7   */   */
# Line 23  Line 23 
23       * Create a queue of given size containing consecutive       * Create a queue of given size containing consecutive
24       * Integers 0 ... n.       * Integers 0 ... n.
25       */       */
26      private LinkedList populatedQueue(int n) {      private LinkedList<Integer> populatedQueue(int n) {
27          LinkedList q = new LinkedList();          LinkedList<Integer> q = new LinkedList<Integer>();
28          assertTrue(q.isEmpty());          assertTrue(q.isEmpty());
29          for (int i = 0; i < n; ++i)          for (int i = 0; i < n; ++i)
30              assertTrue(q.offer(new Integer(i)));              assertTrue(q.offer(new Integer(i)));
# Line 233  Line 233 
233      public void testRemoveElement() {      public void testRemoveElement() {
234          LinkedList q = populatedQueue(SIZE);          LinkedList q = populatedQueue(SIZE);
235          for (int i = 1; i < SIZE; i+=2) {          for (int i = 1; i < SIZE; i+=2) {
236              assertTrue(q.remove(new Integer(i)));              assertTrue(q.contains(i));
237                assertTrue(q.remove((Integer)i));
238                assertFalse(q.contains(i));
239                assertTrue(q.contains(i-1));
240          }          }
241          for (int i = 0; i < SIZE; i+=2) {          for (int i = 0; i < SIZE; i+=2) {
242              assertTrue(q.remove(new Integer(i)));              assertTrue(q.contains(i));
243              assertFalse(q.remove(new Integer(i+1)));              assertTrue(q.remove((Integer)i));
244                assertFalse(q.contains(i));
245                assertFalse(q.remove((Integer)(i+1)));
246                assertFalse(q.contains(i+1));
247          }          }
248          assertTrue(q.isEmpty());          assertTrue(q.isEmpty());
249      }      }
# Line 318  Line 324 
324      }      }
325    
326      /**      /**
327       * toArray contains all elements       * toArray contains all elements in FIFO order
328       */       */
329      public void testToArray() {      public void testToArray() {
330          LinkedList q = populatedQueue(SIZE);          LinkedList q = populatedQueue(SIZE);
331          Object[] o = q.toArray();          Object[] o = q.toArray();
         Arrays.sort(o);  
332          for (int i = 0; i < o.length; i++)          for (int i = 0; i < o.length; i++)
333              assertEquals(o[i], q.poll());              assertSame(o[i], q.poll());
334      }      }
335    
336      /**      /**
337       * toArray(a) contains all elements       * toArray(a) contains all elements in FIFO order
338       */       */
339      public void testToArray2() {      public void testToArray2() {
340          LinkedList q = populatedQueue(SIZE);          LinkedList<Integer> q = populatedQueue(SIZE);
341          Integer[] ints = new Integer[SIZE];          Integer[] ints = new Integer[SIZE];
342          ints = (Integer[])q.toArray(ints);          Integer[] array = q.toArray(ints);
343          Arrays.sort(ints);          assertSame(ints, array);
344          for (int i = 0; i < ints.length; i++)          for (int i = 0; i < ints.length; i++)
345              assertEquals(ints[i], q.poll());              assertSame(ints[i], q.poll());
346      }      }
347    
348      /**      /**
# Line 463  Line 468 
468          assertFalse(it.hasNext());          assertFalse(it.hasNext());
469      }      }
470    
   
471      /**      /**
472       * toString contains toStrings of elements       * toString contains toStrings of elements
473       */       */
# Line 471  Line 475 
475          LinkedList q = populatedQueue(SIZE);          LinkedList q = populatedQueue(SIZE);
476          String s = q.toString();          String s = q.toString();
477          for (int i = 0; i < SIZE; ++i) {          for (int i = 0; i < SIZE; ++i) {
478              assertTrue(s.indexOf(String.valueOf(i)) >= 0);              assertTrue(s.contains(String.valueOf(i)));
479          }          }
480      }      }
481    
# Line 550  Line 554 
554          assertNull(q.peekFirst());          assertNull(q.peekFirst());
555      }      }
556    
   
557      /**      /**
558       * peekLast returns next element, or null if empty       * peekLast returns next element, or null if empty
559       */       */

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.27

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8