-
Notifications
You must be signed in to change notification settings - Fork 587
/
HashBiMapInverseTest.java
55 lines (47 loc) · 1.78 KB
/
HashBiMapInverseTest.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
/*
* Copyright (c) 2022 Goldman Sachs and others.
* 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.test.bimap.mutable;
import java.util.Random;
import org.eclipse.collections.api.bimap.MutableBiMap;
import org.eclipse.collections.impl.bimap.mutable.HashBiMap;
import org.eclipse.collections.impl.test.junit.Java8Runner;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
@RunWith(Java8Runner.class)
public class HashBiMapInverseTest implements MutableBiMapTestCase
{
private static final long CURRENT_TIME_MILLIS = System.currentTimeMillis();
@Override
public <T> MutableBiMap<Object, T> newWith(T... elements)
{
Random random = new Random(CURRENT_TIME_MILLIS);
MutableBiMap<T, Object> result = new HashBiMap<>();
for (T each : elements)
{
assertNull(result.put(each, random.nextDouble()));
}
return result.inverse();
}
@Override
public <K, V> MutableBiMap<K, V> newWithKeysValues(Object... elements)
{
if (elements.length % 2 != 0)
{
fail(String.valueOf(elements.length));
}
MutableBiMap<V, K> result = new HashBiMap<>();
for (int i = 0; i < elements.length; i += 2)
{
assertNull(result.put((V) elements[i + 1], (K) elements[i]));
}
return result.inverse();
}
}