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

Annotation of /jsr166/src/test/tck/ArrayDeque8Test.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download)

1 : jsr166 1.1 /*
2 :     * Written by Doug Lea and Martin Buchholz with assistance from
3 :     * members of JCP JSR-166 Expert Group and released to the public
4 :     * domain, as explained at
5 :     * http://creativecommons.org/publicdomain/zero/1.0/
6 :     */
7 :    
8 :     import java.util.ArrayDeque;
9 :     import java.util.Collections;
10 :     import java.util.Spliterator;
11 :    
12 :     import junit.framework.Test;
13 :    
14 :     public class ArrayDeque8Test extends JSR166TestCase {
15 :     public static void main(String[] args) {
16 :     main(suite(), args);
17 :     }
18 :    
19 :     public static Test suite() {
20 :     return newTestSuite(ArrayDeque8Test.class);
21 :     }
22 :    
23 :     /**
24 :     * Spliterator.getComparator always throws IllegalStateException
25 :     */
26 :     public void testSpliterator_getComparator() {
27 :     assertThrows(IllegalStateException.class,
28 :     () -> new ArrayDeque().spliterator().getComparator());
29 :     }
30 :    
31 :     /**
32 :     * Spliterator characteristics are as advertised
33 :     */
34 :     public void testSpliterator_characteristics() {
35 :     ArrayDeque q = new ArrayDeque();
36 :     Spliterator s = q.spliterator();
37 :     int characteristics = s.characteristics();
38 :     int required = Spliterator.NONNULL
39 :     | Spliterator.ORDERED
40 :     | Spliterator.SIZED
41 :     | Spliterator.SUBSIZED;
42 :     assertEquals(required, characteristics & required);
43 :     assertTrue(s.hasCharacteristics(required));
44 :     assertEquals(0, characteristics
45 :     & (Spliterator.CONCURRENT
46 :     | Spliterator.DISTINCT
47 :     | Spliterator.IMMUTABLE
48 :     | Spliterator.SORTED));
49 :     }
50 :    
51 :     /**
52 :     * Handle capacities near Integer.MAX_VALUE.
53 : jsr166 1.2 * ant -Dvmoptions='-Xms28g -Xmx28g' -Djsr166.expensiveTests=true -Djsr166.tckTestClass=ArrayDeque8Test -Djsr166.methodFilter=testHugeCapacity tck
54 : jsr166 1.1 */
55 : jsr166 1.2 public void testHugeCapacity() {
56 : jsr166 1.1 if (! (testImplementationDetails
57 :     && expensiveTests
58 :     && Runtime.getRuntime().maxMemory() > 24L * (1 << 30)))
59 :     return;
60 :    
61 : jsr166 1.2 final Integer e = 42;
62 :     final int maxArraySize = Integer.MAX_VALUE - 8;
63 : jsr166 1.1
64 :     assertThrows(OutOfMemoryError.class,
65 : jsr166 1.2 () -> new ArrayDeque(Integer.MAX_VALUE));
66 : jsr166 1.1
67 :     {
68 : jsr166 1.2 ArrayDeque q = new ArrayDeque(maxArraySize - 1);
69 : jsr166 1.1 assertEquals(0, q.size());
70 :     assertTrue(q.isEmpty());
71 :     q = null;
72 :     }
73 :    
74 :     {
75 : jsr166 1.2 ArrayDeque q = new ArrayDeque();
76 :     assertTrue(q.addAll(Collections.nCopies(maxArraySize - 3, e)));
77 : jsr166 1.1 assertEquals(e, q.peekFirst());
78 :     assertEquals(e, q.peekLast());
79 : jsr166 1.2 assertEquals(maxArraySize - 3, q.size());
80 : jsr166 1.1 q.addFirst((Integer) 0);
81 :     q.addLast((Integer) 1);
82 :     assertEquals((Integer) 0, q.peekFirst());
83 :     assertEquals((Integer) 1, q.peekLast());
84 : jsr166 1.2 assertEquals(maxArraySize - 1, q.size());
85 : jsr166 1.1
86 :     ArrayDeque qq = q;
87 :     ArrayDeque smallish = new ArrayDeque(
88 : jsr166 1.2 Collections.nCopies(Integer.MAX_VALUE - q.size() + 1, e));
89 : jsr166 1.1 assertThrows(
90 :     IllegalStateException.class,
91 :     () -> qq.addAll(qq),
92 :     () -> qq.addAll(smallish),
93 :     () -> smallish.addAll(qq));
94 :     }
95 :     }
96 :    
97 :     }

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8