20 * questions.
21 */
22
23 /*
24 * This file is available under and governed by the GNU General Public
25 * License version 2 only, as published by the Free Software Foundation.
26 * However, the following notice accompanied the original version of this
27 * file:
28 *
29 * Written by Doug Lea with assistance from members of JCP JSR-166
30 * Expert Group and released to the public domain, as explained at
31 * http://creativecommons.org/publicdomain/zero/1.0/
32 * Other contributors include Andrew Wright, Jeffrey Hayes,
33 * Pat Fisher, Mike Judd.
34 */
35
36 import java.util.Arrays;
37 import java.util.Collection;
38 import java.util.Iterator;
39 import java.util.LinkedList;
40 import java.util.NoSuchElementException;
41
42 import junit.framework.Test;
43
44 public class LinkedListTest extends JSR166TestCase {
45 public static void main(String[] args) {
46 main(suite(), args);
47 }
48
49 public static Test suite() {
50 class Implementation implements CollectionImplementation {
51 public Class<?> klazz() { return LinkedList.class; }
52 public Collection emptyCollection() { return new LinkedList(); }
53 public Object makeElement(int i) { return i; }
54 public boolean isConcurrent() { return false; }
55 public boolean permitsNulls() { return true; }
56 }
57 class SubListImplementation extends Implementation {
58 public Collection emptyCollection() {
59 return new LinkedList().subList(0, 0);
60 }
61 }
62 return newTestSuite(
63 LinkedListTest.class,
64 CollectionTest.testSuite(new Implementation()),
65 CollectionTest.testSuite(new SubListImplementation()));
66 }
67
68 /**
69 * Returns a new queue of given size containing consecutive
70 * Integers 0 ... n - 1.
71 */
72 private static LinkedList<Integer> populatedQueue(int n) {
73 LinkedList<Integer> q = new LinkedList<>();
74 assertTrue(q.isEmpty());
75 for (int i = 0; i < n; ++i)
76 assertTrue(q.offer(new Integer(i)));
77 assertFalse(q.isEmpty());
78 assertEquals(n, q.size());
79 assertEquals((Integer) 0, q.peekFirst());
|
20 * questions.
21 */
22
23 /*
24 * This file is available under and governed by the GNU General Public
25 * License version 2 only, as published by the Free Software Foundation.
26 * However, the following notice accompanied the original version of this
27 * file:
28 *
29 * Written by Doug Lea with assistance from members of JCP JSR-166
30 * Expert Group and released to the public domain, as explained at
31 * http://creativecommons.org/publicdomain/zero/1.0/
32 * Other contributors include Andrew Wright, Jeffrey Hayes,
33 * Pat Fisher, Mike Judd.
34 */
35
36 import java.util.Arrays;
37 import java.util.Collection;
38 import java.util.Iterator;
39 import java.util.LinkedList;
40 import java.util.List;
41 import java.util.NoSuchElementException;
42 import java.util.concurrent.ThreadLocalRandom;
43
44 import junit.framework.Test;
45
46 public class LinkedListTest extends JSR166TestCase {
47 public static void main(String[] args) {
48 main(suite(), args);
49 }
50
51 public static Test suite() {
52 class Implementation implements CollectionImplementation {
53 public Class<?> klazz() { return LinkedList.class; }
54 public List emptyCollection() { return new LinkedList(); }
55 public Object makeElement(int i) { return i; }
56 public boolean isConcurrent() { return false; }
57 public boolean permitsNulls() { return true; }
58 }
59 class SubListImplementation extends Implementation {
60 public List emptyCollection() {
61 List list = super.emptyCollection();
62 ThreadLocalRandom rnd = ThreadLocalRandom.current();
63 if (rnd.nextBoolean())
64 list.add(makeElement(rnd.nextInt()));
65 int i = rnd.nextInt(list.size() + 1);
66 return list.subList(i, i);
67 }
68 }
69 return newTestSuite(
70 LinkedListTest.class,
71 CollectionTest.testSuite(new Implementation()),
72 CollectionTest.testSuite(new SubListImplementation()));
73 }
74
75 /**
76 * Returns a new queue of given size containing consecutive
77 * Integers 0 ... n - 1.
78 */
79 private static LinkedList<Integer> populatedQueue(int n) {
80 LinkedList<Integer> q = new LinkedList<>();
81 assertTrue(q.isEmpty());
82 for (int i = 0; i < n; ++i)
83 assertTrue(q.offer(new Integer(i)));
84 assertFalse(q.isEmpty());
85 assertEquals(n, q.size());
86 assertEquals((Integer) 0, q.peekFirst());
|