Inlist:
- add Inlist.List size() - make Inlist work items indirectly extending Inlist - check Inlist.push() argument to not push lists
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.oscim.utils.pool;
|
||||
|
||||
import static java.lang.System.out;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@@ -75,6 +76,73 @@ public class InlistTest {
|
||||
assertEquals(i, 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveFirstInIterator() {
|
||||
List<Thing> list = new List<Thing>();
|
||||
list.push(new Thing(1));
|
||||
list.push(new Thing(2));
|
||||
list.push(new Thing(3));
|
||||
list.push(new Thing(4));
|
||||
list.push(new Thing(5));
|
||||
|
||||
out.println("\n shouldRemoveFirstInIterator");
|
||||
|
||||
int cnt = 5;
|
||||
for (Thing t : list) {
|
||||
list.remove();
|
||||
cnt--;
|
||||
assertEquals(cnt, list.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveSomeInIterator() {
|
||||
List<Thing> list = new List<Thing>();
|
||||
list.push(new Thing(1));
|
||||
list.push(new Thing(2));
|
||||
list.push(new Thing(3));
|
||||
list.push(new Thing(4));
|
||||
list.push(new Thing(5));
|
||||
list.push(new Thing(6));
|
||||
out.println("\n shouldRemoveSomeInIterator");
|
||||
|
||||
int pos = 0;
|
||||
for (Thing t : list) {
|
||||
if (pos++ % 2 == 0) {
|
||||
out.println(pos + " val:" + t.value);
|
||||
list.remove();
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(3, list.size());
|
||||
|
||||
for (Thing t : list) {
|
||||
out.println(t.value);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveLastInIterator() {
|
||||
List<Thing> list = new List<Thing>();
|
||||
list.append(new Thing(1));
|
||||
list.append(new Thing(2));
|
||||
out.println("\n shouldRemoveLastInIterator");
|
||||
|
||||
int pos = 0;
|
||||
for (Thing t : list) {
|
||||
if (pos++ == 1) {
|
||||
out.println(pos + " val:" + t.value);
|
||||
list.remove();
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(1, list.size());
|
||||
|
||||
for (Thing t : list) {
|
||||
out.println(t.value);
|
||||
}
|
||||
}
|
||||
|
||||
static class Thing extends Inlist<Thing> {
|
||||
final int value;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user