# HG changeset patch # User Jaroslav Tulach # Date 1213429865 -7200 # Node ID afae7be94b2551c40d21617b4a94318b494e3274 # Parent 56735848fe6c1f29c4c136e3800209b873f3f8a5 Fixing the optimized 2.0 implementation and adding yet another test for factorial of 4 diff -r 56735848fe6c -r afae7be94b25 samples/composition/src-api1.0/api/Arithmetica.java --- a/samples/composition/src-api1.0/api/Arithmetica.java Sat Jun 14 09:51:04 2008 +0200 +++ b/samples/composition/src-api1.0/api/Arithmetica.java Sat Jun 14 09:51:05 2008 +0200 @@ -3,6 +3,7 @@ /** Class to simplify arithmetical operations. * * @author Jaroslav Tulach + * @version 1.0 */ public class Arithmetica { public int sumTwo(int one, int second) { diff -r 56735848fe6c -r afae7be94b25 samples/composition/src-api2.0/api/Arithmetica.java --- a/samples/composition/src-api2.0/api/Arithmetica.java Sat Jun 14 09:51:04 2008 +0200 +++ b/samples/composition/src-api2.0/api/Arithmetica.java Sat Jun 14 09:51:05 2008 +0200 @@ -1,8 +1,10 @@ package api; -/** Class to simplify arithmetical operations. +/** Class to simplify arithmetical operations, improved version to compute + * the sum for ranges. * * @author Jaroslav Tulach + * @version 2.0 */ public class Arithmetica { public int sumTwo(int one, int second) { @@ -18,6 +20,6 @@ } public int sumRange(int from, int to) { - return (from + to) * (from - to + 1) / 2; + return (from + to) * (to - from + 1) / 2; } } diff -r 56735848fe6c -r afae7be94b25 samples/composition/src-test/api/FactorialTest.java --- a/samples/composition/src-test/api/FactorialTest.java Sat Jun 14 09:51:04 2008 +0200 +++ b/samples/composition/src-test/api/FactorialTest.java Sat Jun 14 09:51:05 2008 +0200 @@ -31,6 +31,10 @@ assertEquals(6, Factorial.factorial(3)); } + public void testFactorial4() { + assertEquals(24, Factorial.factorial(4)); + } + public void testFactorial5() { assertEquals(120, Factorial.factorial(5)); }