You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2003/12/01 22:51:48 UTC

cvs commit: jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor TestAlgorithms.java

rwaldhoff    2003/12/01 13:51:47

  Modified:    functor/src/test/org/apache/commons/functor/core/comparator
                        TestIsGreaterThan.java TestIsEquivalent.java
                        TestIsNotEquivalent.java TestIsLessThanOrEqual.java
                        TestIsLessThan.java TestIsGreaterThanOrEqual.java
               functor/src/test/org/apache/commons/functor/example/kata/two
                        TestBinaryChop.java
               functor/src/test/org/apache/commons/functor
                        TestAlgorithms.java
  Log:
  add tests
  
  Revision  Changes    Path
  1.5       +7 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java
  
  Index: TestIsGreaterThan.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestIsGreaterThan.java	24 Nov 2003 20:12:16 -0000	1.4
  +++ TestIsGreaterThan.java	1 Dec 2003 21:51:47 -0000	1.5
  @@ -108,6 +108,11 @@
           assertTrue(p.test(new Integer(6),new Integer(4)));
       }
       
  +    public void testInstance() {
  +        assertTrue(IsGreaterThan.instance(new Integer(7)).test(new Integer(8)));
  +        assertTrue(! IsGreaterThan.instance(new Integer(7)).test(new Integer(6)));
  +    }
  +    
       public void testEquals() throws Exception {
           IsGreaterThan p = new IsGreaterThan();
           assertEquals(p,p);
  
  
  
  1.5       +7 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsEquivalent.java
  
  Index: TestIsEquivalent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsEquivalent.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestIsEquivalent.java	24 Nov 2003 20:12:16 -0000	1.4
  +++ TestIsEquivalent.java	1 Dec 2003 21:51:47 -0000	1.5
  @@ -108,6 +108,11 @@
           assertTrue(!p.test(new Integer(6),new Integer(4)));
       }
       
  +    public void testInstance() {
  +        assertTrue(IsEquivalent.instance("Xyzzy").test("Xyzzy"));
  +        assertTrue(!IsEquivalent.instance("Xyzzy").test("z"));
  +    }
  +    
       public void testEquals() throws Exception {
           IsEquivalent p = new IsEquivalent();
           assertEquals(p,p);
  
  
  
  1.5       +7 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java
  
  Index: TestIsNotEquivalent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestIsNotEquivalent.java	1 Dec 2003 05:16:24 -0000	1.4
  +++ TestIsNotEquivalent.java	1 Dec 2003 21:51:47 -0000	1.5
  @@ -108,6 +108,11 @@
           assertTrue(p.test(new Integer(6),new Integer(4)));
       }
       
  +    public void testInstance() {
  +        assertTrue(! IsNotEquivalent.instance(new Integer(7)).test(new Integer(7)));
  +        assertTrue(IsNotEquivalent.instance(new Integer(7)).test(new Integer(8)));
  +    }
  +    
       public void testEquals() throws Exception {
           IsNotEquivalent p = new IsNotEquivalent();
           assertEquals(p,p);
  
  
  
  1.5       +7 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java
  
  Index: TestIsLessThanOrEqual.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestIsLessThanOrEqual.java	1 Dec 2003 05:16:24 -0000	1.4
  +++ TestIsLessThanOrEqual.java	1 Dec 2003 21:51:47 -0000	1.5
  @@ -108,6 +108,11 @@
           assertTrue(!p.test(new Integer(6),new Integer(4)));
       }
       
  +    public void testInstance() {
  +        assertTrue(! IsLessThanOrEqual.instance(new Integer(7)).test(new Integer(8)));
  +        assertTrue(IsLessThanOrEqual.instance(new Integer(7)).test(new Integer(6)));
  +    }
  +    
       public void testEquals() throws Exception {
           IsLessThanOrEqual p = new IsLessThanOrEqual();
           assertEquals(p,p);
  
  
  
  1.5       +7 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsLessThan.java
  
  Index: TestIsLessThan.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsLessThan.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestIsLessThan.java	1 Dec 2003 05:16:24 -0000	1.4
  +++ TestIsLessThan.java	1 Dec 2003 21:51:47 -0000	1.5
  @@ -108,6 +108,11 @@
           assertTrue(!p.test(new Integer(6),new Integer(4)));
       }
       
  +    public void testInstance() {
  +        assertTrue(! IsLessThan.instance(new Integer(7)).test(new Integer(8)));
  +        assertTrue(IsLessThan.instance(new Integer(7)).test(new Integer(6)));
  +    }
  +    
       public void testEquals() throws Exception {
           IsLessThan p = new IsLessThan();
           assertEquals(p,p);
  
  
  
  1.5       +7 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java
  
  Index: TestIsGreaterThanOrEqual.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestIsGreaterThanOrEqual.java	24 Nov 2003 20:12:16 -0000	1.4
  +++ TestIsGreaterThanOrEqual.java	1 Dec 2003 21:51:47 -0000	1.5
  @@ -108,6 +108,11 @@
           assertTrue(p.test(new Integer(6),new Integer(4)));
       }
       
  +    public void testInstance() {
  +        assertTrue(IsGreaterThanOrEqual.instance(new Integer(7)).test(new Integer(8)));
  +        assertTrue(! IsGreaterThanOrEqual.instance(new Integer(7)).test(new Integer(6)));
  +    }
  +
       public void testEquals() throws Exception {
           IsGreaterThanOrEqual p = new IsGreaterThanOrEqual();
           assertEquals(p,p);
  
  
  
  1.8       +4 -4      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
  
  Index: TestBinaryChop.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/example/kata/two/TestBinaryChop.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestBinaryChop.java	1 Dec 2003 21:14:46 -0000	1.7
  +++ TestBinaryChop.java	1 Dec 2003 21:51:47 -0000	1.8
  @@ -295,7 +295,7 @@
        * Using the functor framework, we can make these notions
        * explict.  Specifically, the construction above is:
        * 
  -     *   Algorithms.dountil(BODY,TERM); 
  +     *   Algorithms.untildo(BODY,TERM); 
        * 
        * Since we'll want to share state among the TERM and BODY,
        * let's declare a single interface for the TERM Predicate and
  @@ -379,7 +379,7 @@
        *     end
        *   end
        * 
  -     * We can do that too, see EiffelStyleLoop.
  +     * We can do that too, using EiffelStyleLoop.
        */
       class BinarySearchLoop extends EiffelStyleLoop {
           BinarySearchLoop(Object aSeeking, List aList) {
  
  
  
  1.10      +41 -2     jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/TestAlgorithms.java
  
  Index: TestAlgorithms.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/TestAlgorithms.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestAlgorithms.java	25 Nov 2003 21:29:17 -0000	1.9
  +++ TestAlgorithms.java	1 Dec 2003 21:51:47 -0000	1.10
  @@ -71,6 +71,7 @@
   import org.apache.commons.functor.adapter.LeftBoundPredicate;
   import org.apache.commons.functor.core.IdentityFunction;
   import org.apache.commons.functor.core.IsEqual;
  +import org.apache.commons.functor.core.Limit;
   import org.apache.commons.functor.core.Offset;
   import org.apache.commons.functor.generator.Generator;
   import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
  @@ -278,6 +279,37 @@
           assertEquals("[0, 1]", col.toString());
       }
   
  +    public void testDoUntil() {        
  +        for(int i=0;i<3;i++){
  +            Counter counter = new Counter();
  +            Algorithms.dountil(counter,new Offset(i));
  +            assertEquals(i+1,counter.count);        
  +        }
  +    }
  +    
  +    public void testDoWhile() {        
  +        for(int i=0;i<3;i++){
  +            Counter counter = new Counter();
  +            Algorithms.dowhile(counter,new Limit(i));
  +            assertEquals(i+1,counter.count);        
  +        }
  +    }
  +    
  +    public void testUntilDo() {        
  +        for(int i=0;i<3;i++){
  +            Counter counter = new Counter();
  +            Algorithms.untildo(new Offset(i),counter);
  +            assertEquals(i,counter.count);        
  +        }
  +    }
  +    
  +    public void testWhileDo() {        
  +        for(int i=0;i<3;i++){
  +            Counter counter = new Counter();
  +            Algorithms.whiledo(new Limit(i),counter);
  +            assertEquals(i,counter.count);        
  +        }
  +    }
       public void testRecurse() {
           assertEquals(new Integer(5), Algorithms.recurse(new RecFunc(0, false)));
   
  @@ -336,6 +368,13 @@
       // Classes
       // ------------------------------------------------------------------------
   
  +    static class Counter implements Procedure {
  +        public void run() {
  +            count++;
  +        }
  +        public int count = 0;
  +    }
  +    
       static class Summer implements UnaryProcedure {
           public void run(Object that) {
               sum += ((Number)that).intValue();
  
  
  

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