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/core TestOffset.java TestAll.java
Date Tue, 25 Nov 2003 00:22:26 GMT
rwaldhoff    2003/11/24 16:22:26

  Modified:    functor/src/test/org/apache/commons/functor/core
                        TestAll.java
  Added:       functor/src/java/org/apache/commons/functor/core Offset.java
               functor/src/test/org/apache/commons/functor/core
                        TestOffset.java
  Log:
  add Offset and tests
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/Offset.java
  
  Index: Offset.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/Offset.java,v
1.1 2003/11/25 00:22:26 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;
  
  import org.apache.commons.functor.BinaryPredicate;
  import org.apache.commons.functor.Predicate;
  import org.apache.commons.functor.UnaryPredicate;
  
  /**
   * A predicate that returns <code>false</code>
   * the first <i>n</i> times it is invoked, and
   * <code>true</code> thereafter. 
   *
   * @since 1.0
   * @version $Revision: 1.1 $ $Date: 2003/11/25 00:22:26 $
   * @author Jason Horman (jason@jhorman.org)
   * @author Rodney Waldhoff
   */
  
  public final class Offset implements Predicate, UnaryPredicate, BinaryPredicate {
  
      public Offset(int count) {
          if(count < 0) { 
              throw new IllegalArgumentException("Argument must be a non-negative integer.");
          }
          this.min = count;
      }
  
      public boolean test() {
          // stop incremeting when we've hit max, so we don't loop around
          if(current < min) {
              current++;
              return false;
          } else {
              return true;
          }
      }
  
      public boolean test(Object obj) {
          return test();        
      }
  
      public boolean test(Object a, Object b) {
          return test();        
      }
  
      public String toString() {
          return "Offset<" + min + ">";
      }
      // instance variables
      //---------------------------------------------------------------
      private int min;
      private int current = 0;
  
  }
  
  
  1.8       +3 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestAll.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestAll.java	25 Nov 2003 00:18:58 -0000	1.7
  +++ TestAll.java	25 Nov 2003 00:22:26 -0000	1.8
  @@ -87,6 +87,7 @@
           suite.addTest(TestLeftIdentityPredicate.suite());
           suite.addTest(TestRightIdentityPredicate.suite());
           suite.addTest(TestLimit.suite());
  +        suite.addTest(TestOffset.suite());
   
           suite.addTest(org.apache.commons.functor.core.composite.TestAll.suite());
           suite.addTest(org.apache.commons.functor.core.collection.TestAll.suite());
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestOffset.java
  
  Index: TestOffset.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestOffset.java,v
1.1 2003/11/25 00:22:26 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;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryPredicate;
  import org.apache.commons.functor.Predicate;
  import org.apache.commons.functor.UnaryPredicate;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/11/25 00:22:26 $
   * @author Rodney Waldhoff
   */
  public class TestOffset extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestOffset(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestOffset.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new Offset(3);
      }
      
      // Lifecycle
      // ------------------------------------------------------------------------
  
      // Tests
      // ------------------------------------------------------------------------
  
      public void testZero() throws Exception {
          Predicate p = new Offset(0);
          assertTrue( p.test());
          assertTrue( p.test());
          assertTrue( p.test());
      }
  
      public void testBadArgs() throws Exception {
          try {
              new Offset(-1);
              fail("Expected IllegalArgumentException");
          } catch(IllegalArgumentException e) {
              // expected
          }
      }
      
      public void testTestNilary() throws Exception {
          Predicate p = new Offset(3);
          assertTrue(!p.test());
          assertTrue(!p.test());
          assertTrue(!p.test());
          assertTrue(p.test());
      }
  
      public void testTestUnary() throws Exception {
          UnaryPredicate p = new Offset(3);
          assertTrue(!p.test(null));
          assertTrue(!p.test(null));
          assertTrue(!p.test(null));
          assertTrue(p.test(null));
      }
          
      public void testTestBinary() throws Exception {
          BinaryPredicate p = new Offset(3);
          assertTrue(!p.test(null,null));
          assertTrue(!p.test(null,null));
          assertTrue(!p.test(null,null));
          assertTrue(p.test(null,null));
      }
  }
  
  
  

---------------------------------------------------------------------
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