From e1062a38bb85bfcae47b54518dcee9c62ddc592d Mon Sep 17 00:00:00 2001 From: Brent Worden Date: Sat, 27 Aug 2005 03:31:40 +0000 Subject: [PATCH] added test cases to increase test coverage. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@240383 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/fraction/FractionFormatTest.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/test/org/apache/commons/math/fraction/FractionFormatTest.java b/src/test/org/apache/commons/math/fraction/FractionFormatTest.java index cf924c09e..f3b758f3c 100644 --- a/src/test/org/apache/commons/math/fraction/FractionFormatTest.java +++ b/src/test/org/apache/commons/math/fraction/FractionFormatTest.java @@ -16,6 +16,7 @@ package org.apache.commons.math.fraction; +import java.text.NumberFormat; import java.text.ParseException; import java.util.Locale; @@ -106,6 +107,60 @@ public class FractionFormatTest extends TestCase { } } + public void testParseInteger() { + String source = "10"; + try { + Fraction c = properFormat.parse(source); + assertNotNull(c); + assertEquals(10, c.getNumerator()); + assertEquals(1, c.getDenominator()); + } catch (ParseException ex) { + fail(ex.getMessage()); + } + try { + Fraction c = improperFormat.parse(source); + assertNotNull(c); + assertEquals(10, c.getNumerator()); + assertEquals(1, c.getDenominator()); + } catch (ParseException ex) { + fail(ex.getMessage()); + } + } + + public void testParseInvalid() { + String source = "a"; + String msg = "should not be able to parse '10 / a'."; + try { + properFormat.parse(source); + fail(msg); + } catch (ParseException ex) { + // success + } + try { + improperFormat.parse(source); + fail(msg); + } catch (ParseException ex) { + // success + } + } + + public void testParseInvalidDenominator() { + String source = "10 / a"; + String msg = "should not be able to parse '10 / a'."; + try { + properFormat.parse(source); + fail(msg); + } catch (ParseException ex) { + // success + } + try { + improperFormat.parse(source); + fail(msg); + } catch (ParseException ex) { + // success + } + } + public void testParseNegative() { try { @@ -173,4 +228,42 @@ public class FractionFormatTest extends TestCase { // success } } + + public void testNumeratorFormat() { + NumberFormat old = properFormat.getNumeratorFormat(); + NumberFormat nf = NumberFormat.getIntegerInstance(); + properFormat.setNumeratorFormat(nf); + assertEquals(nf, properFormat.getNumeratorFormat()); + properFormat.setNumeratorFormat(old); + + old = improperFormat.getNumeratorFormat(); + nf = NumberFormat.getIntegerInstance(); + improperFormat.setNumeratorFormat(nf); + assertEquals(nf, improperFormat.getNumeratorFormat()); + improperFormat.setNumeratorFormat(old); + } + + public void testDenominatorFormat() { + NumberFormat old = properFormat.getDenominatorFormat(); + NumberFormat nf = NumberFormat.getIntegerInstance(); + properFormat.setDenominatorFormat(nf); + assertEquals(nf, properFormat.getDenominatorFormat()); + properFormat.setDenominatorFormat(old); + + old = improperFormat.getDenominatorFormat(); + nf = NumberFormat.getIntegerInstance(); + improperFormat.setDenominatorFormat(nf); + assertEquals(nf, improperFormat.getDenominatorFormat()); + improperFormat.setDenominatorFormat(old); + } + + public void testWholeFormat() { + ProperFractionFormat format = (ProperFractionFormat)properFormat; + + NumberFormat old = format.getWholeFormat(); + NumberFormat nf = NumberFormat.getIntegerInstance(); + format.setWholeFormat(nf); + assertEquals(nf, format.getWholeFormat()); + format.setWholeFormat(old); + } }