-
Notifications
You must be signed in to change notification settings - Fork 587
/
UnsortedMapIterableTestCase.java
111 lines (96 loc) · 4.11 KB
/
UnsortedMapIterableTestCase.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
/*
* 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.map;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.UnsortedBag;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.map.UnsortedMapIterable;
import org.eclipse.collections.test.UnorderedIterableTestCase;
import org.eclipse.collections.test.bag.TransformsToBagTrait;
import org.junit.Test;
import static org.eclipse.collections.test.IterableTestCase.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isOneOf;
public interface UnsortedMapIterableTestCase
extends MapIterableTestCase, UnorderedIterableTestCase, TransformsToBagTrait
{
@Override
<T> UnsortedMapIterable<Object, T> newWith(T... elements);
@Override
default <T> UnsortedBag<T> getExpectedFiltered(T... elements)
{
return Bags.immutable.with(elements);
}
@Override
default <T> MutableBag<T> newMutableForFilter(T... elements)
{
return Bags.mutable.with(elements);
}
@Override
default void Iterable_toString()
{
MapIterable<String, Integer> map = this.newWithKeysValues("Two", 2, "One", 1);
assertThat(map.toString(), isOneOf("{One=1, Two=2}", "{Two=2, One=1}"));
assertThat(map.keysView().toString(), isOneOf("[One, Two]", "[Two, One]"));
assertThat(map.valuesView().toString(), isOneOf("[1, 2]", "[2, 1]"));
assertThat(map.keyValuesView().toString(), isOneOf("[One:1, Two:2]", "[Two:2, One:1]"));
assertThat(map.asLazy().toString(), isOneOf("[1, 2]", "[2, 1]"));
}
@Override
@Test
default void RichIterable_makeString_appendString()
{
RichIterable<Integer> iterable = this.newWith(2, 2, 1);
assertThat(iterable.makeString(), isOneOf("2, 2, 1", "1, 2, 2", "2, 1, 2"));
assertThat(iterable.makeString("/"), isOneOf("2/2/1", "1/2/2", "2/1/2"));
assertThat(iterable.makeString("[", "/", "]"), isOneOf("[2/2/1]", "[1/2/2]", "[2/1/2]"));
StringBuilder builder1 = new StringBuilder();
iterable.appendString(builder1);
assertThat(builder1.toString(), isOneOf("2, 2, 1", "1, 2, 2", "2, 1, 2"));
StringBuilder builder2 = new StringBuilder();
iterable.appendString(builder2, "/");
assertThat(builder2.toString(), isOneOf("2/2/1", "1/2/2", "2/1/2"));
StringBuilder builder3 = new StringBuilder();
iterable.appendString(builder3, "[", "/", "]");
assertThat(builder3.toString(), isOneOf("[2/2/1]", "[1/2/2]", "[2/1/2]"));
}
@Override
@Test
default void RichIterable_toList()
{
UnsortedMapIterable<Object, Integer> iterable = this.newWith(2, 2, 1);
assertThat(
iterable.toList(),
isOneOf(
Lists.immutable.with(2, 2, 1),
Lists.immutable.with(1, 2, 2),
Lists.immutable.with(2, 1, 2)));
MutableList<Integer> target = Lists.mutable.empty();
iterable.each(target::add);
assertEquals(
target,
iterable.toList());
}
@Override
@Test
default void RichIterable_into()
{
assertThat(
this.newWith(2, 2, 1).into(Lists.mutable.empty()),
isOneOf(
Lists.immutable.with(2, 2, 1),
Lists.immutable.with(1, 2, 2),
Lists.immutable.with(2, 1, 2)));
}
}