From 5af9537a5fc3d44404e75b8a6116b6850b74d9a6 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Thu, 1 Dec 2011 15:25:19 +0000 Subject: [PATCH] Added a few unit tests. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1209119 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/fraction/FractionFormatTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java b/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java index 5ddc8ae66..a9700c728 100644 --- a/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java +++ b/src/test/java/org/apache/commons/math/fraction/FractionFormatTest.java @@ -136,6 +136,44 @@ public class FractionFormatTest { } } + @Test + public void testParseOne1() { + String source = "1 / 1"; + Fraction c = properFormat.parse(source); + Assert.assertNotNull(c); + Assert.assertEquals(1, c.getNumerator()); + Assert.assertEquals(1, c.getDenominator()); + } + + @Test + public void testParseOne2() { + String source = "10 / 10"; + Fraction c = properFormat.parse(source); + Assert.assertNotNull(c); + Assert.assertEquals(1, c.getNumerator()); + Assert.assertEquals(1, c.getDenominator()); + } + + @Test + public void testParseZero1() { + String source = "0 / 1"; + Fraction c = properFormat.parse(source); + Assert.assertNotNull(c); + Assert.assertEquals(0, c.getNumerator()); + Assert.assertEquals(1, c.getDenominator()); + } + + @Test + public void testParseZero2() { + String source = "-0 / 1"; + Fraction c = properFormat.parse(source); + Assert.assertNotNull(c); + Assert.assertEquals(0, c.getNumerator()); + Assert.assertEquals(1, c.getDenominator()); + // This test shows that the sign is not preserved. + Assert.assertEquals(Double.POSITIVE_INFINITY, 1d / c.doubleValue(), 0); + } + @Test public void testParseInvalid() { String source = "a";