Package: CompactLinkedHashSetTest

CompactLinkedHashSetTest

nameinstructionbranchcomplexitylinemethod
CompactLinkedHashSetTest()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createSet()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createSet(Collection)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createSet(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createSet(int, float)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
testIteratorOrder()
M: 150 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 38 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.eclipse.acceleo.common.tests.unit.utils;
2:
3: import static org.junit.Assert.assertEquals;
4: import static org.junit.Assert.assertFalse;
5: import static org.junit.Assert.assertTrue;
6:
7: import java.util.Collection;
8: import java.util.Collections;
9: import java.util.Iterator;
10: import java.util.Set;
11:
12: import org.eclipse.acceleo.common.utils.CompactLinkedHashSet;
13: import org.junit.Test;
14:
15: /**
16: * Tests for the {@link CompactLinkedHashSet} behavior.
17: * <p>
18: * Most of the tests for the {@link CompactLinkedHashSet} are simply inherited from the
19: * {@link CompactHashSetTest}s. We'll only add custom tests to check iteration order.
20: * </p>
21: *
22: * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
23: */
24: public class CompactLinkedHashSetTest extends CompactHashSetTest {
25:         /**
26:          * Checks that this set's entries are iterated over in insertion order.
27:          **/
28:         @Test
29:         public void testIteratorOrder() {
30:                 Collection<Integer> listInt10 = randomIntegerListNotIn(10, Collections.emptySet());
31:                 Collection<String> setString20 = randomStringSetNotIn(20, Collections.emptySet());
32:                 Collection<String> dequeString40 = randomStringDequeNotIn(40, setString20);
33:
34:                 Set<Object> set = createSet();
35:
36:                 set.addAll(listInt10);
37:                 set.addAll(setString20);
38:                 set.addAll(dequeString40);
39:
40:                 Iterator<Integer> listIterator = listInt10.iterator();
41:                 Iterator<String> setIterator = setString20.iterator();
42:                 Iterator<String> dequeIterator = dequeString40.iterator();
43:                 Iterator<Object> containedValues = set.iterator();
44:•                while (listIterator.hasNext()) {
45:                         assertEquals(listIterator.next(), containedValues.next());
46:                 }
47:                 assertTrue(containedValues.hasNext());
48:•                while (setIterator.hasNext()) {
49:                         assertEquals(setIterator.next(), containedValues.next());
50:                 }
51:                 assertTrue(containedValues.hasNext());
52:•                while (dequeIterator.hasNext()) {
53:                         assertEquals(dequeIterator.next(), containedValues.next());
54:                 }
55:                 assertFalse(containedValues.hasNext());
56:
57:•                for (Integer val : listInt10) {
58:                         set.remove(val);
59:                         assertFalse(set.contains(val));
60:                 }
61:                 set.addAll(listInt10);
62:
63:                 listIterator = listInt10.iterator();
64:                 setIterator = setString20.iterator();
65:                 dequeIterator = dequeString40.iterator();
66:                 containedValues = set.iterator();
67:•                while (setIterator.hasNext()) {
68:                         assertEquals(setIterator.next(), containedValues.next());
69:                 }
70:                 assertTrue(containedValues.hasNext());
71:•                while (dequeIterator.hasNext()) {
72:                         assertEquals(dequeIterator.next(), containedValues.next());
73:                 }
74:                 assertTrue(containedValues.hasNext());
75:•                while (listIterator.hasNext()) {
76:                         assertEquals(listIterator.next(), containedValues.next());
77:                 }
78:                 assertFalse(containedValues.hasNext());
79:         }
80:
81:         /**
82:          * {@inheritDoc}
83:          *
84:          * @see org.eclipse.acceleo.common.tests.unit.utils.CompactHashSetTest#createSet()
85:          */
86:         @Override
87:         protected Set<Object> createSet() {
88:                 return new CompactLinkedHashSet<Object>();
89:         }
90:
91:         /**
92:          * {@inheritDoc}
93:          *
94:          * @see org.eclipse.acceleo.common.tests.unit.utils.CompactHashSetTest#createSet(java.util.Collection)
95:          */
96:         @Override
97:         protected Set<Object> createSet(Collection<? extends Object> collection) {
98:                 return new CompactLinkedHashSet<Object>(collection);
99:         }
100:
101:         /**
102:          * {@inheritDoc}
103:          *
104:          * @see org.eclipse.acceleo.common.tests.unit.utils.CompactHashSetTest#createSet(int)
105:          */
106:         @Override
107:         protected Set<Object> createSet(int elementCount) {
108:                 return new CompactLinkedHashSet<Object>(elementCount);
109:         }
110:
111:         /**
112:          * {@inheritDoc}
113:          *
114:          * @see org.eclipse.acceleo.common.tests.unit.utils.CompactHashSetTest#createSet(int, float)
115:          */
116:         @Override
117:         protected Set<Object> createSet(int elementCount, float loadFactor) {
118:                 return new CompactLinkedHashSet<Object>(elementCount, loadFactor);
119:         }
120: }