1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/composition/test/api/FactorialTest.java Sat Jun 14 09:51:03 2008 +0200
1.3 @@ -0,0 +1,53 @@
1.4 +/*
1.5 + * Žluťoučký kůň je naše hříbátko.
1.6 + * and open the template in the editor.
1.7 + */
1.8 +
1.9 +package api;
1.10 +
1.11 +import junit.framework.TestCase;
1.12 +
1.13 +/**
1.14 + *
1.15 + * @author Jaroslav Tulach <jtulach@netbeans.org>
1.16 + */
1.17 +public class FactorialTest extends TestCase {
1.18 +
1.19 + public FactorialTest(String testName) {
1.20 + super(testName);
1.21 + }
1.22 +
1.23 + @Override
1.24 + protected void setUp() throws Exception {
1.25 + super.setUp();
1.26 + }
1.27 +
1.28 + @Override
1.29 + protected void tearDown() throws Exception {
1.30 + super.tearDown();
1.31 + }
1.32 +
1.33 + public void testFactorial3() {
1.34 + assertEquals(6, Factorial.factorial(3));
1.35 + }
1.36 +
1.37 + public void testFactorial5() {
1.38 + assertEquals(120, Factorial.factorial(5));
1.39 + }
1.40 +
1.41 + /** Class showing inventive, non-expected use of
1.42 + * Arithmetica methods to do multiplication instead of
1.43 + * addition.
1.44 + */
1.45 + private static class Factorial extends Arithmetica {
1.46 + public static int factorial(int n) {
1.47 + return new Factorial().sumRange(1, n);
1.48 + }
1.49 + @Override
1.50 + public int sumTwo(int one, int second) {
1.51 + return one * second;
1.52 + }
1.53 + }
1.54 +
1.55 +
1.56 +}