This is the mail archive of the mauve-patches@sources.redhat.com mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

java.util.Collections


Attached are some new tests for some of the methods in the
java.util.Collections class.  I get one failure with a fairly recent CVS
version of Classpath and JamVM 1.2.0, and zero failures with JDK 1.4.

dgilbert@linux42:~/workspace/mauve> jamvm -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
FAIL: gnu.testlet.java.util.Collections.rotate: uncaught exception at 
number 2
java.lang.ArithmeticException: division by zero
   at java.util.Collections.rotate (Collections.java:1113)
   at gnu.testlet.java.util.Collections.rotate.test (rotate.java:45)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:266)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:394)
1 of 47 tests failed
dgilbert@linux42:~/workspace/mauve> java -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
0 of 49 tests failed

Regards,

Dave Gilbert
www.jfree.org


// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.Collections;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class copy implements Testlet
{

  public void test(TestHarness harness)
  {
    List l1 = new ArrayList();
    List l2 = new ArrayList();
    
    // copy empty list
    Collections.copy(l2, l1);
    harness.check(l2.isEmpty());
    
    // copy a list with 1 item
    l1.add("A");
    l2.add("B");
    Collections.copy(l2, l1);
    harness.check(l2.get(0).equals("A"));
    
    // check that when destination is longer than source, the extra items are 
    // preserved...
    l1 = new ArrayList();
    l1.add("A");
    l2 = new ArrayList();
    l2.add("B"); l2.add("C"); l2.add("D");
    Collections.copy(l2, l1);
    harness.check(l2.get(0).equals("A"));
    harness.check(l2.get(1).equals("C"));
    harness.check(l2.get(2).equals("D"));
    
    // test where destination is shorter than source
    l1 = new ArrayList();
    l1.add("Item 1");
    l2 = new ArrayList();
    boolean pass = false;
    try
    {
      Collections.copy(l2, l1);
    }
    catch (IndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
    
    // test null argument 1
	pass = false;
	try
	{
	  Collections.copy(null, l1);
	}
	catch (NullPointerException e) 
	{
	  pass = true;
	}
	harness.check(pass);
	
	// test null argument 2
	try
	{
	  Collections.copy(l2, null);
	}
	catch (NullPointerException e) 
	{
	  pass = true;
	}
	harness.check(pass);
	
	// try read-only destination
	l1 = new ArrayList(); l1.add("A"); l1.add("B");
	l2 = new ArrayList(); l2.add("C"); l2.add("D");
	l2 = Collections.unmodifiableList(l2);
	pass = false;
	try
	{
	  Collections.copy(l2, l1);
	}
	catch (UnsupportedOperationException e)
	{
	  pass = true;
	}
	harness.check(pass);
	
  }

}
// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.Collections;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class fill implements Testlet
{

  public void test(TestHarness harness)
  {
    List list = new ArrayList();
 
    // fill empty list
    Collections.fill(list, "X");
    harness.check(list.isEmpty());
 
    // fill a list with 1 item
    list.add("A");
    Collections.fill(list, "X");
    harness.check(list.get(0).equals("X"));
 
    // fill a list with multiple items
    list = new ArrayList();
    list.add("A"); list.add("B"); list.add("C");

    Collections.fill(list, "X");
    harness.check(list.get(0).equals("X"));
    harness.check(list.get(1).equals("X"));
    harness.check(list.get(2).equals("X"));
  
    // test null argument 1
	boolean pass = false;
	try
	{
	  Collections.fill(null, "X");
	}
	catch (NullPointerException e) 
	{
	  pass = true;
	}
	harness.check(pass);
	
	// test null argument 2
	Collections.fill(list, null);
    harness.check(list.get(0) == null);
    harness.check(list.get(1) == null);
    harness.check(list.get(2) == null);
		
	// try read-only destination
	list = new ArrayList(); list.add("A"); list.add("B");
	list = Collections.unmodifiableList(list);
	pass = false;
	try
	{
	  Collections.fill(list, "X");
	}
	catch (UnsupportedOperationException e)
	{
	  pass = true;
	}
	harness.check(pass);
	
}

}
// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.Collections;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;

public class max implements Testlet
{

  public void test(TestHarness harness) 
  {
    List list = new ArrayList();
  
    // try an empty list
    boolean pass = false;
    try
    {
      Object m = Collections.max(list);
    }
    catch (NoSuchElementException e)
    {
      pass = true;
    }
    harness.check(true);
  
    // try a regular list
    list.add(new Integer(12));
    list.add(new Integer(9));
    list.add(new Integer(17));
    harness.check(Collections.max(list).equals(new Integer(17)));

    // try a null list
    pass = false;
    try
    {
      Object ignore = Collections.max(null);
    }
    catch (NullPointerException e) 
    {
      pass = true;
    }
    harness.check(pass);
  
    // try a list with non-comparable items
    list.clear();
    list.add("A"); list.add(new Long(1));
    pass = false;
    try
    {
      Object ignore = Collections.max(list);
    }
    catch (ClassCastException e) 
    {
      pass = true;
    }
    harness.check(pass);
  
  }
}
// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.Collections;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;

public class min implements Testlet
{

  public void test(TestHarness harness) 
  {
    List list = new ArrayList();
    
    // try an empty list
    boolean pass = false;
    try
    {
      Object m = Collections.min(list);
    }
    catch (NoSuchElementException e)
    {
      pass = true;
    }
    harness.check(true);
    
    // try a regular list
    list.add(new Integer(12));
    list.add(new Integer(9));
    list.add(new Integer(17));
    harness.check(Collections.min(list).equals(new Integer(9)));
 
    // try a null list
    pass = false;
    try
    {
      Object ignore = Collections.min(null);
    }
    catch (NullPointerException e) 
    {
      pass = true;
    }
    harness.check(pass);
    
    // try a list with non-comparable items
    list.clear();
    list.add("A"); list.add(new Long(1));
    pass = false;
    try
    {
      Object ignore = Collections.min(list);
    }
    catch (ClassCastException e) 
    {
      pass = true;
    }
    harness.check(pass);
    
  }
}
// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.Collections;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.util.Collections;
import java.util.List;

public class nCopies implements Testlet
{

  public void test(TestHarness harness) 
  {
    // try n = 0
    List list = Collections.nCopies(0, "Y");
    harness.check(list.isEmpty());

    // try n > 0
    list = Collections.nCopies(10, "X");
    harness.check(list.size() == 10);
    harness.check(list.get(0).equals("X"));
    harness.check(list.get(9).equals("X"));
    
    // try n < 0
    boolean pass = false;
    try
    {
      list = Collections.nCopies(-1, "X");
    }
    catch (IllegalArgumentException e) 
    {
      pass = true;
    }
    harness.check(pass);
    
    // try null object
    list = Collections.nCopies(3, null);
    harness.check(list.size() == 3);
    harness.check(list.get(0) == null);
    harness.check(list.get(1) == null);
    harness.check(list.get(2) == null);

    // confirm list is unmodifiable
    list = Collections.nCopies(10, "Y");
    pass = false;
    try
    {
      list.add("Z");
    }
    catch (UnsupportedOperationException e)
    {
      pass = true;
    }
    harness.check(pass);
 
    // the method should return a Serializable list
    testSerialization(harness);
  }
  
  private void testSerialization(TestHarness harness) 
  {
    List list1 = Collections.nCopies(99, "X");
    List list2 = null;

    try {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      ObjectOutput out = new ObjectOutputStream(buffer);
      out.writeObject(list1);
      out.close();

      ObjectInput in = new ObjectInputStream(
        new ByteArrayInputStream(buffer.toByteArray())
      );
      list2 = (List) in.readObject();
      in.close();
    }
    catch (Exception e) {
        harness.debug(e);
    }
    harness.check(list1.equals(list2));
  }
}
// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.Collections;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class reverse implements Testlet
{

  public void test(TestHarness harness) 
  {
    List list1 = new ArrayList();
    list1.add("t"); list1.add("a"); list1.add("n"); list1.add("k"); list1.add("s");
    List list2 = new ArrayList();
    list2.add("s"); list2.add("k"); list2.add("n"); list2.add("a"); list2.add("t"); 
    Collections.reverse(list1);
    harness.check(list1.equals(list2));    // check 1
 
    // try an empty list
    list1 = new ArrayList();
    Collections.reverse(list1);
    harness.check(list1.isEmpty());        // check 2
 
    // try a null list
    boolean pass = false;
    try
    {
      Collections.reverse(null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);                   // check 3
 
    // try an unmodifiable list
    list1 = Collections.unmodifiableList(list1);
    pass = false;
    try
    {
      Collections.reverse(null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);                   // check 4

  }
}
// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.Collections;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.util.Arrays;
import java.util.Collections;

public class reverseOrder implements Testlet
{

  public void test(TestHarness harness) 
  {
    String[] a = new String[] {"A", "B", "C"};
    Arrays.sort(a, Collections.reverseOrder());
    harness.check(a[0].equals("C"));
    harness.check(a[1].equals("B"));
    harness.check(a[2].equals("A"));
  }
}
// Tags: JDK1.4

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.util.Collections;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class rotate implements Testlet
{

  public void test(TestHarness harness) 
  {
    List list1 = new ArrayList();
    list1.add("t"); list1.add("a"); list1.add("n"); list1.add("k"); list1.add("s");
    List list2 = new ArrayList();
    list2.add("s"); list2.add("t"); list2.add("a"); list2.add("n"); list2.add("k"); 
    Collections.rotate(list1, -4);
    harness.check(list1.equals(list2));    // check 1
    
    // try an empty list
    list1 = new ArrayList();
    Collections.rotate(list1, 2);
    harness.check(list1.isEmpty());        // check 2
    
    // try a null list
    boolean pass = false;
    try
    {
      Collections.rotate(null, 2);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);                   // check 3
    
    // try an unmodifiable list
    list1 = Collections.unmodifiableList(list1);
    pass = false;
    try
    {
      Collections.rotate(null, 2);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);                   // check 4

  }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]