commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example Quicksort.java
Date Fri, 21 Feb 2003 00:12:29 GMT
rwaldhoff    2003/02/20 16:12:29

  Modified:    functor/src/java/org/apache/commons/functor/core/comparator
                        ComparatorFunction.java
               functor/src/test/org/apache/commons/functor/core/collection
                        TestAll.java TestPredicatedIterator.java
               functor/src/test/org/apache/commons/functor/core/comparator
                        TestAll.java TestComparatorFunction.java
               functor/src/test/org/apache/commons/functor/example
                        Quicksort.java
  Added:       functor/src/test/org/apache/commons/functor/core/collection
                        TestIsEmpty.java TestSize.java
  Log:
  add some tests
  
  Revision  Changes    Path
  1.2       +6 -11     jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
  
  Index: ComparatorFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComparatorFunction.java	20 Feb 2003 01:12:40 -0000	1.1
  +++ ComparatorFunction.java	21 Feb 2003 00:12:28 -0000	1.2
  @@ -70,11 +70,11 @@
    */
   public final class ComparatorFunction implements BinaryFunction, Serializable {
       public ComparatorFunction() {
  -        this(ComparableComparator.getInstance());
  +        this(null);
       }
   
       public ComparatorFunction(Comparator comparator) {
  -        this.comparator = comparator;
  +        this.comparator = null == comparator ? ComparableComparator.getInstance() : comparator;
       }
       
       /**
  @@ -99,19 +99,14 @@
        * @see #equals(Object)
        */
       public boolean equals(ComparatorFunction that) {
  -        return null != that && 
  -            null == comparator ? null == that.comparator : comparator.equals(that.comparator);
  +        return null != that && comparator.equals(that.comparator);
       }
   
       /**
        * @see java.lang.Object#hashCode()
        */
       public int hashCode() {
  -        int hash = "ComparatorFunction".hashCode();
  -        if(null != comparator) {
  -            hash ^= comparator.hashCode();
  -        }
  -        return hash;
  +        return "ComparatorFunction".hashCode() ^ comparator.hashCode();
       }
   
       /**
  
  
  
  1.2       +5 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestAll.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestAll.java	19 Feb 2003 00:54:37 -0000	1.1
  +++ TestAll.java	21 Feb 2003 00:12:28 -0000	1.2
  @@ -73,6 +73,9 @@
           TestSuite suite = new TestSuite();
           
           suite.addTest(TestCollectionAlgorithms.suite());
  +        suite.addTest(TestPredicatedIterator.suite());
  +        suite.addTest(TestIsEmpty.suite());
  +        suite.addTest(TestSize.suite());
           
           return suite;
       }
  
  
  
  1.2       +87 -2     jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestPredicatedIterator.java
  
  Index: TestPredicatedIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestPredicatedIterator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestPredicatedIterator.java	20 Feb 2003 01:12:41 -0000	1.1
  +++ TestPredicatedIterator.java	21 Feb 2003 00:12:28 -0000	1.2
  @@ -60,6 +60,7 @@
   import java.util.Collections;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.NoSuchElementException;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
  @@ -149,6 +150,90 @@
           assertTrue(!testing.hasNext());
       }
   
  +    public void testNextWithoutHasNext() {
  +        Iterator testing = new PredicatedIterator(isEven,list.iterator());
  +        Iterator expected = evens.iterator();
  +        while(expected.hasNext()) {
  +            assertEquals(expected.next(),testing.next());
  +        }
  +        assertTrue(!(testing.hasNext()));
  +    }
  +
  +    public void testNextAfterEndOfList() {
  +        Iterator testing = new PredicatedIterator(isEven,list.iterator());
  +        Iterator expected = evens.iterator();
  +        while(expected.hasNext()) {
  +            assertEquals(expected.next(),testing.next());
  +        }
  +        try {
  +            testing.next();
  +            fail("ExpectedNoSuchElementException");
  +        } catch(NoSuchElementException e) {
  +            // expected
  +        }
  +    }
  +
  +    public void testNextOnEmptyList() {
  +        Iterator testing = new PredicatedIterator(isEven,Collections.EMPTY_LIST.iterator());
  +        try {
  +            testing.next();
  +            fail("ExpectedNoSuchElementException");
  +        } catch(NoSuchElementException e) {
  +            // expected
  +        }
  +    }
  +    
  +    public void testRemoveBeforeNext() {
  +        Iterator testing = new PredicatedIterator(isEven,list.iterator());
  +        try {
  +            testing.remove();
  +            fail("IllegalStateException");
  +        } catch(IllegalStateException e) {
  +            // expected
  +        }
  +    }
  +    
  +    public void testRemoveAfterNext() {
  +        Iterator testing = new PredicatedIterator(isEven,list.iterator());
  +        testing.next();
  +        testing.remove();
  +        try {
  +            testing.remove();
  +            fail("IllegalStateException");
  +        } catch(IllegalStateException e) {
  +            // expected
  +        }
  +    }
  +    
  +    public void testRemoveSome() {
  +        Iterator testing = new PredicatedIterator(isEven,list.iterator());
  +        while(testing.hasNext()) {
  +            testing.next();
  +            testing.remove();
  +        }
  +        for(Iterator iter = list.iterator(); iter.hasNext();) {
  +            assertTrue(! isEven.test(iter.next()) );
  +        }
  +    }
  +
  +    public void testRemoveAll() {
  +        Iterator testing = new PredicatedIterator(ConstantPredicate.getTruePredicate(),list.iterator());
  +        while(testing.hasNext()) {
  +            testing.next();
  +            testing.remove();
  +        }
  +        assertTrue(list.isEmpty());
  +    }
  +
  +    public void testRemoveWithoutHasNext() {
  +        Iterator testing = new PredicatedIterator(ConstantPredicate.getTruePredicate(),list.iterator());
  +        for(int i=0,m = list.size();i<m;i++) {
  +            testing.next();
  +            testing.remove();
  +        }
  +        assertTrue(list.isEmpty());
  +    }
  +    
       // Attributes
       // ------------------------------------------------------------------------
       private List list = null;    
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestIsEmpty.java
  
  Index: TestIsEmpty.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestIsEmpty.java,v
1.1 2003/02/21 00:12:28 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.core.collection;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Set;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.UnaryPredicate;
  import org.apache.commons.functor.core.ConstantPredicate;
  import org.apache.commons.functor.core.composite.NotUnaryPredicate;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/02/21 00:12:28 $
   * @author Rodney Waldhoff
   */
  public class TestIsEmpty extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestIsEmpty(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestIsEmpty.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new IsEmpty();
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------
      
      public void testTest() throws Exception {
          assertTrue(IsEmpty.getIsEmpty().test(Collections.EMPTY_LIST));
          assertTrue(IsEmpty.getIsEmpty().test(Collections.EMPTY_SET));
          {
              List list = new ArrayList();
              assertTrue(IsEmpty.getIsEmpty().test(list));
              list.add("Xyzzy");
              assertTrue(!IsEmpty.getIsEmpty().test(list));
          }
          {
              Set set = new HashSet();
              assertTrue(IsEmpty.getIsEmpty().test(set));
              set.add("Xyzzy");
              assertTrue(!IsEmpty.getIsEmpty().test(set));
          }
      }
  
      public void testTestNull() throws Exception {
          try {
              IsEmpty.getIsEmpty().test(null);
              fail("Expected NullPointerException");
          } catch(NullPointerException e) {
              // expected
          }
      }
      
      public void testTestNonCollection() throws Exception {
          try {
              IsEmpty.getIsEmpty().test(new Integer(3));
              fail("Expected ClassCastException");
          } catch(ClassCastException e) {
              // expected
          }
      }
      
      public void testEquals() throws Exception {
          UnaryPredicate p = new IsEmpty();
          assertEquals(p,p);
          assertObjectsAreEqual(p,new IsEmpty());
          assertObjectsAreEqual(p,IsEmpty.getIsEmpty());
          assertSame(IsEmpty.getIsEmpty(),IsEmpty.getIsEmpty());
          assertObjectsAreNotEqual(p,new ConstantPredicate(true));
          assertObjectsAreNotEqual(p,new NotUnaryPredicate(null));
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestSize.java
  
  Index: TestSize.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestSize.java,v
1.1 2003/02/21 00:12:28 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.core.collection;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Set;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.UnaryFunction;
  import org.apache.commons.functor.core.ConstantFunction;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/02/21 00:12:28 $
   * @author Rodney Waldhoff
   */
  public class TestSize extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestSize(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestSize.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new Size();
      }
  
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------
      
      public void testEvaluate() throws Exception {
          assertEquals(new Integer(0),Size.getSize().evaluate(Collections.EMPTY_LIST));
          assertEquals(new Integer(0),Size.getSize().evaluate(Collections.EMPTY_SET));
          {
              List list = new ArrayList();
              assertEquals(new Integer(0),Size.getSize().evaluate(list));
              for(int i=0;i<2;i++) {
                  assertEquals(new Integer(i),Size.getSize().evaluate(list));            
   
                  list.add(new Integer(i));
                  assertEquals(new Integer(i+1),Size.getSize().evaluate(list));          
     
              }
          }
          {
              Set set = new HashSet();
              assertEquals(new Integer(0),Size.getSize().evaluate(set));
              for(int i=0;i<2;i++) {
                  assertEquals(new Integer(i),Size.getSize().evaluate(set));             
  
                  set.add(new Integer(i));
                  assertEquals(new Integer(i+1),Size.getSize().evaluate(set));           
    
              }
          }
      }
  
      public void testEvaluateNull() throws Exception {
          try {
              Size.getSize().evaluate(null);
              fail("Expected NullPointerException");
          } catch(NullPointerException e) {
              // expected
          }
      }
      
      public void testTestNonCollection() throws Exception {
          try {
              Size.getSize().evaluate(new Integer(3));
              fail("Expected ClassCastException");
          } catch(ClassCastException e) {
              // expected
          }
      }
      
      public void testEquals() throws Exception {
          UnaryFunction f = new Size();
          assertEquals(f,f);
          assertObjectsAreEqual(f,new Size());
          assertObjectsAreEqual(f,Size.getSize());
          assertSame(Size.getSize(),Size.getSize());
          assertObjectsAreNotEqual(f,new ConstantFunction(null));
          assertTrue(! f.equals((Size)null) );
      }
  
  }
  
  
  
  1.2       +3 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestAll.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestAll.java	20 Feb 2003 01:12:41 -0000	1.1
  +++ TestAll.java	21 Feb 2003 00:12:29 -0000	1.2
  @@ -73,6 +73,7 @@
           TestSuite suite = new TestSuite();
           
           suite.addTest(TestComparableComparator.suite());
  +        suite.addTest(TestComparatorFunction.suite());
           
           return suite;
       }
  
  
  
  1.2       +45 -6     jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
  
  Index: TestComparatorFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestComparatorFunction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestComparatorFunction.java	20 Feb 2003 01:12:41 -0000	1.1
  +++ TestComparatorFunction.java	21 Feb 2003 00:12:29 -0000	1.2
  @@ -56,6 +56,8 @@
    */
   package org.apache.commons.functor.core.comparator;
   
  +import java.util.Collections;
  +
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  @@ -88,9 +90,46 @@
       // Tests
       // ------------------------------------------------------------------------
       
  -    public void testEqualsAndHashCode() {
  -        assertEquals(new ComparatorFunction(),new ComparatorFunction(new ComparableComparator()));
  -        assertEquals(new ComparatorFunction().hashCode(),new ComparatorFunction().hashCode());
  -        assertTrue(!new ComparatorFunction().equals(null));
  +    public void testEvaluate() {
  +        ComparatorFunction f = new ComparatorFunction();
  +
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(Integer.MAX_VALUE)))).intValue()
== 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(1)))).intValue()
> 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(0)))).intValue()
> 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(-1)))).intValue()
> 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(Integer.MIN_VALUE)))).intValue()
> 0);
  +
  +        assertTrue(((Integer)(f.evaluate(new Integer(1),new Integer(Integer.MAX_VALUE)))).intValue()
< 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(1),new Integer(1)))).intValue() ==
0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(1),new Integer(0)))).intValue() >
0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(1),new Integer(-1)))).intValue() >
0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(1),new Integer(Integer.MIN_VALUE)))).intValue()
> 0);
  +        
  +        assertTrue(((Integer)(f.evaluate(new Integer(0),new Integer(Integer.MAX_VALUE)))).intValue()
< 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(0),new Integer(1)))).intValue() <
0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(0),new Integer(0)))).intValue() ==
0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(0),new Integer(-1)))).intValue() >
0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(0),new Integer(Integer.MIN_VALUE)))).intValue()
> 0);
  +        
  +        assertTrue(((Integer)(f.evaluate(new Integer(-1),new Integer(Integer.MAX_VALUE)))).intValue()
< 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(-1),new Integer(1)))).intValue() <
0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(-1),new Integer(0)))).intValue() <
0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(-1),new Integer(-1)))).intValue()
== 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(-1),new Integer(Integer.MIN_VALUE)))).intValue()
> 0);
  +
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(Integer.MAX_VALUE)))).intValue()
< 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(1)))).intValue()
< 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(0)))).intValue()
< 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(-1)))).intValue()
< 0);
  +        assertTrue(((Integer)(f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(Integer.MIN_VALUE)))).intValue()
