author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:51:05 +0200 | |
changeset 22 | 7b36dbc9df32 |
parent 20 | afae7be94b25 |
child 207 | 675393d7093a |
permissions | -rw-r--r-- |
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@20 | 34 |
public void testFactorial4() { |
jtulach@20 | 35 |
assertEquals(24, Factorial.factorial(4)); |
jtulach@20 | 36 |
} |
jtulach@20 | 37 |
|
jtulach@17 | 38 |
public void testFactorial5() { |
jtulach@17 | 39 |
assertEquals(120, Factorial.factorial(5)); |
jtulach@17 | 40 |
} |
jtulach@17 | 41 |
|
jtulach@17 | 42 |
/** Class showing inventive, non-expected use of |
jtulach@17 | 43 |
* Arithmetica methods to do multiplication instead of |
jtulach@17 | 44 |
* addition. |
jtulach@17 | 45 |
*/ |
jtulach@22 | 46 |
//BEGIN: design.composition.arith.factorial |
jtulach@22 | 47 |
public static final class Factorial extends Arithmetica { |
jtulach@17 | 48 |
public static int factorial(int n) { |
jtulach@17 | 49 |
return new Factorial().sumRange(1, n); |
jtulach@17 | 50 |
} |
jtulach@17 | 51 |
@Override |
jtulach@17 | 52 |
public int sumTwo(int one, int second) { |
jtulach@17 | 53 |
return one * second; |
jtulach@17 | 54 |
} |
jtulach@17 | 55 |
} |
jtulach@22 | 56 |
//END: design.composition.arith.factorial |
jtulach@17 | 57 |
|
jtulach@17 | 58 |
|
jtulach@17 | 59 |
} |