samples/composition/src-test/api/FactorialTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:51:05 +0200
changeset 20 afae7be94b25
parent 17 af005434d27f
child 22 7b36dbc9df32
permissions -rw-r--r--
Fixing the optimized 2.0 implementation and adding yet another test for factorial of 4
     1 /*
     2  * Žluťoučký kůň je naše hříbátko.
     3  * and open the template in the editor.
     4  */
     5 
     6 package api;
     7 
     8 import junit.framework.TestCase;
     9 
    10 /**
    11  *
    12  * @author Jaroslav Tulach <jtulach@netbeans.org>
    13  */
    14 public class FactorialTest extends TestCase {
    15     
    16     public FactorialTest(String testName) {
    17         super(testName);
    18     }            
    19 
    20     @Override
    21     protected void setUp() throws Exception {
    22         super.setUp();
    23     }
    24 
    25     @Override
    26     protected void tearDown() throws Exception {
    27         super.tearDown();
    28     }
    29     
    30     public void testFactorial3() {
    31         assertEquals(6, Factorial.factorial(3));
    32     }
    33     
    34     public void testFactorial4() {
    35         assertEquals(24, Factorial.factorial(4));
    36     }
    37     
    38     public void testFactorial5() {
    39         assertEquals(120, Factorial.factorial(5));
    40     }
    41 
    42     /** Class showing inventive, non-expected use of 
    43      * Arithmetica methods to do multiplication instead of
    44      * addition.
    45      */
    46     private static class Factorial extends Arithmetica {
    47         public static int factorial(int n) {
    48             return new Factorial().sumRange(1, n);
    49         }
    50         @Override
    51         public int sumTwo(int one, int second) {
    52             return one * second;
    53         }
    54     }
    55 
    56     
    57 }