-
Notifications
You must be signed in to change notification settings - Fork 587
/
BooleanHashBagTest.java
136 lines (122 loc) · 4.91 KB
/
BooleanHashBagTest.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
/*
* 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.bag.mutable.primitive;
import java.util.NoSuchElementException;
import org.eclipse.collections.api.bag.primitive.MutableBooleanBag;
import org.eclipse.collections.api.iterator.BooleanIterator;
import org.eclipse.collections.api.list.primitive.MutableBooleanList;
import org.eclipse.collections.api.set.primitive.MutableBooleanSet;
import org.eclipse.collections.impl.factory.primitive.BooleanSets;
import org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList;
import org.eclipse.collections.impl.test.Verify;
import org.junit.Assert;
import org.junit.Test;
/**
* JUnit test for {@link BooleanHashBag}.
*/
public class BooleanHashBagTest extends AbstractMutableBooleanBagTestCase
{
@Override
protected BooleanHashBag classUnderTest()
{
return BooleanHashBag.newBagWith(true, false, true);
}
@Override
protected BooleanHashBag newWith(boolean... elements)
{
return BooleanHashBag.newBagWith(elements);
}
@Override
@Test
public void newCollection()
{
super.newCollection();
Assert.assertEquals(
BooleanHashBag.newBagWith(true, false, true, false, true),
BooleanHashBag.newBag(BooleanArrayList.newListWith(true, false, true, false, true)));
}
@Override
@Test
public void size()
{
super.size();
Verify.assertSize(3, BooleanHashBag.newBagWith(true, false, true));
Verify.assertSize(3, new BooleanHashBag(BooleanHashBag.newBagWith(true, false, true)));
Verify.assertSize(3, new BooleanHashBag(BooleanArrayList.newListWith(true, false, true)));
}
@Override
@Test
public void with()
{
super.with();
BooleanHashBag hashBag = new BooleanHashBag().with(true);
BooleanHashBag emptyBag = new BooleanHashBag();
BooleanHashBag hashBag0 = emptyBag.with(true, false);
BooleanHashBag hashBag1 = new BooleanHashBag().with(true, false, true);
BooleanHashBag hashBag2 = new BooleanHashBag().with(true).with(false).with(true).with(false);
BooleanHashBag hashBag3 = new BooleanHashBag().with(true).with(false).with(true).with(false).with(true);
Assert.assertSame(emptyBag, hashBag0);
Assert.assertEquals(BooleanHashBag.newBagWith(true), hashBag);
Assert.assertEquals(BooleanHashBag.newBagWith(true, false), hashBag0);
Assert.assertEquals(BooleanHashBag.newBagWith(true, false, true), hashBag1);
Assert.assertEquals(BooleanHashBag.newBagWith(true, false, true, false), hashBag2);
Assert.assertEquals(BooleanHashBag.newBagWith(true, false, true, false, true), hashBag3);
}
@Override
@Test
public void booleanIterator()
{
super.booleanIterator();
BooleanHashBag bag = this.newWith(true, false, false, true, true, true);
BooleanIterator iterator = bag.booleanIterator();
Assert.assertTrue(iterator.hasNext());
Assert.assertFalse(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertFalse(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.next());
Assert.assertFalse(iterator.hasNext());
Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator::next);
}
@Override
@Test
public void appendString()
{
super.appendString();
StringBuilder appendable2 = new StringBuilder();
BooleanHashBag bag1 = this.newWith(false, false, true);
bag1.appendString(appendable2);
Assert.assertEquals(appendable2.toString(), "false, false, true", appendable2.toString());
}
@Override
@Test
public void toList()
{
super.toList();
MutableBooleanList list = this.newWith(true, true, true, false).toList();
Assert.assertEquals(list, BooleanArrayList.newListWith(false, true, true, true));
}
@Override
@Test
public void selectUnique()
{
super.selectUnique();
MutableBooleanBag bag = this.classUnderTest();
MutableBooleanSet expected = BooleanSets.mutable.with(false);
MutableBooleanSet actual = bag.selectUnique();
Assert.assertEquals(expected, actual);
}
}