sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1403773 [3/3] - in /sis/trunk: ./ sis-build-helper/src/main/resources/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/ sis-utility/src/main/java/org/apache/sis/internal/simple/ sis-utility/src/main/java/org/apache/sis/internal/util...
Date Tue, 30 Oct 2012 16:38:01 GMT
Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/io/TableFormatterTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/io/TableFormatterTest.java?rev=1403773&r1=1403772&r2=1403773&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/io/TableFormatterTest.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/io/TableFormatterTest.java Tue Oct
30 16:37:58 2012
@@ -18,7 +18,7 @@ package org.apache.sis.io;
 
 import java.io.IOException;
 import org.apache.sis.test.DependsOn;
-import org.apache.sis.util.CharSequencesTest;
+import org.junit.Test;
 
 import static org.junit.Assert.*;
 
@@ -34,7 +34,10 @@ import org.apache.sis.internal.util.JDK7
  * @version 0.3
  * @module
  */
-@DependsOn({CharSequencesTest.class, X364Test.class, ExpandedTabFormatterTest.class})
+@DependsOn({
+  org.apache.sis.util.CharSequencesTest.class,
+  org.apache.sis.internal.util.X364Test.class,
+  LineFormatterTest.class})
 public final strictfp class TableFormatterTest extends FormatterTestCase {
     /**
      * The table formatter to test. May not be same instance than {@link #formatter},
@@ -100,4 +103,46 @@ public final strictfp class TableFormatt
                 + "║ Neptune │ Neptune │ 3.883  ║" + lineSeparator
                 + "╚═════════╧═════════╧════════╝"
+ lineSeparator);
     }
+
+    /**
+     * Tests the {@link TableFormatter#toString()} method.
+     * The intend of this test is also to ensure that we can use the API
+     * more easily, without having to deal with {@link IOException}.
+     */
+    @Test
+    public void testToString() { // NO throws IOException
+        /*
+         * First, ensure that TableFormatter.toString() does not
+         * mess with the content of user-supplied Appendable.
+         */
+        testToString(table, "");
+        /*
+         * When TableFormatter is created with its own internal buffer,
+         * then TableFormatter.toString() is allowed to format the table.
+         */
+        testToString(new TableFormatter(),
+                "╔═════════╤═════════╤════════╗\n"
+              + "║ English │ French  │ r.e.d. ║\n"
+              + "╟─────────┼─────────┼────────╢\n"
+              + "║ Mercury │ Mercure │ 0.382  ║\n"
+              + "║ Venus   │ Vénus   │ 0.949  ║\n"
+              + "║ Earth   │ Terre   │ 1.00   ║\n"
+              + "╚═════════╧═════════╧════════╝\n");
+    }
+
+    /**
+     * Helper method for {@link #testToString()}.
+     *
+     * @param table    Where to format the table.
+     * @param expected The expected string representation of the formatted table.
+     */
+    private static void testToString(final TableFormatter table, final String expected) {
+        table.nextLine('═');
+        table.append("English\tFrench\tr.e.d.\n").writeHorizontalSeparator();
+        table.append("Mercury\tMercure\t0.382\n")
+             .append("Venus\tVénus\t0.949\n")
+             .append("Earth\tTerre\t1.00\n")
+             .nextLine('═');
+        assertEquals(expected, table.toString());
+    }
 }

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java?rev=1403773&r1=1403772&r2=1403773&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java Tue Oct
30 16:37:58 2012
@@ -52,6 +52,27 @@ public final strictfp class MathFunction
     private static final int LOWEST_USHORT_PRIME = 32771;
 
     /**
+     * Tests {@link MathFunctions#truncate(double)}.
+     */
+    @Test
+    public void testTruncate() {
+        assertEquals(+4, truncate(+4.9), 0);
+        assertEquals(-4, truncate(-4.9), 0);
+        assertEquals("Positive zero",
+                Double.doubleToLongBits(+0.0),
+                Double.doubleToLongBits(truncate(+0.5)));
+        assertEquals("Negative zero",
+                Double.doubleToLongBits(-0.0),
+                Double.doubleToLongBits(truncate(-0.5)));
+        assertEquals("Positive zero",
+                Double.doubleToLongBits(+0.0),
+                Double.doubleToLongBits(truncate(+0.0)));
+        assertEquals("Negative zero",
+                Double.doubleToLongBits(-0.0),
+                Double.doubleToLongBits(truncate(-0.0)));
+    }
+
+    /**
      * Tests the {@link MathFunctions#magnitude(double[])} method.
      */
     @Test
