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.3 by jsr166, Thu Oct 29 23:09:07 2009 UTC vs.
Revision 1.5 by jsr166, Mon Nov 16 04:57:09 2009 UTC

# Line 26 | Line 26 | public class DequeBash {
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;
29 >        seed = (t > 0) ? t : t + 0x7fffffff;
30          return (t & 0x7fffffff) % bound;
31      }
32  
33      static int random() {
34          int x = seed;
35          int t = (x % 127773) * 16807 - (x / 127773) * 2836;
36 <        seed = (t > 0)? t : t + 0x7fffffff;
36 >        seed = (t > 0) ? t : t + 0x7fffffff;
37          return (t & 0x7fffffff);
38      }
39  
# Line 157 | Line 157 | public class DequeBash {
157      static void randomOp(Deque<Integer> deque) throws Exception {
158  
159          // Perform a random operation
160 <        switch(random() & 3) {
160 >        switch (random() & 3) {
161          case 0:
162 <            switch(random() & 3) {
162 >            switch (random() & 3) {
163              case 0: deque.addLast(nextTail++);   break;
164              case 1: deque.offerLast(nextTail++); break;
165              case 2: deque.offer(nextTail++);     break;
# Line 172 | Line 172 | public class DequeBash {
172                  int result = 666;
173                  boolean threw = false;
174                  try {
175 <                    switch(random(3)) {
175 >                    switch (random(3)) {
176                      case 0: result = deque.removeFirst(); break;
177                      case 1: result = deque.remove();      break;
178                      case 2: result = deque.pop();         break;
179                      default: throw new Exception("How'd we get here");
180                      }
181 <                } catch(NoSuchElementException e) {
181 >                } catch (NoSuchElementException e) {
182                      threw = true;
183                  }
184                  if (!threw)
185                      throw new Exception("Remove-no exception: " + result);
186              } else { // deque nonempty
187                  int result = -1;
188 <                switch(random(5)) {
188 >                switch (random(5)) {
189                  case 0: result = deque.removeFirst(); break;
190                  case 1: result = deque.remove();      break;
191                  case 2: result = deque.pop();         break;
# Line 199 | Line 199 | public class DequeBash {
199              }
200              break;
201          case 2:
202 <            switch(random(3)) {
202 >            switch (random(3)) {
203              case 0: deque.addFirst(nextHead--);   break;
204              case 1: deque.offerFirst(nextHead--); break;
205              case 2: deque.push(nextHead--);       break;
# Line 212 | Line 212 | public class DequeBash {
212                  boolean threw = false;
213                  try {
214                      result = deque.removeLast();
215 <                } catch(NoSuchElementException e) {
215 >                } catch (NoSuchElementException e) {
216                      threw = true;
217                  }
218                  if (!threw)
219                      throw new Exception("Remove-no exception: " + result);
220              } else { // deque nonempty
221 <                int result = ((random() & 1) == 0?
221 >                int result = ((random() & 1) == 0 ?
222                                deque.removeLast() : deque.pollLast());
223                  if (result != --nextTail)
224                      throw new Exception(
225 <                                        "Removed "+ result + " expecting "+(nextTail + 1));
225 >                        "Removed "+ result + " expecting "+(nextTail + 1));
226              }
227              break;
228          default:
# Line 237 | Line 237 | public class DequeBash {
237          if (d1.size() != d2.size())
238              throw new Exception("Size " + d1.size() + " != " + d2.size());
239          Iterator<Integer> it = d2.iterator();
240 <        for(int i : d1) {
240 >        for (int i : d1) {
241              int j = it.next();
242              if (j != i)
243                  throw new Exception("Element " + j + " != " + i);
244          }
245  
246 <        for(int i : d1)
246 >        for (int i : d1)
247              if (!d2.contains(i))
248                  throw new Exception("d2 doesn't contain " + i);
249 <        for(int i : d2)
249 >        for (int i : d2)
250              if (!d1.contains(i))
251                  throw new Exception("d2 doesn't contain " + i);
252  
# Line 280 | Line 280 | public class DequeBash {
280                  bos.toByteArray());
281              ObjectInputStream ois = new ObjectInputStream(bin);
282              return (T) ois.readObject();
283 <        } catch(Exception e) {
283 >        } catch (Exception e) {
284              throw new IllegalArgumentException(e);
285          }
286      }
287  
288      private static void testRemove(Deque<Integer> deque) throws Exception {
289          Deque<Integer> copy = null;
290 <        switch(random() & 1) {
290 >        switch (random() & 1) {
291            case 0:
292              copy = (Deque<Integer>) deque.getClass().
293                  getConstructor(Collection.class).newInstance(deque);
# Line 320 | Line 320 | public class DequeBash {
320                  throw new Exception(e + " missing.");
321  
322              boolean removed = false;
323 <            switch(random(3)) {
323 >            switch (random(3)) {
324                  case 0:  removed = copy.remove(e);                break;
325                  case 1:  removed = copy.removeFirstOccurrence(e); break;
326                  case 2:  removed = copy.removeLastOccurrence(e);  break;
# Line 368 | Line 368 | public class DequeBash {
368              boolean threw = false;
369              int result = 666;
370              try {
371 <                result = ((random() & 1) == 0?
371 >                result = ((random() & 1) == 0 ?
372                            deque.getFirst() : deque.element());
373 <            } catch(NoSuchElementException e) {
373 >            } catch (NoSuchElementException e) {
374                  threw = true;
375              }
376              if (!threw)
# Line 378 | Line 378 | public class DequeBash {
378              threw = false;
379              try {
380                  result = deque.getLast();
381 <            } catch(NoSuchElementException e) {
381 >            } catch (NoSuchElementException e) {
382                  threw = true;
383              }
384              if (!threw)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines