commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 37095] New: - [math] Failure to fail when testing for exceptions in MathUtils
Date Fri, 14 Oct 2005 15:45:44 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=37095>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=37095

           Summary: [math] Failure to fail when testing for exceptions in
                    MathUtils
           Product: Commons
           Version: 1.1.0
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Math
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: elharo@metalab.unc.edu


In MathUtilsTest I found the following code:

    public void testAddAndCheck() {
        int big = Integer.MAX_VALUE;
        int bigNeg = Integer.MIN_VALUE;
        assertEquals(big, MathUtils.addAndCheck(big, 0));
        try {
            int res = MathUtils.addAndCheck(big, 1);
        } catch (ArithmeticException ex) {}
        try {
            int res = MathUtils.addAndCheck(bigNeg, -1);
        } catch (ArithmeticException ex) {}
    }
    
    public void testMulAndCheck() {
        int big = Integer.MAX_VALUE;
        int bigNeg = Integer.MIN_VALUE;
        assertEquals(big, MathUtils.mulAndCheck(big, 1));
        try {
            int res = MathUtils.mulAndCheck(big, 2);
        } catch (ArithmeticException ex) {}
        try {
            int res = MathUtils.mulAndCheck(bigNeg, 2);
        } catch (ArithmeticException ex) {}
    }
    
    public void testSubAndCheck() {
        int big = Integer.MAX_VALUE;
        int bigNeg = Integer.MIN_VALUE;
        assertEquals(big, MathUtils.subAndCheck(big, 0));
        try {
            int res = MathUtils.subAndCheck(big, -1);
        } catch (ArithmeticException ex) {}
        try {
            int res = MathUtils.subAndCheck(bigNeg, 1);
        } catch (ArithmeticException ex) {}
    }

These tests pass even if the expected excepiton is thrown. All three should be
reworked with fail() statements at the end of the try block like so:

        try {
            int res = MathUtils.subAndCheck(big, -1);
            fail("Didn't throw exceptions when subtracting one over the maximum");
        } catch (ArithmeticException ex) {}
        try {
            int res = MathUtils.subAndCheck(bigNeg, 1);
            fail("Didn't throw exceptions when subtracting one over the maximum");
        } catch (ArithmeticException ex) {}


I doubt there's a real bug here, but if there is, these tests won't find it.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message