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

Comparing jsr166/src/test/loops/DequeBash.java (file contents):
Revision 1.2 by dl, Fri Sep 16 11:15:56 2005 UTC vs.
Revision 1.3 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 22 | Line 22 | public class DequeBash {
22      static int nextHead = -1;
23      static int size() { return nextTail - nextHead - 1; }
24  
25 <    
26 <    static int random(int bound) {
25 >
26 >    static int random(int bound) {
27          int x = seed;
28          int t = (x % 127773) * 16807 - (x / 127773) * 2836;
29          seed = (t > 0)? t : t + 0x7fffffff;
30          return (t & 0x7fffffff) % bound;
31      }
32  
33 <    static int random() {
33 >    static int random() {
34          int x = seed;
35          int t = (x % 127773) * 16807 - (x / 127773) * 2836;
36          seed = (t > 0)? t : t + 0x7fffffff;
# Line 75 | Line 75 | public class DequeBash {
75                  testEqual(deque, (Deque<Integer>) deque.getClass().
76                            getConstructor(Collection.class).newInstance(deque));
77              }
78 <            
78 >
79              // Test fancy removal stuff once in a blue moon
80              if ((i & 8191) == 0)
81                  testRemove(deque);
82 <            
82 >
83           }
84  
85          // Stupid tests for clear, toString
# Line 91 | Line 91 | public class DequeBash {
91              throw new Exception("Deque.toString():  " + deque.toString());
92      }
93  
94 <    static void testIter(Deque<Integer> deque) throws Exception {                
94 >    static void testIter(Deque<Integer> deque) throws Exception {
95          int next = nextHead + 1;
96          int count = 0;
97          for (int j : deque) {
# Line 103 | Line 103 | public class DequeBash {
103              throw new Exception("Count " + count + " != " + size());
104      }
105  
106 <    static void testDescendingIter(Deque<Integer> deque) throws Exception {                
106 >    static void testDescendingIter(Deque<Integer> deque) throws Exception {
107          int next = deque.size() + nextHead;
108          int count = 0;
109          for (Iterator<Integer> it = deque.descendingIterator(); it.hasNext();) {
# Line 124 | Line 124 | public class DequeBash {
124              throw new Exception(
125                                  "IsEmpty " + deque.isEmpty() + ", size " + size());
126          // Check head and tail
127 <        if (size() == 0)
127 >        if (size() == 0)
128              testEmpty(deque);
129 <        else
129 >        else
130              nonEmptyTest(deque);
131  
132      }
133  
134 <    static void nonEmptyTest(Deque<Integer> deque) throws Exception {            
134 >    static void nonEmptyTest(Deque<Integer> deque) throws Exception {
135          if (deque.getFirst() != nextHead + 1)
136 <            throw new Exception("getFirst got: " +
136 >            throw new Exception("getFirst got: " +
137                                  deque.getFirst() + " expecting " + (nextHead + 1));
138          if (deque.element() != nextHead + 1)
139              throw new Exception("element got: " + deque.element() +
# Line 144 | Line 144 | public class DequeBash {
144          if (deque.peek() != nextHead + 1)
145              throw new Exception("peek got: " +  deque.peek() +
146                                  " expecting " + (nextHead + 1));
147 <        
147 >
148          if (deque.peekLast() != nextTail - 1)
149              throw new Exception("peekLast got: " + deque.peekLast() +
150                                  " expecting " + (nextTail - 1));
151          if (deque.getLast() != nextTail - 1)
152 <            throw new Exception("getLast got: " +
152 >            throw new Exception("getLast got: " +
153                                  deque.getLast() + " expecting " + (nextTail - 1));
154 <    }        
155 <    
154 >    }
155 >
156  
157      static void randomOp(Deque<Integer> deque) throws Exception {
158 <        
158 >
159          // Perform a random operation
160          switch(random() & 3) {
161          case 0:
# Line 324 | Line 324 | public class DequeBash {
324                  case 0:  removed = copy.remove(e);                break;
325                  case 1:  removed = copy.removeFirstOccurrence(e); break;
326                  case 2:  removed = copy.removeLastOccurrence(e);  break;
327 <                default: throw new Exception("How'd we get here");            
327 >                default: throw new Exception("How'd we get here");
328              }
329              if (!removed)
330                  throw new Exception(e + " not removed.");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines