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

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

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

revision 1.41, Sun Oct 16 20:44:18 2016 UTC revision 1.42, Sun Oct 16 22:13:15 2016 UTC
# Line 12  Line 12 
12  import java.util.NoSuchElementException;  import java.util.NoSuchElementException;
13  import java.util.Queue;  import java.util.Queue;
14  import java.util.Random;  import java.util.Random;
15    import java.util.concurrent.ThreadLocalRandom;
16    
17  import junit.framework.Test;  import junit.framework.Test;
18  import junit.framework.TestSuite;  import junit.framework.TestSuite;
# Line 38  Line 39 
39       * Integers 0 ... n - 1.       * Integers 0 ... n - 1.
40       */       */
41      private ArrayDeque<Integer> populatedDeque(int n) {      private ArrayDeque<Integer> populatedDeque(int n) {
42          ArrayDeque<Integer> q = new ArrayDeque<Integer>();          // Randomize various aspects of memory layout, including
43            // filled-to-capacity and wraparound.
44            final ArrayDeque<Integer> q;
45            ThreadLocalRandom rnd = ThreadLocalRandom.current();
46            switch (rnd.nextInt(6)) {
47            case 0: q = new ArrayDeque<Integer>(); break;
48            case 1: q = new ArrayDeque<Integer>(0); break;
49            case 2: q = new ArrayDeque<Integer>(1); break;
50            case 3: q = new ArrayDeque<Integer>(n - 1); break;
51            case 4: q = new ArrayDeque<Integer>(n); break;
52            case 5: q = new ArrayDeque<Integer>(n + 1); break;
53            default: throw new AssertionError();
54            }
55            switch (rnd.nextInt(3)) {
56            case 0:
57                q.addFirst(42);
58                assertEquals((Integer) 42, q.removeLast());
59                break;
60            case 1:
61                q.addLast(42);
62                assertEquals((Integer) 42, q.removeLast());
63                break;
64            case 2: /* do nothing */ break;
65            default: throw new AssertionError();
66            }
67          assertTrue(q.isEmpty());          assertTrue(q.isEmpty());
68          for (int i = 0; i < n; ++i)          if (rnd.nextBoolean())
69              assertTrue(q.offerLast(new Integer(i)));              for (int i = 0; i < n; i++)
70                    assertTrue(q.offerLast((Integer) i));
71            else
72                for (int i = n; --i >= 0; )
73                    q.addFirst((Integer) i);
74          assertFalse(q.isEmpty());          assertFalse(q.isEmpty());
75          assertEquals(n, q.size());          assertEquals(n, q.size());
76          assertEquals((Integer) 0, q.peekFirst());          assertEquals((Integer) 0, q.peekFirst());

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8