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