Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 34802 invoked from network); 23 Dec 2010 17:58:39 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Dec 2010 17:58:39 -0000 Received: (qmail 44295 invoked by uid 500); 23 Dec 2010 17:58:39 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 44203 invoked by uid 500); 23 Dec 2010 17:58:38 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 44196 invoked by uid 99); 23 Dec 2010 17:58:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Dec 2010 17:58:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Dec 2010 17:58:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A9F4F23888FE; Thu, 23 Dec 2010 17:58:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1052341 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/exception/ main/java/org/apache/commons/math/exception/util/ main/java/org/apache/commons/math/linear/ main/resources/META-INF/localization/ test/java/org/apach... Date: Thu, 23 Dec 2010 17:58:11 -0000 To: commits@commons.apache.org From: erans@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101223175811.A9F4F23888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: erans Date: Thu Dec 23 17:58:11 2010 New Revision: 1052341 URL: http://svn.apache.org/viewvc?rev=1052341&view=rev Log: MATH-461 Created unchecked exception "MathParseException". Removed occurrence of old "MathRuntimeException". Modified unit tests to not use the base class "parseObject" method because its signature contains a checked exception). Upgraded tests to Junit4 (MATH-423). Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java (with props) Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java?rev=1052341&view=auto ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java Thu Dec 23 17:58:11 2010 @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math.exception; + +import org.apache.commons.math.exception.util.Localizable; +import org.apache.commons.math.exception.util.LocalizedFormats; + +/** + * Class to signal parse failures. + * + * @since 2.2 + * @version $Revision$ $Date$ + */ +public class MathParseException extends MathRuntimeException { + /** Serializable version Id. */ + private static final long serialVersionUID = -6024911025449780478L; + + /** + * @param wrong Bad string representation of the object. + * @param position Index, in the {@code wrong} string, that caused the + * parsing to fail. + * @param type Class of the object supposedly represented by the + * {@code wrong} string. + */ + public MathParseException(String wrong, + int position, + Class type) { + super(null, null, LocalizedFormats.CANNOT_PARSE_AS_TYPE, + wrong, new Integer(position), type.getName()); + } + + /** + * @param wrong Bad string representation of the object. + * @param position Index, in the {@code wrong} string, that caused the + * parsing to fail. + */ + public MathParseException(String wrong, + int position) { + super(null, null, LocalizedFormats.CANNOT_PARSE, + wrong, new Integer(position)); + } +} Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1052341&r1=1052340&r2=1052341&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Thu Dec 23 17:58:11 2010 @@ -298,6 +298,8 @@ public enum LocalizedFormats implements UNABLE_TO_SOLVE_SINGULAR_PROBLEM("unable to solve: singular problem"), UNBOUNDED_SOLUTION("unbounded solution"), UNKNOWN_MODE("unknown mode {0}, known modes: {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) and {11} ({12})"), + CANNOT_PARSE_AS_TYPE("string {0} unparseable (from position {1}) as an object of type {2}"), /* keep */ + CANNOT_PARSE("string {0} unparseable (from position {1})"), /* keep */ UNPARSEABLE_3D_VECTOR("unparseable 3D vector: \"{0}\""), UNPARSEABLE_COMPLEX_NUMBER("unparseable complex number: \"{0}\""), UNPARSEABLE_FRACTION_NUMBER("unparseable fraction number: \"{0}\""), Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java?rev=1052341&r1=1052340&r2=1052341&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVectorFormat.java Thu Dec 23 17:58:11 2010 @@ -19,13 +19,12 @@ package org.apache.commons.math.linear; import java.text.FieldPosition; import java.text.NumberFormat; -import java.text.ParseException; import java.text.ParsePosition; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import org.apache.commons.math.MathRuntimeException; +import org.apache.commons.math.exception.MathParseException; import org.apache.commons.math.exception.MathIllegalArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.CompositeFormat; @@ -253,26 +252,28 @@ public class RealVectorFormat extends Co } /** - * Parses a string to produce a {@link RealVector} object. - * @param source the string to parse + * Parse a string to produce a {@link RealVector} object. + * + * @param source String to parse. * @return the parsed {@link RealVector} object. - * @exception ParseException if the beginning of the specified string - * cannot be parsed. + * @throws MathParseException if the beginning of the specified string + * cannot be parsed. */ - public ArrayRealVector parse(String source) throws ParseException { - ParsePosition parsePosition = new ParsePosition(0); - ArrayRealVector result = parse(source, parsePosition); + public ArrayRealVector parse(String source) { + final ParsePosition parsePosition = new ParsePosition(0); + final ArrayRealVector result = parse(source, parsePosition); if (parsePosition.getIndex() == 0) { - throw MathRuntimeException.createParseException( - parsePosition.getErrorIndex(), - LocalizedFormats.UNPARSEABLE_REAL_VECTOR, source); + throw new MathParseException(source, + parsePosition.getErrorIndex(), + ArrayRealVector.class); } return result; } /** - * Parses a string to produce a {@link RealVector} object. - * @param source the string to parse + * Parse a string to produce a {@link RealVector} object. + * + * @param source String to parse. * @param pos input/ouput parsing parameter. * @return the parsed {@link RealVector} object. */ @@ -323,7 +324,6 @@ public class RealVectorFormat extends Co data[i] = components.get(i).doubleValue(); } return new ArrayRealVector(data, false); - } /** @@ -337,5 +337,4 @@ public class RealVectorFormat extends Co public Object parseObject(String source, ParsePosition pos) { return parse(source, pos); } - } Modified: commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties?rev=1052341&r1=1052340&r2=1052341&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties (original) +++ commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties Thu Dec 23 17:58:11 2010 @@ -270,6 +270,8 @@ UNABLE_TO_PERFORM_QR_DECOMPOSITION_ON_JA UNABLE_TO_SOLVE_SINGULAR_PROBLEM = r\u00e9solution impossible : probl\u00e8me singulier UNBOUNDED_SOLUTION = solution non born\u00e9e UNKNOWN_MODE = mode {0} inconnu, modes connus : {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) et {11} ({12}) +CANNOT_PARSE_AS_TYPE = cha\u00eene {0} non analysable (\u00e0 partir de la position {1}) en un objet de type {2} +CANNOT_PARSE = cha\u00eene {0} non analysable (\u00e0 partir de la position {1}) UNPARSEABLE_3D_VECTOR = vecteur 3D non analysable : "{0}" UNPARSEABLE_COMPLEX_NUMBER = nombre complexe non analysable : "{0}" UNPARSEABLE_FRACTION_NUMBER = nombre fractionnaire non analysable : "{0}" Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java?rev=1052341&r1=1052340&r2=1052341&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorFormatAbstractTest.java Thu Dec 23 17:58:11 2010 @@ -18,16 +18,17 @@ package org.apache.commons.math.linear; import java.text.NumberFormat; -import java.text.ParseException; import java.text.ParsePosition; import java.util.Locale; -import junit.framework.TestCase; +import org.junit.Test; +import org.junit.Assert; +import org.apache.commons.math.exception.MathParseException; import org.apache.commons.math.exception.MathIllegalArgumentException; import org.apache.commons.math.util.CompositeFormat; -public abstract class RealVectorFormatAbstractTest extends TestCase { +public abstract class RealVectorFormatAbstractTest { RealVectorFormat realVectorFormat = null; RealVectorFormat realVectorFormatSquare = null; @@ -36,21 +37,22 @@ public abstract class RealVectorFormatAb protected abstract char getDecimalCharacter(); - @Override - public void setUp() throws Exception { + public RealVectorFormatAbstractTest() { realVectorFormat = RealVectorFormat.getInstance(getLocale()); final NumberFormat nf = NumberFormat.getInstance(getLocale()); nf.setMaximumFractionDigits(2); realVectorFormatSquare = new RealVectorFormat("[", "]", " : ", nf); } + @Test public void testSimpleNoDecimals() { ArrayRealVector c = new ArrayRealVector(new double[] {1, 1, 1}); String expected = "{1; 1; 1}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testSimpleWithDecimals() { ArrayRealVector c = new ArrayRealVector(new double[] {1.23, 1.43, 1.63}); String expected = @@ -59,9 +61,10 @@ public abstract class RealVectorFormatAb "43; 1" + getDecimalCharacter() + "63}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testSimpleWithDecimalsTrunc() { ArrayRealVector c = new ArrayRealVector(new double[] {1.2323, 1.4343, 1.6333}); String expected = @@ -70,9 +73,10 @@ public abstract class RealVectorFormatAb "43; 1" + getDecimalCharacter() + "63}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testNegativeX() { ArrayRealVector c = new ArrayRealVector(new double[] {-1.2323, 1.4343, 1.6333}); String expected = @@ -81,9 +85,10 @@ public abstract class RealVectorFormatAb "43; 1" + getDecimalCharacter() + "63}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testNegativeY() { ArrayRealVector c = new ArrayRealVector(new double[] {1.2323, -1.4343, 1.6333}); String expected = @@ -92,9 +97,10 @@ public abstract class RealVectorFormatAb "43; 1" + getDecimalCharacter() + "63}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testNegativeZ() { ArrayRealVector c = new ArrayRealVector(new double[] {1.2323, 1.4343, -1.6333}); String expected = @@ -103,16 +109,18 @@ public abstract class RealVectorFormatAb "43; -1" + getDecimalCharacter() + "63}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testNonDefaultSetting() { ArrayRealVector c = new ArrayRealVector(new double[] {1, 1, 1}); String expected = "[1 : 1 : 1]"; String actual = realVectorFormatSquare.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testStaticFormatRealVectorImpl() { Locale defaultLocal = Locale.getDefault(); Locale.setDefault(getLocale()); @@ -124,59 +132,65 @@ public abstract class RealVectorFormatAb "33; 432" + getDecimalCharacter() + "44}"; String actual = RealVectorFormat.formatRealVector(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); Locale.setDefault(defaultLocal); } + @Test public void testNan() { ArrayRealVector c = new ArrayRealVector(new double[] {Double.NaN, Double.NaN, Double.NaN}); String expected = "{(NaN); (NaN); (NaN)}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testPositiveInfinity() { ArrayRealVector c = new ArrayRealVector(new double[] { Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY }); String expected = "{(Infinity); (Infinity); (Infinity)}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void tesNegativeInfinity() { ArrayRealVector c = new ArrayRealVector(new double[] { Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY }); String expected = "{(-Infinity); (-Infinity); (-Infinity)}"; String actual = realVectorFormat.format(c); - assertEquals(expected, actual); + Assert.assertEquals(expected, actual); } + @Test public void testParseSimpleNoDecimals() { String source = "{1; 1; 1}"; ArrayRealVector expected = new ArrayRealVector(new double[] {1, 1, 1}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseIgnoredWhitespace() { ArrayRealVector expected = new ArrayRealVector(new double[] {1, 1, 1}); ParsePosition pos1 = new ParsePosition(0); String source1 = "{1;1;1}"; - assertEquals(expected, realVectorFormat.parseObject(source1, pos1)); - assertEquals(source1.length(), pos1.getIndex()); + Assert.assertEquals(expected, realVectorFormat.parse(source1, pos1)); + Assert.assertEquals(source1.length(), pos1.getIndex()); ParsePosition pos2 = new ParsePosition(0); String source2 = " { 1 ; 1 ; 1 } "; - assertEquals(expected, realVectorFormat.parseObject(source2, pos2)); - assertEquals(source2.length() - 1, pos2.getIndex()); + Assert.assertEquals(expected, realVectorFormat.parse(source2, pos2)); + Assert.assertEquals(source2.length() - 1, pos2.getIndex()); } + @Test public void testParseSimpleWithDecimals() { String source = "{1" + getDecimalCharacter() + @@ -185,13 +199,14 @@ public abstract class RealVectorFormatAb "63}"; ArrayRealVector expected = new ArrayRealVector(new double[] {1.23, 1.43, 1.63}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseSimpleWithDecimalsTrunc() { String source = "{1" + getDecimalCharacter() + @@ -200,13 +215,14 @@ public abstract class RealVectorFormatAb "6333}"; ArrayRealVector expected = new ArrayRealVector(new double[] {1.2323, 1.4343, 1.6333}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseNegativeX() { String source = "{-1" + getDecimalCharacter() + @@ -215,13 +231,14 @@ public abstract class RealVectorFormatAb "6333}"; ArrayRealVector expected = new ArrayRealVector(new double[] {-1.2323, 1.4343, 1.6333}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseNegativeY() { String source = "{1" + getDecimalCharacter() + @@ -230,13 +247,14 @@ public abstract class RealVectorFormatAb "6333}"; ArrayRealVector expected = new ArrayRealVector(new double[] {1.2323, -1.4343, 1.6333}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseNegativeZ() { String source = "{1" + getDecimalCharacter() + @@ -245,13 +263,14 @@ public abstract class RealVectorFormatAb "6333}"; ArrayRealVector expected = new ArrayRealVector(new double[] {1.2323, 1.4343, -1.6333}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseNegativeAll() { String source = "{-1" + getDecimalCharacter() + @@ -260,13 +279,14 @@ public abstract class RealVectorFormatAb "6333}"; ArrayRealVector expected = new ArrayRealVector(new double[] {-1.2323, -1.4343, -1.6333}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseZeroX() { String source = "{0" + getDecimalCharacter() + @@ -275,13 +295,14 @@ public abstract class RealVectorFormatAb "6333}"; ArrayRealVector expected = new ArrayRealVector(new double[] {0.0, -1.4343, 1.6333}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseNonDefaultSetting() { String source = "[1" + getDecimalCharacter() + @@ -290,99 +311,107 @@ public abstract class RealVectorFormatAb "6333]"; ArrayRealVector expected = new ArrayRealVector(new double[] {1.2323, 1.4343, 1.6333}); try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormatSquare.parseObject(source); - assertEquals(expected, actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormatSquare.parse(source); + Assert.assertEquals(expected, actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseNan() { String source = "{(NaN); (NaN); (NaN)}"; try { - ArrayRealVector actual = (ArrayRealVector) realVectorFormat.parseObject(source); - assertEquals(new ArrayRealVector(new double[] {Double.NaN, Double.NaN, Double.NaN}), actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(new ArrayRealVector(new double[] {Double.NaN, Double.NaN, Double.NaN}), actual); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParsePositiveInfinity() { String source = "{(Infinity); (Infinity); (Infinity)}"; try { - ArrayRealVector actual = (ArrayRealVector)realVectorFormat.parseObject(source); - assertEquals(new ArrayRealVector(new double[] { + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(new ArrayRealVector(new double[] { Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY }), actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseNegativeInfinity() { String source = "{(-Infinity); (-Infinity); (-Infinity)}"; try { - ArrayRealVector actual = (ArrayRealVector)realVectorFormat.parseObject(source); - assertEquals(new ArrayRealVector(new double[] { + ArrayRealVector actual = realVectorFormat.parse(source); + Assert.assertEquals(new ArrayRealVector(new double[] { Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY }), actual); - } catch (ParseException ex) { - fail(ex.getMessage()); + } catch (MathParseException ex) { + Assert.fail(ex.getMessage()); } } + @Test public void testParseNoComponents() { try { - realVectorFormat.parseObject("{ }"); - fail("Expecting ParseException"); - } catch (ParseException pe) { + realVectorFormat.parse("{ }"); + Assert.fail("Expecting MathParseException"); + } catch (MathParseException pe) { // expected behavior } } - public void testParseManyComponents() throws ParseException { - ArrayRealVector parsed = - (ArrayRealVector) realVectorFormat.parseObject("{0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}"); - assertEquals(24, parsed.getDimension()); + @Test + public void testParseManyComponents() { + ArrayRealVector parsed = realVectorFormat.parse("{0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}"); + Assert.assertEquals(24, parsed.getDimension()); } + @Test public void testConstructorSingleFormat() { NumberFormat nf = NumberFormat.getInstance(); RealVectorFormat cf = new RealVectorFormat(nf); - assertNotNull(cf); - assertEquals(nf, cf.getFormat()); + Assert.assertNotNull(cf); + Assert.assertEquals(nf, cf.getFormat()); } + @Test public void testFormatObject() { try { CompositeFormat cf = new RealVectorFormat(); Object object = new Object(); cf.format(object); - fail(); + Assert.fail(); } catch (MathIllegalArgumentException ex) { // success } } + @Test public void testForgottenPrefix() { ParsePosition pos = new ParsePosition(0); final String source = "1; 1; 1}"; - assertNull("Should not parse <"+source+">",new RealVectorFormat().parse(source, pos)); - assertEquals(0, pos.getErrorIndex()); + Assert.assertNull("Should not parse <"+source+">",new RealVectorFormat().parse(source, pos)); + Assert.assertEquals(0, pos.getErrorIndex()); } + @Test public void testForgottenSeparator() { ParsePosition pos = new ParsePosition(0); final String source = "{1; 1 1}"; - assertNull("Should not parse <"+source+">",new RealVectorFormat().parse(source, pos)); - assertEquals(6, pos.getErrorIndex()); + Assert.assertNull("Should not parse <"+source+">",new RealVectorFormat().parse(source, pos)); + Assert.assertEquals(6, pos.getErrorIndex()); } + @Test public void testForgottenSuffix() { ParsePosition pos = new ParsePosition(0); final String source = "{1; 1; 1 "; - assertNull("Should not parse <"+source+">",new RealVectorFormat().parse(source, pos)); - assertEquals(8, pos.getErrorIndex()); + Assert.assertNull("Should not parse <"+source+">",new RealVectorFormat().parse(source, pos)); + Assert.assertEquals(8, pos.getErrorIndex()); } - }