/
MultimapsTest.java
176 lines (164 loc) · 10.3 KB
/
MultimapsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Copyright (c) 2015 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.impl.factory;
import org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.multimap.list.ImmutableListMultimap;
import org.eclipse.collections.api.multimap.list.MutableListMultimap;
import org.eclipse.collections.api.multimap.set.ImmutableSetMultimap;
import org.eclipse.collections.api.multimap.set.MutableSetMultimap;
import org.eclipse.collections.api.multimap.sortedbag.ImmutableSortedBagMultimap;
import org.eclipse.collections.api.multimap.sortedset.ImmutableSortedSetMultimap;
import org.eclipse.collections.api.multimap.sortedset.MutableSortedSetMultimap;
import org.eclipse.collections.impl.multimap.bag.HashBagMultimap;
import org.eclipse.collections.impl.multimap.bag.sorted.mutable.TreeBagMultimap;
import org.eclipse.collections.impl.multimap.list.FastListMultimap;
import org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap;
import org.eclipse.collections.impl.multimap.set.sorted.TreeSortedSetMultimap;
import org.eclipse.collections.impl.test.Verify;
import org.eclipse.collections.impl.tuple.Tuples;
import org.junit.Assert;
import org.junit.Test;
public class MultimapsTest
{
@Test
public void immutableList()
{
ImmutableListMultimap<Integer, Integer> empty = Multimaps.immutable.list.of();
ImmutableListMultimap<Integer, Integer> emptyWith = Multimaps.immutable.list.with();
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
ImmutableListMultimap<Integer, Integer> one = Multimaps.immutable.list.of(1, 1);
Assert.assertEquals(FastListMultimap.newMultimap(Tuples.pair(1, 1)), one);
ImmutableListMultimap<Integer, Integer> two = Multimaps.immutable.list.of(1, 1, 2, 2);
Assert.assertEquals(FastListMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
ImmutableListMultimap<Integer, Integer> three = Multimaps.immutable.list.of(1, 1, 2, 2, 3, 3);
Assert.assertEquals(FastListMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void immutableSet()
{
ImmutableSetMultimap<Integer, Integer> empty = Multimaps.immutable.set.of();
ImmutableSetMultimap<Integer, Integer> emptyWith = Multimaps.immutable.set.with();
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
ImmutableSetMultimap<Integer, Integer> one = Multimaps.immutable.set.of(1, 1);
Assert.assertEquals(UnifiedSetMultimap.newMultimap(Tuples.pair(1, 1)), one);
ImmutableSetMultimap<Integer, Integer> two = Multimaps.immutable.set.of(1, 1, 2, 2);
Assert.assertEquals(UnifiedSetMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
ImmutableSetMultimap<Integer, Integer> three = Multimaps.immutable.set.of(1, 1, 2, 2, 3, 3);
Assert.assertEquals(UnifiedSetMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void immutableSortedSet()
{
ImmutableSortedSetMultimap<Integer, Integer> empty = Multimaps.immutable.sortedSet.of(Integer::compareTo);
ImmutableSortedSetMultimap<Integer, Integer> emptyWith = Multimaps.immutable.sortedSet.with(Integer::compareTo);
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
ImmutableSortedSetMultimap<Integer, Integer> one = Multimaps.immutable.sortedSet.of(Integer::compareTo, 1, 1);
Assert.assertEquals(TreeSortedSetMultimap.newMultimap(Tuples.pair(1, 1)), one);
ImmutableSortedSetMultimap<Integer, Integer> two = Multimaps.immutable.sortedSet.of(Integer::compareTo, 1, 1, 2, 2);
Assert.assertEquals(TreeSortedSetMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
ImmutableSortedSetMultimap<Integer, Integer> three = Multimaps.immutable.sortedSet.of(Integer::compareTo, 1, 1, 2, 2, 3, 3);
Assert.assertEquals(TreeSortedSetMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void immutableSortedBagMultimap()
{
ImmutableSortedBagMultimap<Integer, Integer> empty = Multimaps.immutable.multimap.of(Integer::compareTo);
ImmutableSortedBagMultimap<Integer, Integer> emptyWith = Multimaps.immutable.multimap.with(Integer::compareTo);
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
ImmutableSortedBagMultimap<Integer, Integer> one = Multimaps.immutable.multimap.of(Integer::compareTo, 1, 1);
Assert.assertEquals(TreeBagMultimap.newMultimap(Tuples.pair(1, 1)), one);
ImmutableSortedBagMultimap<Integer, Integer> two = Multimaps.immutable.multimap.of(Integer::compareTo, 1, 1, 2, 2);
ImmutableSortedBagMultimap<? extends Object, ? extends Object> toStringOffTwo = Multimaps.immutable.multimap.of(String::compareTo, "A", "B");
Assert.assertEquals(TreeBagMultimap.newMultimap(Tuples.pair("A", "B")), toStringOffTwo);
Assert.assertEquals(TreeBagMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
ImmutableSortedBagMultimap<Integer, Integer> three = Multimaps.immutable.multimap.of(Integer::compareTo, 1, 1, 2, 2, 3, 3);
Assert.assertEquals(TreeBagMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void immutableBag()
{
ImmutableBagMultimap<Integer, Integer> empty = Multimaps.immutable.bag.of();
ImmutableBagMultimap<Integer, Integer> emptyWith = Multimaps.immutable.bag.with();
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
ImmutableBagMultimap<Integer, Integer> one = Multimaps.immutable.bag.of(1, 1);
Assert.assertEquals(HashBagMultimap.newMultimap(Tuples.pair(1, 1)), one);
ImmutableBagMultimap<Integer, Integer> two = Multimaps.immutable.bag.of(1, 1, 2, 2);
Assert.assertEquals(HashBagMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
ImmutableBagMultimap<Integer, Integer> three = Multimaps.immutable.bag.of(1, 1, 2, 2, 3, 3);
Assert.assertEquals(HashBagMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void mutableList()
{
MutableListMultimap<Integer, Integer> empty = Multimaps.mutable.list.of();
MutableListMultimap<Integer, Integer> emptyWith = Multimaps.mutable.list.with();
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
MutableListMultimap<Integer, Integer> one = Multimaps.mutable.list.of(1, 1);
Assert.assertEquals(FastListMultimap.newMultimap(Tuples.pair(1, 1)), one);
MutableListMultimap<Integer, Integer> two = Multimaps.mutable.list.of(1, 1, 2, 2);
Assert.assertEquals(FastListMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
MutableListMultimap<Integer, Integer> three = Multimaps.mutable.list.of(1, 1, 2, 2, 3, 3);
Assert.assertEquals(FastListMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void mutableSet()
{
MutableSetMultimap<Integer, Integer> empty = Multimaps.mutable.set.of();
MutableSetMultimap<Integer, Integer> emptyWith = Multimaps.mutable.set.with();
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
MutableSetMultimap<Integer, Integer> one = Multimaps.mutable.set.of(1, 1);
Assert.assertEquals(UnifiedSetMultimap.newMultimap(Tuples.pair(1, 1)), one);
MutableSetMultimap<Integer, Integer> two = Multimaps.mutable.set.of(1, 1, 2, 2);
Assert.assertEquals(UnifiedSetMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
MutableSetMultimap<Integer, Integer> three = Multimaps.mutable.set.of(1, 1, 2, 2, 3, 3);
Assert.assertEquals(UnifiedSetMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void mutableSortedSet()
{
MutableSortedSetMultimap<Integer, Integer> empty = Multimaps.mutable.sortedSet.of(Integer::compareTo);
MutableSortedSetMultimap<Integer, Integer> emptyWith = Multimaps.mutable.sortedSet.with(Integer::compareTo);
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
MutableSortedSetMultimap<Integer, Integer> one = Multimaps.mutable.sortedSet.of(Integer::compareTo, 1, 1);
Assert.assertEquals(TreeSortedSetMultimap.newMultimap(Tuples.pair(1, 1)), one);
MutableSortedSetMultimap<Integer, Integer> two = Multimaps.mutable.sortedSet.of(Integer::compareTo, 1, 1, 2, 2);
Assert.assertEquals(TreeSortedSetMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
MutableSortedSetMultimap<Integer, Integer> three = Multimaps.mutable.sortedSet.of(Integer::compareTo, 1, 1, 2, 2, 3, 3);
Assert.assertEquals(TreeSortedSetMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void mutableBag()
{
MutableBagMultimap<Integer, Integer> empty = Multimaps.mutable.bag.of();
MutableBagMultimap<Integer, Integer> emptyWith = Multimaps.mutable.bag.with();
Verify.assertEmpty(empty);
Verify.assertEmpty(emptyWith);
MutableBagMultimap<Integer, Integer> one = Multimaps.mutable.bag.of(1, 1);
Assert.assertEquals(HashBagMultimap.newMultimap(Tuples.pair(1, 1)), one);
MutableBagMultimap<Integer, Integer> two = Multimaps.mutable.bag.of(1, 1, 2, 2);
Assert.assertEquals(HashBagMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2)), two);
MutableBagMultimap<Integer, Integer> three = Multimaps.mutable.bag.of(1, 1, 2, 2, 3, 3);
Assert.assertEquals(HashBagMultimap.newMultimap(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 3)), three);
}
@Test
public void classIsNonInstantiable()
{
Verify.assertClassNonInstantiable(Multimaps.class);
}
}