CPE 102 Program 1b - Tests for the Fraction class

Ground Rules

No collaboration is allowed on this program assignment. Your program must be an individual and original effort. Except for any situations explicitly identified in this assignment, if any, you may only receive help from your instructor or the tutors provided by the Computer Science Department. See the Syllabus for the significant consequences for disallowed collaboration and/or plagiarism.

Errata

None so far - updates and corrections, if any, will show up here (be sure to refresh this page as necessary).

Due Date and Submission Instructions

Submit the following file(s) on one of the CSL servers using handin as follows:

    file(s): FractionTest.java

    touser: eaugusti

          assignment/subdirectory: 102-program01b
Objectives
Specifications
  1. Your source code must meet the Programming Guidelines.

  2. Read about Test Driven Development (TDD) to orient yourself to the process you are about to embark on.
  3. Minimally implement a class called Fraction to this specification. This will allow you to compile and test your tests as you develop them. Recall that a minimally implemented class has no instance variables and no logic except for the return statements necessary to satisfy the compiler. Where possible, choose return values that are always wrong (would never be returned by a correct version of the method) so that tests checking for correct behavior will always fail. When no always-wrong value is then choose something clearly recognizable and remember to not write tests expecting that value to be returned as the correct result.

  4. In a class called FractionTest write SUnit tests (the class you wrote in Program 1a) for each of the public methods of the Fraction class including the constructors.

    1. Testing in any Object Oriented language has the special challenge that the instance variables of an object are often private. Private instance variables are inaccessable to code outside the class which means the testing code cannot access them directly.The testing code must, instead, use the public methods of the class to perform the testing. The best practice is to use the same small set of methods to verify the results of all tests that result in a Fraction object. The equals method is not sufficient because it only tells you if two Fraction objects are equal, not if they have specific expected values for the numerator and denominator. To that end, you must use the following two methods when checking Fraction objects returned by the methods you are testing:
      1. getNumerator()
      2. getDenominator()
    1. You must use SampleTest.java as the starting point for your FractionTest class. Use the save-as feature of your browser (or wget/curl if you are a cool kid), not cut-and-paste, to obtain a copy of SampleTest.java

      1. You must to rename SampleTest.java as FractionTest.java
      2. You must change the name of the class from SampleTest to FractionTest.
      3. Do not write or use constructors - they will not be called when grading your tests.
      4. Do not use any instance variables - they can not be accessed by the static test methods you will be writting.
      5. Do not modify the main - it will not be called when I grade your tests.
      6. You should write separate test methods for each Fraction method you are testing.
      7. You must call your test methods in the testAll method or they will not be called when grading your tests.
    2. At a minimum you must write the following number of tests (you may write more). Think about negative fractions (is the sign always carried in the numerator as required by the Fraction class specification?), positive fractions, and fractions that should be reduced, i.e., a result that should be 1/2 is not something like 2/4 (Fraction objects are always supposed to be stored in reduced form).

      1. Fraction(): 1 test (2 calls to SUnit methods, one for the numerator and one for the denominator).
      2. Fraction(int numerator): 2 tests (4 calls to SUnit methods).
      3. Fraction(int numerator, int denominator): 5 tests (9 calls to SUnit methods) One of the 9 test should verify this constructor throws the expecte exception when the denominator is 0. Your instructor will lecture on how to do this - don't miss it!
      4. getNumerator(): 2 tests (2 calls to SUnit methods - just checking the numerator).
      5. getDenominator(): 2 tests (2 calls to SUnit methods - just checking the denominator).
      6. add(Fraction other): 4 tests (8 calls to SUnit methods, checking both numerator and denominator of result).
      7. sub(Fraction other): 4 tests (8 calls to SUnit methods, checking both numerator and denominator of result).
      8. mul(Fraction other): 4 tests (8 calls to SUnit methods, checking both numerator and denominator of result).
      9. div(Fraction other): 4 tests (8 calls to SUnit methods, checking both numerator and denominator of result).
      10. value(): 2 tests (2 calls to SUnit methods)
      11. equals(): 2 tests (2 calls to SUnit methods)
      12. toString(): 3 tests (3 calls to SUnit methods)
    Grading
    1. All of your non-boolean tests must report an error when compiled and run with a minimal implementation of the Fraction class.

    2. Some of your boolean tests must report an error (all of your true-tests or all of your false-tests for a method depending on what the minimal implementation returns).

    3. All of your tests must not report an error when compiled and run with a correct implementation of the Fraction class. You may not have a correct implementation when this is due so develop them carefully!

    Program courtesy of Kurt Mammen.