import junit.framework.TestCase;
import org.apache.commons.lang.math.*;
public class FractionTest extends TestCase {
public void testAddition() {
Fraction half = Fraction.getFraction(2, 4);
Fraction fourth = Fraction.getFraction(1, 4);
Fraction actual = half.add(fourth);
Fraction expected = Fraction.getFraction(3, 4);
assertEquals(expected, actual);
}
public void testSubtraction() {
Fraction half = Fraction.getFraction(2, 4);
Fraction fourth = Fraction.getFraction(1, 4);
Fraction actual = half.subtract(fourth);
Fraction expected = fourth;
assertEquals(expected, actual);
}
public void testAddNumberToItself() {
Fraction half = Fraction.getFraction(2, 4);
Fraction actual = half.add(half);
Fraction expected = Fraction.ONE;
assertEquals(expected, actual);
}
}
Notice the duplication of code. Duplication of code is bad!