Uploaded image for project: 'Commons Numbers'
  1. Commons Numbers
  2. NUMBERS-100

Code in file FractionTest.java is unsatisfactory

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • None
    • 1.0-beta1
    • fraction
    • None

    Description

      The following characteristics of the file FractionTest.java can be improved:

      • The second-to-last try-catch-block in the method testAdd() is a duplicate of the preceding try-catch-block and is therefore redundant.
      • In the method testPow(), the conditions assertFraction(9, 49, a.pow(2)) and assertFraction(49, 9, a.pow(-2)) are tested twice each (once in the block after a's declaration, and a second time in the block after b's declaration. This is probably a typo.
      • The last two assertions in the method testGetReducedFraction() pass the parameters to the method Assert.assertEquals(long, long) in the wrong order (the expected value should go first).
      • Several methods in this class contain a number of tests that use shared local variables but are completely independent of each other because these local variables get assigned new values at the beginning of a test. The fact that the scope of these local variables encompasses all those independent tests makes the code look more confusing than necessary.
      • Except for the method testGoldenRatio(), the throwing of an exception is tested with a construct involving the swallowing of an exception, rather than an explicit syntax.
      • The helper method assertFraction(int, int, Fraction) is neglected throughout large sections of the class in favor of Assert.assertEquals(long, long) pairs, increasing the amount of code duplication.

      Attachments

        Activity

          People

            Unassigned Unassigned
            Schamschi Heinrich Bohne
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 50m
                1h 50m