From fa4c993e5d68641fff5fe39138195facc63de420 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Tue, 24 Mar 2009 22:10:16 +0000 Subject: [PATCH] removed spurious exception in optimization git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@758051 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArgumentOutsideDomainExceptionTest.java | 2 +- .../math/FunctionEvaluationExceptionTest.java | 67 ++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java b/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java index 1a78cb7f4..eac05706d 100644 --- a/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java +++ b/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java @@ -31,7 +31,7 @@ public class ArgumentOutsideDomainExceptionTest extends TestCase { assertNull(ex.getCause()); assertNotNull(ex.getMessage()); assertTrue(ex.getMessage().indexOf("3.14") > 0); - assertEquals(Math.PI, ex.getArgument(), 0); + assertEquals(Math.PI, ex.getArgument()[0], 0); assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH))); } diff --git a/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java b/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java index f462cd5cb..119aa4e5d 100644 --- a/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java +++ b/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java @@ -31,11 +31,22 @@ public class FunctionEvaluationExceptionTest extends TestCase { assertNull(ex.getCause()); assertNotNull(ex.getMessage()); assertTrue(ex.getMessage().indexOf("0") > 0); - assertEquals(0.0, ex.getArgument(), 0); + assertEquals(0.0, ex.getArgument()[0], 0); + } + + public void testConstructorArray(){ + FunctionEvaluationException ex = + new FunctionEvaluationException(new double[] { 0, 1, 2 }); + assertNull(ex.getCause()); + assertNotNull(ex.getMessage()); + assertTrue(ex.getMessage().indexOf("0") > 0); + assertEquals(0.0, ex.getArgument()[0], 0); + assertEquals(1.0, ex.getArgument()[1], 0); + assertEquals(2.0, ex.getArgument()[2], 0); } public void testConstructorPatternArguments(){ - String pattern = "Evaluation failed for argument = {0}"; + String pattern = "evaluation failed for argument = {0}"; Object[] arguments = { Double.valueOf(0.0) }; FunctionEvaluationException ex = new FunctionEvaluationException(0.0, pattern, arguments); assertNull(ex.getCause()); @@ -48,8 +59,26 @@ public class FunctionEvaluationExceptionTest extends TestCase { assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH))); } + public void testConstructorArrayPatternArguments(){ + String pattern = "evaluation failed for argument = {0}"; + Object[] arguments = { Double.valueOf(0.0) }; + FunctionEvaluationException ex = + new FunctionEvaluationException(new double[] { 0, 1, 2 }, pattern, arguments); + assertNull(ex.getCause()); + assertEquals(pattern, ex.getPattern()); + assertEquals(arguments.length, ex.getArguments().length); + for (int i = 0; i < arguments.length; ++i) { + assertEquals(arguments[i], ex.getArguments()[i]); + } + assertFalse(pattern.equals(ex.getMessage())); + assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH))); + assertEquals(0.0, ex.getArgument()[0], 0); + assertEquals(1.0, ex.getArgument()[1], 0); + assertEquals(2.0, ex.getArgument()[2], 0); + } + public void testConstructorPatternArgumentsCause(){ - String pattern = "Evaluation failed for argument = {0}"; + String pattern = "evaluation failed for argument = {0}"; Object[] arguments = { Double.valueOf(0.0) }; String inMsg = "inner message"; Exception cause = new Exception(inMsg); @@ -64,6 +93,26 @@ public class FunctionEvaluationExceptionTest extends TestCase { assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH))); } + public void testConstructorArrayPatternArgumentsCause(){ + String pattern = "evaluation failed for argument = {0}"; + Object[] arguments = { Double.valueOf(0.0) }; + String inMsg = "inner message"; + Exception cause = new Exception(inMsg); + FunctionEvaluationException ex = + new FunctionEvaluationException(cause, new double[] { 0, 1, 2 }, pattern, arguments); + assertEquals(cause, ex.getCause()); + assertEquals(pattern, ex.getPattern()); + assertEquals(arguments.length, ex.getArguments().length); + for (int i = 0; i < arguments.length; ++i) { + assertEquals(arguments[i], ex.getArguments()[i]); + } + assertFalse(pattern.equals(ex.getMessage())); + assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH))); + assertEquals(0.0, ex.getArgument()[0], 0); + assertEquals(1.0, ex.getArgument()[1], 0); + assertEquals(2.0, ex.getArgument()[2], 0); + } + public void testConstructorArgumentCause(){ String inMsg = "inner message"; Exception cause = new Exception(inMsg); @@ -72,4 +121,16 @@ public class FunctionEvaluationExceptionTest extends TestCase { assertTrue(ex.getMessage().equals(ex.getMessage(Locale.FRENCH))); } + public void testConstructorArrayArgumentCause(){ + String inMsg = "inner message"; + Exception cause = new Exception(inMsg); + FunctionEvaluationException ex = + new FunctionEvaluationException(cause, new double[] { 0, 1, 2 }); + assertEquals(cause, ex.getCause()); + assertTrue(ex.getMessage().equals(ex.getMessage(Locale.FRENCH))); + assertEquals(0.0, ex.getArgument()[0], 0); + assertEquals(1.0, ex.getArgument()[1], 0); + assertEquals(2.0, ex.getArgument()[2], 0); + } + }