/**** * Class SimpleFractionTest is a very small example illustrating what your * FractionTest class can look like for Programming Assignment 1. */ public class SimpleFractionTest { /** * Call the test method for testNumeratorDenominator. In the complete * FractionTest you're writing, this main method calls all of the faction * test methods. */ public static void main(String[] args) { testNumeratorDenominatorConstructor(); } /** * Test the full initializing constructor of the Fraction class with three * sample test cases. In the full version of this test method you'll need * some additional test cases. Use the guidelines in Lecture Notes 2 to * help figure out what the additional test case should be. */ private static void testNumeratorDenominatorConstructor() { Fraction f; // value produced by the constructor // Test Case 1: check the boundary case of a zero numerator "0/1". test(0, 1, 0, 1); // Test Case 2: check a simple case the doesn't need reduction. test(1, 2, 1, 2); // Test Case 3: check a case that needs some reduction. test(4, 8, 1, 2); } /** * Output an error if the given Fraction f does not have the given * values for nExpected and dExpected for its numerator and denominator. */ private static void test(int nIn, int dIn, int nExpected, int dExpected) { int n; // convenience variable for the numerator value int d = 0; // convenience variable for the denominator value Fraction f = new Fraction(nIn, dIn); if ((n = f.getNumerator()) != nExpected || (d = f.getDenominator()) != dExpected) { System.out.println("Got " + n + "/" + d + " expected " + nExpected + "/" + dExpected); } } }