* FYI: Mauve tests for CopyOnWriteArrayList
@ 2007-11-24 22:37 Mario Torre
0 siblings, 0 replies; only message in thread
From: Mario Torre @ 2007-11-24 22:37 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 1206 bytes --]
I've added these few tests to mauve.
Thanks,
Mario
2007-11-24 Mario Torre <neugens@limasoftware.net>
* gnu/testlet/java/util/concurrent/CopyOnWriteArrayList: new
package.
*
gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java:
test.
*
gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java:
likewise.
*
gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java:
likewise.
*
gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java:
likewise.
*
gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java:
likewise.
*
gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java:
likewise.
*
gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java:
likewise.
--
Lima Software - http://www.limasoftware.net/
GNU Classpath Developer - http://www.classpath.org/
Fedora Ambassador - http://fedoraproject.org/wiki/MarioTorre
Jabber: neugens@jabber.org
pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA FC7C 4086 63E3 80F2 40CF
Please, support open standards:
http://opendocumentfellowship.org/petition/
http://www.nosoftwarepatents.com/
[-- Attachment #2: 2007-11-24-copy-on-write-array-list-mauve.patch --]
[-- Type: text/x-patch, Size: 20051 bytes --]
### Eclipse Workspace Patch 1.0
#P mauve
Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java
===================================================================
RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java
diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,142 @@
+/* AddAllTest.java -- test for addAll.
+ Copyright (C) 2007 Mario Torre <neugens@limasoftware.net>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.5
+
+package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class AddAllTest implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ testAdd(harness);
+ testExceptions(harness);
+ }
+
+ private void testExceptions(TestHarness harness)
+ {
+ CopyOnWriteArrayList<Integer> list =
+ new CopyOnWriteArrayList<Integer>();
+
+ List<Integer> list2 = new ArrayList<Integer>();
+ list2.add(0);
+
+ harness.checkPoint("addAll - IndexOutOfBoundsException");
+
+ try
+ {
+ // try with index < 0 first
+ list.addAll(-1, list2);
+
+ // we should not get here
+ harness.check(false);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ harness.check(true);
+ }
+ catch (Exception e)
+ {
+ harness.check(false, "Exception of unexpected type: " + e.getMessage());
+ }
+
+ list.add(0);
+ list.add(1);
+
+ try
+ {
+ // try with index > list.size() first
+ list.addAll(list.size() + 1, list2);
+
+ // we should not get here
+ harness.check(false);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ harness.check(true);
+ }
+ catch (Exception e)
+ {
+ harness.check(false, "Exception of unexpected type: " + e.getMessage());
+ }
+
+ harness.checkPoint("addAll - NullPointerException");
+
+ try
+ {
+ // finally try NullPointerException
+ list.addAll(null);
+
+ // we should not get here
+ harness.check(false);
+ }
+ catch (NullPointerException e)
+ {
+ harness.check(true);
+ }
+ catch (Exception e)
+ {
+ harness.check(false, "Exception of unexpected type: " + e.getMessage());
+ }
+ }
+
+ private void testAdd(TestHarness harness)
+ {
+ harness.checkPoint("addAll");
+
+ int [] expected =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
+ };
+
+ CopyOnWriteArrayList<Integer> list =
+ new CopyOnWriteArrayList<Integer>();
+
+ for (int i = 0; i < 10; i++)
+ list.add(i);
+
+ List<Integer> list2 = new ArrayList<Integer>();
+ for (int i = 5; i < 15; i++)
+ list2.add(i);
+
+ list.addAll(list2);
+
+ harness.check(list.size() == 20);
+
+ int i = 0;
+ for (ListIterator<Integer> elements = list.listIterator();
+ elements.hasNext();)
+ {
+ harness.check(elements.next().intValue() == expected[i++]);
+ }
+ }
+}
Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java
===================================================================
RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java
diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,153 @@
+/* TestIterators.java -- test for the Iterator and ListIterator methods.
+ Copyright (C) 2007 Mario Torre <neugens@limasoftware.net>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.5
+
+package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class TestIterators implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ iteratorTests(harness);
+ listIteratorTests(harness);
+ }
+
+ private void listIteratorTests(TestHarness harness)
+ {
+ harness.checkPoint("listIterator");
+
+ int [] expected =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9
+ };
+
+ CopyOnWriteArrayList<Integer> list =
+ new CopyOnWriteArrayList<Integer>();
+
+ java.util.List<Integer> data = new ArrayList<Integer>();
+
+ for (int i = 0; i < 10; i++)
+ data.add(i);
+
+ // list.add copy the storage array each time is called, adding elements
+ // that way we avoid all this copying
+ list.addAll(data);
+
+ ListIterator<Integer> iterator = list.listIterator();
+ int i = 0;
+
+ harness.checkPoint("listIterator - forward");
+
+ while (iterator.hasNext())
+ harness.check(iterator.next().intValue() == expected[i++]);
+
+ harness.checkPoint("listIterator - backward");
+
+ while (iterator.hasPrevious())
+ harness.check(iterator.previous().intValue() == expected[--i]);
+
+ harness.checkPoint("listIterator - forward from element");
+
+ iterator = list.listIterator(5);
+ i = 5;
+
+ while (iterator.hasNext())
+ harness.check(iterator.next().intValue() == expected[i++]);
+
+ harness.checkPoint("listIterator - backward from element");
+
+ while (iterator.hasPrevious())
+ harness.check(iterator.previous().intValue() == expected[--i]);
+ }
+
+ private void iteratorTests(TestHarness harness)
+ {
+ harness.checkPoint("iterator");
+
+ int [] expected =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+ };
+
+ CopyOnWriteArrayList<Integer> list =
+ new CopyOnWriteArrayList<Integer>();
+
+ java.util.List<Integer> data = new ArrayList<Integer>();
+
+ for (int i = 0; i < 10; i++)
+ data.add(i);
+
+ // list.add copy the storage array each time is called, adding elements
+ // that way we avoid all this copying
+ list.addAll(data);
+
+ int i = 0;
+ for (Iterator<Integer> iterator = list.iterator(); iterator.hasNext(); )
+ {
+ harness.check(iterator.next().intValue() == expected[i++]);
+ }
+
+ harness.checkPoint("iterator - snapshot");
+ Iterator<Integer> iterator = list.iterator();
+
+ list.clear();
+
+ harness.check(list.size() == 0);
+
+ // the iterator contains a snapshot of the list so resetting the list
+ // has no effect to the content of the iterator.
+
+ i = 0;
+ while (iterator.hasNext())
+ harness.check(iterator.next().intValue() == expected[i++]);
+
+ harness.checkPoint("iterator - remove");
+
+ list.addAll(data);
+
+ try
+ {
+ for (Iterator<Integer> iter = list.iterator(); iter.hasNext(); )
+ {
+ iter.remove();
+ harness.check(false);
+ }
+
+ harness.check(false);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ harness.check(true);
+ }
+ }
+}
Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java
===================================================================
RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java
diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,65 @@
+/* RetainAllTest.java -- test for retainAll
+ Copyright (C) 2007 Mario Torre <neugens@limasoftware.net>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+ */
+
+// Tags: JDK1.5
+
+
+package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class RetainAllTest
+ implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ CopyOnWriteArrayList<Integer> list =
+ new CopyOnWriteArrayList<Integer>();
+
+ for (int i = 0; i < 10; i++)
+ list.add(i);
+
+ List<Integer> list2 = new ArrayList<Integer>();
+ for (int i = 5; i < 15; i++)
+ list2.add(i);
+
+ list.retainAll(list2);
+
+ harness.check(list.size() == 5);
+
+ int i = 5;
+ for (ListIterator<Integer> elements = list.listIterator();
+ elements.hasNext();)
+ {
+ harness.check(elements.next().intValue() == i);
+ i++;
+ }
+ }
+}
Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java
===================================================================
RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java
diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,38 @@
+/* SubListTest.java -- Test for subList.
+ Copyright (C) 2007 Mario Torre <neugens@liamasoftware.net>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.5
+
+package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * @author Mario Torre <neugens@liamasoftware.net>
+ */
+public class SubListTest implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+
+ }
+}
Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java
===================================================================
RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java
diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,64 @@
+/* AddAllAbsentTest.java -- test for addAllAbsent.
+ Copyright (C) 2007 Mario Torre <neugens@limasoftware.net>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.5
+
+package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class AddAllAbsentTest implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ for (int i = 0; i < 10; i++)
+ {
+ list.add("#" + i);
+ }
+
+ List<String> list2 = new ArrayList<String>();
+
+ for (int i = 9; i < 20; i++)
+ list2.add("#" + i);
+
+ list.addAllAbsent(list2);
+
+ harness.check(list.size() == 20);
+
+ int i = 0;
+ for (ListIterator<String> elements = list.listIterator();
+ elements.hasNext();)
+ {
+ harness.check(elements.next().equals("#" + i));
+ i++;
+ }
+ }
+}
Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java
===================================================================
RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java
diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,72 @@
+/* RemoveTest.java -- test for remove.
+ Copyright (C) 2007 Mario Torre <neugens@limasoftware.net>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.5
+
+package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class RemoveTest implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ CopyOnWriteArrayList<Integer> list =
+ new CopyOnWriteArrayList<Integer>();
+
+ List<Integer> data = new ArrayList<Integer>();
+ for (int i = 0; i < 10; i++)
+ data.add(i);
+
+ list.addAll(data);
+
+ harness.check(list.size() == 10);
+
+ Integer el = list.remove(5);
+
+ harness.check(el.intValue() == 5);
+ harness.check(list.size() == 9);
+
+ harness.check(list.add(el));
+ harness.check(list.size() == 10);
+
+ harness.check(list.remove(el));
+ harness.check(list.size() == 9);
+
+ int [] expected =
+ {
+ 0, 1, 2, 3, 4, 6, 7, 8, 9
+ };
+
+ int i = 0;
+ for (Iterator<Integer> iterator = list.iterator(); iterator.hasNext(); )
+ harness.check(iterator.next().intValue() == expected[i++]);
+ }
+}
Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java
===================================================================
RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java
diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,66 @@
+/* RemoveAllTest.java -- test for removeAll.
+ Copyright (C) 2007 Mario Torre <neugens@limasoftware.net>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+ */
+
+// Tags: JDK1.5
+
+
+package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class RemoveAllTest
+ implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ for (int i = 0; i < 10; i++)
+ {
+ list.add("#" + i);
+ }
+
+ List<String> list2 = new ArrayList<String>();
+
+ for (int i = 3; i < 20; i++)
+ list2.add("#" + i);
+
+ list.removeAll(list2);
+
+ harness.check(list.size() == 3);
+
+ int i = 0;
+ for (ListIterator<String> elements = list.listIterator();
+ elements.hasNext();)
+ {
+ harness.check(elements.next().equals("#" + i));
+ i++;
+ }
+ }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-11-24 22:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-24 22:37 FYI: Mauve tests for CopyOnWriteArrayList Mario Torre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).