Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-07-04 09:59:12 +0000
committerEike Stepper2010-07-04 09:59:12 +0000
commit0f93ac386da1192b83829c280ff6ec5ca9040548 (patch)
tree67fc6ab89e6b182f0da9df106ea88623b040aa53 /plugins/org.eclipse.net4j.tests
parent707b6432c08bec2497b524fde9b92b01b1f2b59f (diff)
downloadcdo-0f93ac386da1192b83829c280ff6ec5ca9040548.tar.gz
cdo-0f93ac386da1192b83829c280ff6ec5ca9040548.tar.xz
cdo-0f93ac386da1192b83829c280ff6ec5ca9040548.zip
[318807] Add JavaDocs
https://bugs.eclipse.org/bugs/show_bug.cgi?id=318807
Diffstat (limited to 'plugins/org.eclipse.net4j.tests')
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java275
1 files changed, 275 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java
new file mode 100644
index 0000000000..57a42a3bfb
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java
@@ -0,0 +1,275 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.collection.FastList;
+
+/**
+ * @author Eike Stepper
+ * @since 3.0
+ */
+public class FastListTest extends AbstractOMTest
+{
+ public static void testAddFirst() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+
+ Integer[] result = list.get();
+ assertEquals(true, result != null);
+ assertEquals(true, result.length == 1);
+ assertEquals(true, list.getElements().length == 1);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 1);
+ assertEquals(true, list.removed == 0);
+ }
+
+ public static void testAddSecond() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+
+ Integer[] result = list.get();
+ assertEquals(true, result != null);
+ assertEquals(true, result.length == 2);
+ assertEquals(true, list.getElements().length == 2);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 1);
+ assertEquals(true, list.removed == 0);
+ }
+
+ public static void testRemoveHead() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+ list.add(2);
+ list.add(9);
+ list.add(1);
+ list.add(4);
+ list.add(8);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(5);
+
+ Integer[] result = list.get();
+ assertEquals(true, removed);
+ assertEquals(true, result != null);
+ assertEquals(true, result != old);
+ assertEquals(true, result.length == 6);
+ assertEquals(true, list.getElements().length == 6);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 7);
+ assertEquals(true, result[1] == 2);
+ assertEquals(true, result[2] == 9);
+ assertEquals(true, result[3] == 1);
+ assertEquals(true, result[4] == 4);
+ assertEquals(true, result[5] == 8);
+ }
+
+ public static void testRemoveMiddle() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+ list.add(2);
+ list.add(9);
+ list.add(1);
+ list.add(4);
+ list.add(8);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(9);
+
+ Integer[] result = list.get();
+ assertEquals(true, removed);
+ assertEquals(true, result != null);
+ assertEquals(true, result != old);
+ assertEquals(true, result.length == 6);
+ assertEquals(true, list.getElements().length == 6);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 5);
+ assertEquals(true, result[1] == 7);
+ assertEquals(true, result[2] == 2);
+ assertEquals(true, result[3] == 1);
+ assertEquals(true, result[4] == 4);
+ assertEquals(true, result[5] == 8);
+ }
+
+ public static void testRemoveTail() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+ list.add(2);
+ list.add(9);
+ list.add(1);
+ list.add(4);
+ list.add(8);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(8);
+
+ Integer[] result = list.get();
+ assertEquals(true, removed);
+ assertEquals(true, result != old);
+ assertEquals(true, result != null);
+ assertEquals(true, result.length == 6);
+ assertEquals(true, list.getElements().length == 6);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 5);
+ assertEquals(true, result[1] == 7);
+ assertEquals(true, result[2] == 2);
+ assertEquals(true, result[3] == 9);
+ assertEquals(true, result[4] == 1);
+ assertEquals(true, result[5] == 4);
+ }
+
+ public static void testRemoveLast() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+
+ Integer[] old = list.reset();
+ boolean removed1 = list.remove(7);
+ boolean removed2 = list.remove(5);
+
+ Integer[] result = list.get();
+ assertEquals(true, removed1);
+ assertEquals(true, removed2);
+ assertEquals(true, result != old);
+ assertEquals(true, result == null);
+ assertEquals(true, list.getElements() == null);
+ assertEquals(true, list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 1);
+ }
+
+ public static void testNotFoundInMany() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+ list.add(2);
+ list.add(9);
+ list.add(1);
+ list.add(4);
+ list.add(8);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(10);
+
+ Integer[] result = list.get();
+ assertEquals(true, !removed);
+ assertEquals(true, result != null);
+ assertEquals(true, result == old);
+ assertEquals(true, result.length == 7);
+ assertEquals(true, list.getElements().length == 7);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 5);
+ assertEquals(true, result[1] == 7);
+ assertEquals(true, result[2] == 2);
+ assertEquals(true, result[3] == 9);
+ assertEquals(true, result[4] == 1);
+ assertEquals(true, result[5] == 4);
+ assertEquals(true, result[6] == 8);
+ }
+
+ public static void testNotFoundInOne() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(10);
+
+ Integer[] result = list.get();
+ assertEquals(true, !removed);
+ assertEquals(true, result != null);
+ assertEquals(true, result == old);
+ assertEquals(true, result.length == 1);
+ assertEquals(true, list.getElements().length == 1);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 5);
+ }
+
+ public static void testNotFoundInEmpty() throws Exception
+ {
+ TestList list = new TestList();
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(10);
+
+ Integer[] result = list.get();
+ assertEquals(true, !removed);
+ assertEquals(true, result == null);
+ assertEquals(true, result == old);
+ assertEquals(true, list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class TestList extends FastList<Integer>
+ {
+ public int added;
+
+ public int removed;
+
+ public TestList()
+ {
+ }
+
+ public Integer[] getElements()
+ {
+ return elements;
+ }
+
+ public Integer[] reset()
+ {
+ added = 0;
+ removed = 0;
+ return elements;
+ }
+
+ @Override
+ protected Integer[] newArray(int length)
+ {
+ return new Integer[length];
+ }
+
+ @Override
+ protected void firstElementAdded()
+ {
+ ++added;
+ }
+
+ @Override
+ protected void lastElementRemoved()
+ {
+ ++removed;
+ }
+ }
+}

Back to the top