@@ -63,6 +84,54 @@ public final strictfp class MathFunction
     }
 
     /**
+     * Tests {@link MathFunctions#fractionDigitsForDelta(double, boolean)}.
+     */
+    @Test
+    public void testFractionDigitsForDelta() {
+        assertEquals(3, fractionDigitsForDelta(0.001, true));
+        assertEquals(3, fractionDigitsForDelta(0.009, true));
+        assertEquals(2, fractionDigitsForDelta(0.010, true));
+        assertEquals(2, fractionDigitsForDelta(0.015, true));
+        assertEquals(1, fractionDigitsForDelta(0.100, true));
+        assertEquals(1, fractionDigitsForDelta(0.125, true));
+        assertEquals(1, fractionDigitsForDelta(0.949, true));
+        assertEquals(2, fractionDigitsForDelta(0.994, true)); // Special case
+        assertEquals(3, fractionDigitsForDelta(0.999, true)); // Special case
+
+        assertEquals( 0, fractionDigitsForDelta(  1.0, true));
+        assertEquals( 0, fractionDigitsForDelta(  1.9, true));
+        assertEquals( 0, fractionDigitsForDelta(  9.1, true));
+        assertEquals(-1, fractionDigitsForDelta( 10.0, true));
+        assertEquals(-1, fractionDigitsForDelta( 19.9, true));
+        assertEquals(-1, fractionDigitsForDelta( 94.9, true));
+        assertEquals( 0, fractionDigitsForDelta( 99.0, true)); // Special case
+        assertEquals(-2, fractionDigitsForDelta(100.0, true));
+        assertEquals(-2, fractionDigitsForDelta(100.1, true));
+        assertEquals(-1, fractionDigitsForDelta(994.9, true)); // Special case
+        assertEquals(+1, fractionDigitsForDelta(999.9, true)); // Special case
+        assertEquals(-3, fractionDigitsForDelta(1000,  true));
+
+        // Tests values out of the POW10 array range.
+        assertEquals(23,  fractionDigitsForDelta(1.0E-23,  true));
+        assertEquals(23,  fractionDigitsForDelta(1.9E-23,  true));
+        assertEquals(23,  fractionDigitsForDelta(9.1E-23,  true));
+        assertEquals(24,  fractionDigitsForDelta(9.6E-23,  true)); // Special case
+        assertEquals(300, fractionDigitsForDelta(1.1E-300, true));
+
+        assertEquals(-23,  fractionDigitsForDelta(1.0E+23,  true));
+        assertEquals(-23,  fractionDigitsForDelta(1.9E+23,  true));
+        assertEquals(-23,  fractionDigitsForDelta(9.1E+23,  true));
+        assertEquals(-22,  fractionDigitsForDelta(9.6E+23,  true)); // Special case
+        assertEquals(-300, fractionDigitsForDelta(1.1E+300, true));
+
+        // Special cases.
+        assertEquals(0,  fractionDigitsForDelta(0, true));
+        assertEquals(0,  fractionDigitsForDelta(Double.NaN, true));
+        assertEquals(0,  fractionDigitsForDelta(Double.POSITIVE_INFINITY, true));
+        assertEquals(0,  fractionDigitsForDelta(Double.NEGATIVE_INFINITY, true));
+    }
+
+    /**
      * Tests the {@link MathFunctions#pow10(double)} method.
      * This will indirectly test {@link MathFunctions#pow10(int)}
      * since the former will delegate to the later in this test.

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java?rev=1403773&r1=1403772&r2=1403773&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java Tue Oct
30 16:37:58 2012
@@ -19,6 +19,7 @@ package org.apache.sis.measure;
 import java.util.Locale;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.DependsOnMethod;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -36,11 +37,32 @@ import static org.apache.sis.test.TestUt
 @DependsOn(org.apache.sis.math.MathFunctionsTest.class)
 public final strictfp class AngleFormatTest extends TestCase {
     /**
+     * Tests a pattern with illegal usage of D, M and S symbols.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testIllegalPattern() {
+        final AngleFormat f = new AngleFormat(Locale.CANADA);
+        f.applyPattern("DD°SS′MM″");
+    }
+
+    /**
+     * Tests an illegal pattern with illegal symbols for the fraction part.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testIllegalFractionPattern() {
+        final AngleFormat f = new AngleFormat(Locale.CANADA);
+        f.applyPattern("DD°MM′SS.m″");
+    }
+
+    /**
      * Tests using {@link Locale#CANADA}.
      */
     @Test
     public void testCanadaLocale() {
         final AngleFormat f = new AngleFormat("DD.ddd°", Locale.CANADA);
+        assertEquals(3, f.getMinimumFractionDigits());
+        assertEquals(3, f.getMaximumFractionDigits());
+        assertEquals( "DD.ddd°",  f.toPattern());
         assertEquals( "20.000°",  formatAndParse(f, new Angle   ( 20.000)));
         assertEquals( "20.749°",  formatAndParse(f, new Angle   ( 20.749)));
         assertEquals("-12.247°",  formatAndParse(f, new Angle   (-12.247)));
@@ -54,6 +76,9 @@ public final strictfp class AngleFormatT
     @Test
     public void testFranceLocale() {
         final AngleFormat f = new AngleFormat("DD.ddd°", Locale.FRANCE);
+        assertEquals(3, f.getMinimumFractionDigits());
+        assertEquals(3, f.getMaximumFractionDigits());
+        assertEquals( "DD.ddd°", f.toPattern());
         assertEquals("19,457°E", formatAndParse(f, new Longitude( 19.457)));
         assertEquals("78,124°S", formatAndParse(f, new Latitude (-78.124)));
     }
@@ -64,17 +89,112 @@ public final strictfp class AngleFormatT
     @Test
     public void testNoSeparator() {
         final AngleFormat f = new AngleFormat("DDddd", Locale.CANADA);
+        assertEquals(3, f.getMinimumFractionDigits());
+        assertEquals(3, f.getMaximumFractionDigits());
+        assertEquals("DDddd",  f.toPattern());
         assertEquals("19457E", formatAndParse(f, new Longitude( 19.457)));
         assertEquals("78124S", formatAndParse(f, new Latitude (-78.124)));
     }
 
     /**
-     * Tests with the degree separator.
+     * Tests with a minute fields.
      */
     @Test
-    public void testDegreeSeparator() {
+    @DependsOnMethod("testCanadaLocale")
+    public void testDegreeMinutes() {
         final AngleFormat f = new AngleFormat("DD°MM.m", Locale.CANADA);
+        assertEquals(1, f.getMinimumFractionDigits());
+        assertEquals(1, f.getMaximumFractionDigits());
+        assertEquals( "DD°MM.m", f.toPattern());
         assertEquals( "12°30.0", formatAndParse(f, new Angle( 12.50)));
         assertEquals("-10°15.0", formatAndParse(f, new Angle(-10.25)));
     }
+
+    /**
+     * Tests with a seconds fields.
+     */
+    @Test
+    @DependsOnMethod("testDegreeMinutes")
+    public void testDegreeMinutesSeconds() {
+        final AngleFormat f = new AngleFormat("DD°MM′SS.sss″", Locale.CANADA);
+        assertEquals(3, f.getMinimumFractionDigits());
+        assertEquals(3, f.getMaximumFractionDigits());
+        assertEquals( "DD°MM′SS.sss″", f.toPattern());
+        assertEquals( "12°30′56.250″", formatAndParse(f, new Angle( 12.515625)));
+        assertEquals("-12°30′56.250″", formatAndParse(f, new Angle(-12.515625)));
+    }
+
+    /**
+     * Tests with optional digits.
+     */
+    @Test
+    @DependsOnMethod("testDegreeMinutesSeconds")
+    public void testOptionalFractionDigits() {
+        final AngleFormat f = new AngleFormat("DD°MM′SS.s##″", Locale.CANADA);
+        assertEquals(1, f.getMinimumFractionDigits());
+        assertEquals(3, f.getMaximumFractionDigits());
+        assertEquals( "DD°MM′SS.s##″", f.toPattern());
+        assertEquals( "12°30′56.25″",  formatAndParse(f, new Angle( 12.515625)));
+        assertEquals("-12°30′56.25″",  formatAndParse(f, new Angle(-12.515625)));
+        assertEquals( "12°31′52.5″",   formatAndParse(f, new Angle( 12.53125
)));
+        assertEquals("-12°31′52.5″",   formatAndParse(f, new Angle(-12.53125
)));
+        assertEquals( "12°33′45.0″",   formatAndParse(f, new Angle( 12.5625
 )));
+        assertEquals("-12°33′45.0″",   formatAndParse(f, new Angle(-12.5625
 )));
+
+        f.applyPattern("DD°MM′SS.###″");
+        assertEquals(0, f.getMinimumFractionDigits());
+        assertEquals(3, f.getMaximumFractionDigits());
+        assertEquals( "DD°MM′SS.###″", f.toPattern());
+        assertEquals( "12°33′45″", formatAndParse(f, new Angle( 12.5625)));
+        assertEquals("-12°33′45″", formatAndParse(f, new Angle(-12.5625)));
+    }
+
+    /**
+     * Tests the {@link AngleFormat#setMaximumWidth(int)} method.
+     */
+    @Test
+    @DependsOnMethod("testOptionalFractionDigits")
+    public void testSetMaximumWidth() {
+        final AngleFormat f = new AngleFormat(Locale.CANADA);
+        assertEquals("D°MM′SS.################″", f.toPattern());
+
+        f.setMaximumWidth(12);
+        assertEquals("D°MM′SS.###″", f.toPattern());
+        assertEquals("8°07′24.442″", f.format(new Angle( 8.123456)));
+        assertEquals("20°07′24.44″", f.format(new Angle(20.123456)));
+
+        f.setMaximumWidth(10);
+        assertEquals("D°MM′SS.#″", f.toPattern());
+        assertEquals("8°07′24.4″", f.format(new Angle( 8.123456)));
+        assertEquals("20°07′24″",  f.format(new Angle(20.123456)));
+
+        f.setMaximumWidth(9);
+        assertEquals("D°MM′SS″", f.toPattern());
+        f.setMaximumWidth(8);
+        assertEquals("D°MM′SS″", f.toPattern());
+
+        // Test the drop of seconds field.
+        f.setMaximumFractionDigits(6);
+        f.setMaximumWidth(7);
+        assertEquals("D°MM.#′",  f.toPattern());
+        assertEquals("8°07.4′",  f.format(new Angle( 8.123456)));
+        assertEquals("20°07.4′", f.format(new Angle(20.123456)));
+
+        f.setMaximumWidth(6);
+        assertEquals("D°MM′",  f.toPattern());
+        assertEquals("8°07′",  f.format(new Angle( 8.123456)));
+        assertEquals("20°07′", f.format(new Angle(20.123456)));
+
+        // Test the drop of minutes field.
+        f.setMaximumFractionDigits(6);
+        f.setMaximumWidth(4);
+        assertEquals("D.#°", f.toPattern());
+        assertEquals("8.1°", f.format(new Angle( 8.123456)));
+        assertEquals("20°",  f.format(new Angle(20.123456)));
+
+        f.setMaximumWidth(3);
+        assertEquals("D°",  f.toPattern());
+        assertEquals("8°",  f.format(new Angle( 8.123456)));
+        assertEquals("20°", f.format(new Angle(20.123456)));
+    }
 }

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/test/Assert.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/test/Assert.java?rev=1403773&r1=1403772&r2=1403773&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/test/Assert.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/test/Assert.java Tue Oct 30 16:37:58
2012
@@ -79,7 +79,13 @@ public strictfp class Assert extends org
      * @param actual   The actual string.
      */
     public static void assertMultilinesEquals(final String message, final CharSequence expected,
final CharSequence actual) {
-        assertArrayEquals(message, CharSequences.split(expected, '\n'), CharSequences.split(actual,
'\n'));
+        final CharSequence[] a1 = CharSequences.split(expected, '\n');
+        final CharSequence[] a2 = CharSequences.split(actual,   '\n');
+        final int length = Math.min(a1.length, a2.length);
+        for (int i=0; i<length; i++) {
+            assertEquals("Line " + (i+1) + ':', a1[i], a2[i]);
+        }
+        assertArrayEquals(message, a1, a2);
     }
 
     /**

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1403773&r1=1403772&r2=1403773&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java Tue
Oct 30 16:37:58 2012
@@ -57,11 +57,9 @@ import org.junit.runners.Suite;
 
   // Formatting
   org.apache.sis.measure.AngleFormatTest.class,
-  org.apache.sis.io.X364Test.class,
-  org.apache.sis.io.EndOfLineFormatterTest.class,
-  org.apache.sis.io.IndentedLineFormatterTest.class,
-  org.apache.sis.io.ExpandedTabFormatterTest.class,
-  org.apache.sis.io.LineWrapFormatterTest.class,
+  org.apache.sis.measure.AngleTest.class,
+  org.apache.sis.internal.util.X364Test.class,
+  org.apache.sis.io.LineFormatterTest.class,
   org.apache.sis.io.TableFormatterTest.class,
 
   // XML most basic types.

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1403773&r1=1403772&r2=1403773&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java Tue Oct
30 16:37:58 2012
@@ -44,10 +44,10 @@ public final strictfp class CharSequence
      */
     @Test
     public void testSpaces() {
-        assertEquals("",         spaces(0));
-        assertEquals(" ",        spaces(1));
-        assertEquals("        ", spaces(8));
-        assertEquals("",         spaces(-2));
+        assertEquals("",         spaces( 0).toString());
+        assertEquals(" ",        spaces( 1).toString());
+        assertEquals("        ", spaces( 8).toString());
+        assertEquals("",         spaces(-2).toString());
     }
 
     /**

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/xml/XLinkTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/xml/XLinkTest.java?rev=1403773&r1=1403772&r2=1403773&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/xml/XLinkTest.java (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/xml/XLinkTest.java Tue Oct 30 16:37:58
2012
@@ -35,7 +35,7 @@ import static org.junit.Assert.*;
  */
 public final strictfp class XLinkTest extends TestCase {
     /**
-     * Tests the automatic {@link #getType()} detection.
+     * Tests the automatic {@link XLink#getType()} detection.
      *
      * @throws URISyntaxException Should never happen.
      */

Modified: sis/trunk/src/main/docbook/fr.xml
URL: http://svn.apache.org/viewvc/sis/trunk/src/main/docbook/fr.xml?rev=1403773&r1=1403772&r2=1403773&view=diff
==============================================================================
--- sis/trunk/src/main/docbook/fr.xml (original)
+++ sis/trunk/src/main/docbook/fr.xml Tue Oct 30 16:37:58 2012
@@ -31,5 +31,6 @@
   <xi:include href="fr/standards.xml"/>
   <xi:include href="fr/geoapi.xml"/>
   <xi:include href="fr/XML.xml"/>
+  <xi:include href="fr/utility.xml"/>
 
 </book>



Mime
View raw message