== 0);
  +    }
  +
  +    public void testEquals() {
  +        ComparatorFunction f = new ComparatorFunction();
  +        assertObjectsAreEqual(f,f);
  +        assertObjectsAreEqual(f,new ComparatorFunction(null));
  +        assertObjectsAreEqual(new ComparatorFunction(null),new ComparatorFunction(null));
  +        assertObjectsAreEqual(f,new ComparatorFunction(new ComparableComparator()));
  +        assertObjectsAreNotEqual(f,new ComparatorFunction(Collections.reverseOrder()));
       }
   }
  
  
  
  1.2       +7 -7      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/Quicksort.java
  
  Index: Quicksort.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/Quicksort.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Quicksort.java	20 Feb 2003 01:12:42 -0000	1.1
  +++ Quicksort.java	21 Feb 2003 00:12:29 -0000	1.2
  @@ -79,10 +79,10 @@
   
   
   /**
  - * An example of implemeting the quicksort sorting algorithm 
  + * An example of implementing the quicksort sorting algorithm 
    * using commons-functor.
    * <p> 
  - * See the extensive inline comments for details.
  + * See the extensive in line comments for details.
    * 
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff
  @@ -101,7 +101,7 @@
    * Within this source file, the "literate" comments will use
    * c-style, multi-line comments (slash-star to star-slash).
    * 
  - * For convienience, and to make sure this example stays up to date, 
  + * For convenience, and to make sure this example stays up to date, 
    * we'll implement our quicksort example as a JUnit TestCase...
    * 
    */
  @@ -164,7 +164,7 @@
       }    
   
   /*
  - * Similiarly, sorting an List composed of a single element
  + * Similarly, sorting an List composed of a single element
    * should produce an equivalent list:
    */
   
  @@ -359,7 +359,7 @@
            */
           System.out.println();        
           System.out.println(
  -            "QuickSort Example: Sorted " + COUNT + 
  +            "Quicksort Example: Sorted " + COUNT + 
               " lists of " + SIZE + 
               " elements in " + elapsed + " millis (" + 
               avgmillis + 
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message