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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Fri Nov 18 03:19:20 2016 UTC (2 years, 9 months ago) by jsr166
Branch: MAIN
Changes since 1.1: +11 -12 lines
fix testHuge (actually test it!)

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 import junit.framework.TestSuite;
14
15 public class ArrayDeque8Test extends JSR166TestCase {
16 public static void main(String[] args) {
17 main(suite(), args);
18 }
19
20 public static Test suite() {
21 return newTestSuite(ArrayDeque8Test.class);
22 }
23
24 /**
25 * Spliterator.getComparator always throws IllegalStateException
26 */
27 public void testSpliterator_getComparator() {
28 assertThrows(IllegalStateException.class,
29 () -> new ArrayDeque().spliterator().getComparator());
30 }
31
32 /**
33 * Spliterator characteristics are as advertised
34 */
35 public void testSpliterator_characteristics() {
36 ArrayDeque q = new ArrayDeque();
37 Spliterator s = q.spliterator();
38 int characteristics = s.characteristics();
39 int required = Spliterator.NONNULL
40 | Spliterator.ORDERED
41 | Spliterator.SIZED
42 | Spliterator.SUBSIZED;
43 assertEquals(required, characteristics & required);
44 assertTrue(s.hasCharacteristics(required));
45 assertEquals(0, characteristics
46 & (Spliterator.CONCURRENT
47 | Spliterator.DISTINCT
48 | Spliterator.IMMUTABLE
49 | Spliterator.SORTED));
50 }
51
52 /**
53 * Handle capacities near Integer.MAX_VALUE.
54 * ant -Dvmoptions='-Xms28g -Xmx28g' -Djsr166.expensiveTests=true -Djsr166.tckTestClass=ArrayDeque8Test -Djsr166.methodFilter=testHugeCapacity tck
55 */
56 public void testHugeCapacity() {
57 if (! (testImplementationDetails
58 && expensiveTests
59 && Runtime.getRuntime().maxMemory() > 24L * (1 << 30)))
60 return;
61
62 final Integer e = 42;
63 final int maxArraySize = Integer.MAX_VALUE - 8;
64
65 assertThrows(OutOfMemoryError.class,
66 () -> new ArrayDeque(Integer.MAX_VALUE));
67
68 {
69 ArrayDeque q = new ArrayDeque(maxArraySize - 1);
70 assertEquals(0, q.size());
71 assertTrue(q.isEmpty());
72 q = null;
73 }
74
75 {
76 ArrayDeque q = new ArrayDeque();
77 assertTrue(q.addAll(Collections.nCopies(maxArraySize - 3, e)));
78 assertEquals(e, q.peekFirst());
79 assertEquals(e, q.peekLast());
80 assertEquals(maxArraySize - 3, q.size());
81 q.addFirst((Integer) 0);
82 q.addLast((Integer) 1);
83 assertEquals((Integer) 0, q.peekFirst());
84 assertEquals((Integer) 1, q.peekLast());
85 assertEquals(maxArraySize - 1, q.size());
86
87 ArrayDeque qq = q;
88 ArrayDeque smallish = new ArrayDeque(
89 Collections.nCopies(Integer.MAX_VALUE - q.size() + 1, e));
90 assertThrows(
91 IllegalStateException.class,
92 () -> qq.addAll(qq),
93 () -> qq.addAll(smallish),
94 () -> smallish.addAll(qq));
95 }
96 }
97
98 }

dl@cs.oswego.edu
ViewVC Help
Powered by ViewVC 1.1.27