author | dl |
Fri, 23 Sep 2016 13:24:33 -0700 | |
changeset 41131 | 87edc8451f8a |
parent 23010 | 6dadb192ad81 |
child 43522 | f9c6f543c4db |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
19059
diff
changeset
|
2 |
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6207984 6268068 |
|
27 |
* @summary Test contains/remove equator compatibility |
|
28 |
* @author Martin Buchholz |
|
29 |
*/ |
|
30 |
||
41131
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
31 |
import java.util.ArrayDeque; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
32 |
import java.util.Arrays; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
33 |
import java.util.Comparator; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
34 |
import java.util.List; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
35 |
import java.util.PriorityQueue; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
36 |
import java.util.Queue; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
37 |
import java.util.concurrent.ArrayBlockingQueue; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
38 |
import java.util.concurrent.LinkedBlockingDeque; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
39 |
import java.util.concurrent.LinkedBlockingQueue; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
40 |
import java.util.concurrent.PriorityBlockingQueue; |
87edc8451f8a
8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
dl
parents:
23010
diff
changeset
|
41 |
import java.util.concurrent.LinkedTransferQueue; |
2 | 42 |
|
43 |
public class RemoveContains { |
|
44 |
static volatile int passed = 0, failed = 0; |
|
45 |
||
46 |
static void fail(String msg) { |
|
47 |
failed++; |
|
48 |
new AssertionError(msg).printStackTrace(); |
|
49 |
} |
|
50 |
||
51 |
static void pass() { |
|
52 |
passed++; |
|
53 |
} |
|
54 |
||
55 |
static void unexpected(Throwable t) { |
|
56 |
failed++; |
|
57 |
t.printStackTrace(); |
|
58 |
} |
|
59 |
||
60 |
static void check(boolean condition, String msg) { |
|
61 |
if (condition) |
|
62 |
passed++; |
|
63 |
else |
|
64 |
fail(msg); |
|
65 |
} |
|
66 |
||
67 |
static void check(boolean condition) { |
|
68 |
check(condition, "Assertion failure"); |
|
69 |
} |
|
70 |
||
71 |
public static void main(String[] args) { |
|
72 |
final Comparator<String> firstChar = new Comparator<String>() { |
|
73 |
public int compare(String x, String y) { |
|
74 |
return x.charAt(0) - y.charAt(0); }}; |
|
75 |
||
19059
510ac28edfef
8021601: Add unit test for PriorityQueue(Comparator) constructor
mduigou
parents:
5506
diff
changeset
|
76 |
test(new PriorityQueue<String>(firstChar)); |
2 | 77 |
test(new PriorityQueue<String>(10, firstChar)); |
78 |
test(new PriorityBlockingQueue<String>(10, firstChar)); |
|
79 |
test(new ArrayBlockingQueue<String>(10)); |
|
80 |
test(new LinkedBlockingQueue<String>(10)); |
|
81 |
test(new LinkedBlockingDeque<String>(10)); |
|
4110 | 82 |
test(new LinkedTransferQueue<String>()); |
2 | 83 |
test(new ArrayDeque<String>(10)); |
84 |
||
85 |
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
|
86 |
if (failed > 0) throw new Error("Some tests failed"); |
|
87 |
} |
|
88 |
||
89 |
private static void test(Queue<String> q) { |
|
90 |
try { |
|
91 |
List<String> words = |
|
92 |
Arrays.asList("foo", "fee", "fi", "fo", "fum", |
|
93 |
"Englishman"); |
|
94 |
q.addAll(words); |
|
95 |
for (String word : words) |
|
96 |
check(q.contains(word)); |
|
97 |
check(! q.contains("flurble")); |
|
98 |
||
99 |
check(q.remove("fi")); |
|
100 |
for (String word : words) |
|
101 |
check(q.contains(word) ^ word.equals("fi")); |
|
102 |
||
103 |
check(! q.remove("fi")); |
|
104 |
check(! q.remove("flurble")); |
|
105 |
||
106 |
} catch (Throwable t) { unexpected(t); } |
|
107 |
} |
|
108 |
} |