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