Author: desruisseaux
Date: Mon Dec 17 07:52:55 2012
New Revision: 1422779
URL: http://svn.apache.org/viewvc?rev=1422779&view=rev
Log:
Ported AbstractEnvelopeTest.
Some tests are disabled for now because we need a CRS:84 implementation to
enable them.
Added:
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
(with props)
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/referencing/
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/referencing/Assert.java
- copied, changed from r1422657,
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java
Added:
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java?rev=1422779&view=auto
==============================================================================
---
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
(added)
+++
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
Mon Dec 17 07:52:55 2012
@@ -0,0 +1,385 @@
+/*
+ * 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.sis.geometry;
+
+import java.awt.geom.Rectangle2D;
+import org.opengis.geometry.Envelope;
+import org.opengis.geometry.DirectPosition;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static java.lang.Double.NaN;
+import static org.apache.sis.referencing.Assert.*;
+
+
+/**
+ * Tests the methods defined in the {@link AbstractEnvelope} class.
+ * Various implementations are used for each test.
+ *
+ * @author Martin Desruisseaux (IRD, Geomatys)
+ * @since 0.3 (derived from geotk-3.20)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(GeneralDirectPositionTest.class)
+public final strictfp class AbstractEnvelopeTest extends TestCase {
+ /**
+ * Tolerance threshold for strict floating point comparisons.
+ */
+ private static final double STRICT = 0;
+
+ /**
+ * Enumeration of implementations to be tested.
+ * The {@code LAST} constant is for stopping the loops.
+ */
+ private static final int GENERAL=0, IMMUTABLE=1, RECTANGLE=2, LAST=3;
+
+ /**
+ * Creates an envelope of the given type. The type shall be one of the
+ * {@link #GENERAL}, {@link #IMMUTABLE} or {@link #RECTANGLE} constants.
+ */
+ private static Envelope create(final int type,
+ final double xmin, final double xmax,
+ final double ymin, final double ymax)
+ {
+ switch (type) {
+ case GENERAL: {
+ final GeneralEnvelope envelope = new GeneralEnvelope(2);
+ envelope.setRange(0, xmin, xmax);
+ envelope.setRange(1, ymin, ymax);
+ return envelope;
+ }
+ case IMMUTABLE: {
+ // TODO return new ImmutableEnvelope(xmin, xmax, ymin, ymax,
null);
+ }
+ case RECTANGLE: {
+ return new Envelope2D(xmin, ymin, xmax - xmin, ymax - ymin,
null);
+ }
+ default: throw new IllegalArgumentException(String.valueOf(type));
+ }
+ }
+
+ /**
+ * Tests the simple case (no anti-meridian crossing).
+ *
+ * {@preformat text
+ * âââââââââââââââ
+ * â âââââââââ â
+ * â âââââââââ â
+ * âââââââââââââââ
+ * }
+ */
+ @Test
+ public void testSimpleEnvelope() {
+ final DirectPosition2D inside = new DirectPosition2D( 3, 32);
+ final DirectPosition2D outside = new DirectPosition2D(-5, 32);
+ final Envelope2D contained = (Envelope2D) create(RECTANGLE, -2, 10,
35, 40);
+ final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16,
35, 40);
+ final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, 14, 16,
35, 40);
+ for (int type=0; type<LAST; type++) {
+ final String label = "Type " + type;
+ final Envelope envelope = create(type, -4, 12, 30, 50);
+ assertEquals(label, 30, envelope.getMinimum(1), STRICT);
+ assertEquals(label, 50, envelope.getMaximum(1), STRICT);
+ assertEquals(label, 40, envelope.getMedian (1), STRICT);
+ assertEquals(label, 20, envelope.getSpan (1), STRICT);
+ assertEquals(label, -4, envelope.getMinimum(0), STRICT);
+ assertEquals(label, 12, envelope.getMaximum(0), STRICT);
+ assertEquals(label, 4, envelope.getMedian (0), STRICT);
+ assertEquals(label, 16, envelope.getSpan (0), STRICT);
+ if (envelope instanceof AbstractEnvelope) {
+ final AbstractEnvelope ext = (AbstractEnvelope) envelope;
+ assertTrue (label, ext.contains (inside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (intersect, false));
+ assertTrue (label, ext.intersects(intersect, false));
+ assertDisjoint(ext, disjoint);
+ assertContains(ext, contained);
+ }
+ if (envelope instanceof Rectangle2D) {
+ final Rectangle2D ext = (Rectangle2D) envelope;
+ assertTrue (label, ext.contains (inside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (intersect));
+ assertTrue (label, ext.intersects(intersect));
+ assertDisjoint(ext, disjoint);
+ assertContains(ext, contained);
+ }
+ }
+ }
+
+ /**
+ * Tests a case crossing the anti-meridian.
+ *
+ * {@preformat text
+ * ââââââ ââââââââââ
ââââââ ââââââ
+ * â â ââââââ or âââ â
â âââ
+ * â â ââââââ âââ â
â âââ
+ * ââââââ ââââââââââ
ââââââ ââââââ
+ * }
+ */
+ @Test
+ @Ignore("The tested envelope needs to be associated to CRS:84")
+ public void testCrossingAntiMeridian() {
+ final DirectPosition2D inside = new DirectPosition2D(18, 32);
+ final DirectPosition2D outside = new DirectPosition2D( 3, 32);
+ final Envelope2D contained = (Envelope2D) create(RECTANGLE, 14, 16,
35, 40);
+ final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16,
35, 40);
+ final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, -2, 10,
35, 40);
+ final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8,
35, 40);
+ for (int type=0; type<LAST; type++) {
+ final String label = "Type " + type;
+ final Envelope envelope = create(type, 12, -4, 30, 50);
+ final DirectPosition lower = envelope.getLowerCorner();
+ final DirectPosition upper = envelope.getUpperCorner();
+ assertEquals(label, 30, envelope.getMinimum (1), STRICT);
+ assertEquals(label, 50, envelope.getMaximum (1), STRICT);
+ assertEquals(label, 40, envelope.getMedian (1), STRICT);
+ assertEquals(label, 20, envelope.getSpan (1), STRICT);
+ assertEquals(label, 12, lower .getOrdinate(0), STRICT);
+ assertEquals(label, -180, envelope.getMinimum (0), STRICT);
+ assertEquals(label, -4, upper .getOrdinate(0), STRICT);
+ assertEquals(label, +180, envelope.getMaximum (0), STRICT);
+ assertEquals(label, -176, envelope.getMedian (0), STRICT);
+ assertEquals(label, 344, envelope.getSpan (0), STRICT); //
360° - testSimpleEnvelope()
+ if (envelope instanceof AbstractEnvelope) {
+ final AbstractEnvelope ext = (AbstractEnvelope) envelope;
+ assertTrue (label, ext.contains (inside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (intersect, false));
+ assertTrue (label, ext.intersects(intersect, false));
+ assertDisjoint(ext, disjoint);
+ assertContains(ext, contained);
+ assertContains(ext, spanning);
+ }
+ if (envelope instanceof Rectangle2D) {
+ final Rectangle2D ext = (Rectangle2D) envelope;
+ assertTrue (label, ext.contains (inside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (intersect));
+ assertTrue (label, ext.intersects(intersect));
+ assertDisjoint(ext, disjoint);
+ assertContains(ext, contained);
+ assertContains(ext, spanning);
+ }
+ }
+ }
+
+ /**
+ * Tests a the anti-meridian case with a larger empty space
+ * on the left side.
+ *
+ * {@preformat text
+ * ââââ ââââââââââ
ââââ ââââââ
+ * â â ââââââ or
ââââ¼âââ â âââ
+ * â â ââââââ
ââââ¼âââ â âââ
+ * ââââ ââââââââââ
ââââ ââââââ
+ * }
+ */
+ @Test
+ @Ignore("The tested envelope needs to be associated to CRS:84")
+ public void testCrossingAntiMeridianTwice() {
+ final DirectPosition2D inside = new DirectPosition2D(18, 32);
+ final DirectPosition2D outside = new DirectPosition2D( 3, 32);
+ final Envelope2D contained = (Envelope2D) create(RECTANGLE, 14, 16,
35, 40);
+ final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16,
35, 40);
+ final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, -2, 10,
35, 40);
+ final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8,
35, 40);
+ for (int type=0; type<LAST; type++) {
+ final String label = "Type " + type;
+ final Envelope envelope = create(type, 12, -364, 30, 50);
+ final DirectPosition lower = envelope.getLowerCorner();
+ final DirectPosition upper = envelope.getUpperCorner();
+ assertEquals(label, 30, envelope.getMinimum (1), STRICT);
+ assertEquals(label, 50, envelope.getMaximum (1), STRICT);
+ assertEquals(label, 40, envelope.getMedian (1), STRICT);
+ assertEquals(label, 20, envelope.getSpan (1), STRICT);
+ assertEquals(label, 12, lower .getOrdinate(0), STRICT);
+ assertEquals(label, -180, envelope.getMinimum (0), STRICT);
+ assertEquals(label, -364, upper .getOrdinate(0), STRICT);
+ assertEquals(label, +180, envelope.getMaximum (0), STRICT);
+ assertEquals(label, 4, envelope.getMedian (0), STRICT); //
Note the alternance with the previous test methods.
+ assertEquals(label, NaN, envelope.getSpan (0), STRICT); //
testCrossingAntiMeridian() + 360°.
+ if (envelope instanceof AbstractEnvelope) {
+ final AbstractEnvelope ext = (AbstractEnvelope) envelope;
+ assertTrue (label, ext.contains (inside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (intersect, false));
+ assertTrue (label, ext.intersects(intersect, false));
+ assertFalse(label, ext.contains (spanning, false));
+ assertTrue (label, ext.intersects(spanning, false));
+ assertDisjoint(ext, disjoint);
+ assertContains(ext, contained);
+ }
+ if (envelope instanceof Rectangle2D) {
+ final Rectangle2D ext = (Rectangle2D) envelope;
+ assertTrue (label, ext.contains (inside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (intersect));
+ assertTrue (label, ext.intersects(intersect));
+ assertFalse(label, ext.contains (spanning));
+ assertTrue (label, ext.intersects(spanning));
+ assertDisjoint(ext, disjoint);
+ assertContains(ext, contained);
+ }
+ }
+ }
+
+ /**
+ * Tests a the anti-meridian case with a larger empty space
+ * on the left and right sides.
+ */
+ @Test
+ @Ignore("The tested envelope needs to be associated to CRS:84")
+ public void testCrossingAntiMeridianThreeTimes() {
+ final DirectPosition2D wasInside = new DirectPosition2D(18, 32);
+ final DirectPosition2D outside = new DirectPosition2D( 3, 32);
+ final Envelope2D wasContained = (Envelope2D) create(RECTANGLE, 14, 16,
35, 40);
+ final Envelope2D wasIntersect = (Envelope2D) create(RECTANGLE, -2, 16,
35, 40);
+ final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, -2, 10,
35, 40);
+ final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8,
35, 40);
+ for (int type=0; type<LAST; type++) {
+ final String label = "Type " + type;
+ final Envelope envelope = create(type, 372, -364, 30, 50);
+ final DirectPosition lower = envelope.getLowerCorner();
+ final DirectPosition upper = envelope.getUpperCorner();
+ assertEquals(label, 30, envelope.getMinimum (1), STRICT);
+ assertEquals(label, 50, envelope.getMaximum (1), STRICT);
+ assertEquals(label, 40, envelope.getMedian (1), STRICT);
+ assertEquals(label, 20, envelope.getSpan (1), STRICT);
+ assertEquals(label, 372, lower .getOrdinate(0), STRICT);
+ assertEquals(label, -180, envelope.getMinimum (0), STRICT);
+ assertEquals(label, -364, upper .getOrdinate(0), STRICT);
+ assertEquals(label, +180, envelope.getMaximum (0), STRICT);
+ assertEquals(label, -176, envelope.getMedian (0), STRICT); //
Note the alternance with the previous test methods.
+ assertEquals(label, NaN, envelope.getSpan (0), STRICT); //
testCrossingAntiMeridianTwice() + 360°.
+ if (envelope instanceof AbstractEnvelope) {
+ final AbstractEnvelope ext = (AbstractEnvelope) envelope;
+ assertFalse(label, ext.contains (wasInside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (spanning, false));
+ assertTrue (label, ext.intersects(spanning, false));
+ assertDisjoint(ext, wasIntersect);
+ assertDisjoint(ext, disjoint);
+ assertDisjoint(ext, wasContained);
+ }
+ if (envelope instanceof Rectangle2D) {
+ final Rectangle2D ext = (Rectangle2D) envelope;
+ assertFalse(label, ext.contains (wasInside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (spanning));
+ assertTrue (label, ext.intersects(spanning));
+ assertDisjoint(ext, wasIntersect);
+ assertDisjoint(ext, disjoint);
+ assertDisjoint(ext, wasContained);
+ }
+ }
+ }
+
+ /**
+ * Tests an empty envelope from -0 to 0°
+ */
+ @Test
+ public void testRange0() {
+ final DirectPosition2D wasInside = new DirectPosition2D(18, 32);
+ final DirectPosition2D outside = new DirectPosition2D( 3, 32);
+ final Envelope2D wasContained = (Envelope2D) create(RECTANGLE, 14, 16,
35, 40);
+ final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16,
35, 40);
+ final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8,
35, 40);
+ for (int type=0; type<LAST; type++) {
+ final String label = "Type " + type;
+ final Envelope envelope = create(type, -0.0, 0.0, 30, 50);
+ assertEquals(label, 30, envelope.getMinimum(1), STRICT);
+ assertEquals(label, 50, envelope.getMaximum(1), STRICT);
+ assertEquals(label, 40, envelope.getMedian (1), STRICT);
+ assertEquals(label, 20, envelope.getSpan (1), STRICT);
+ assertEquals(label, -0.0, envelope.getMinimum(0), STRICT);
+ assertEquals(label, 0.0, envelope.getMaximum(0), STRICT);
+ assertEquals(label, 0, envelope.getMedian (0), STRICT);
+ assertEquals(label, 0, envelope.getSpan (0), STRICT);
+ if (envelope instanceof AbstractEnvelope) {
+ final AbstractEnvelope ext = (AbstractEnvelope) envelope;
+ assertFalse(label, ext.contains (wasInside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (intersect, false));
+ assertTrue (label, ext.intersects(intersect, false));
+ assertFalse(label, ext.contains (spanning, false));
+ assertFalse(label, ext.intersects(spanning, false));
+ assertFalse(label, ext.intersects(spanning, false));
+ assertDisjoint(ext, wasContained);
+ }
+ if (envelope instanceof Rectangle2D) {
+ final Rectangle2D ext = (Rectangle2D) envelope;
+ assertFalse(label, ext.contains (wasInside));
+ assertFalse(label, ext.contains (outside));
+ assertFalse(label, ext.contains (intersect));
+ assertTrue (label, ext.intersects(intersect));
+ assertFalse(label, ext.contains (spanning));
+ assertFalse(label, ext.intersects(spanning));
+ assertFalse(label, ext.intersects(spanning));
+ assertDisjoint(ext, wasContained);
+ }
+ }
+ }
+
+ /**
+ * Tests a case crossing the anti-meridian crossing, from 0° to -0°.
+ */
+ @Test
+ @Ignore("The tested envelope needs to be associated to CRS:84")
+ public void testRange360() {
+ final DirectPosition2D inside = new DirectPosition2D(18, 32);
+ final DirectPosition2D wasOutside = new DirectPosition2D( 3, 32);
+ final Envelope2D contained = (Envelope2D) create(RECTANGLE, 14, 16,
35, 40);
+ final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16,
35, 40);
+ final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8,
35, 40);
+ for (int type=0; type<LAST; type++) {
+ final String label = "Type " + type;
+ final Envelope envelope = create(type, 0.0, -0.0, 30, 50);
+ final DirectPosition lower = envelope.getLowerCorner();
+ final DirectPosition upper = envelope.getUpperCorner();
+ assertEquals(label, 30, envelope.getMinimum (1), STRICT);
+ assertEquals(label, 50, envelope.getMaximum (1), STRICT);
+ assertEquals(label, 40, envelope.getMedian (1), STRICT);
+ assertEquals(label, 20, envelope.getSpan (1), STRICT);
+ assertEquals(label, 0.0, lower .getOrdinate(0), STRICT);
+ assertEquals(label, -180, envelope.getMinimum (0), STRICT);
+ assertEquals(label, -0.0, upper .getOrdinate(0), STRICT);
+ assertEquals(label, +180, envelope.getMaximum (0), STRICT);
+ assertEquals(label, 180, envelope.getMedian (0), STRICT);
+ assertEquals(label, 360, envelope.getSpan (0), STRICT);
+ if (envelope instanceof AbstractEnvelope) {
+ final AbstractEnvelope ext = (AbstractEnvelope) envelope;
+ assertTrue(label, ext.contains(inside));
+ assertTrue(label, ext.contains(wasOutside));
+ assertTrue(label, ext.intersects(intersect, false));
+ assertContains(ext, contained);
+ assertContains(ext, spanning);
+ }
+ if (envelope instanceof Rectangle2D) {
+ final Rectangle2D ext = (Rectangle2D) envelope;
+ assertTrue(label, ext.contains(inside));
+ assertTrue(label, ext.contains(wasOutside));
+ assertTrue(label, ext.intersects(intersect));
+ assertContains(ext, contained);
+ assertContains(ext, spanning);
+ }
+ }
+ }
+}
Propchange:
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/referencing/Assert.java
(from r1422657,
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java)
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/referencing/Assert.java?p2=sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/referencing/Assert.java&p1=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java&r1=1422657&r2=1422779&rev=1422779&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java
(original)
+++
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/referencing/Assert.java
Mon Dec 17 07:52:55 2012
@@ -14,41 +14,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.test;
+package org.apache.sis.referencing;
-import java.util.Set;
-import java.util.Map;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.LinkedHashSet;
-import java.util.LinkedHashMap;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RectangularShape;
-import java.awt.image.RenderedImage;
-import javax.swing.tree.TreeNode;
-import javax.xml.parsers.ParserConfigurationException;
-import org.xml.sax.SAXException;
+import java.awt.geom.AffineTransform;
+import javax.measure.unit.Unit;
+import org.opengis.geometry.Envelope;
+import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterValue;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.referencing.operation.Matrix;
+import org.apache.sis.geometry.AbstractEnvelope;
+import org.apache.sis.geometry.GeneralDirectPosition;
-import org.apache.sis.util.CharSequences;
-
-// Related to JDK7
-import java.util.Objects;
+import static java.lang.StrictMath.*;
/**
- * Assertion methods used by the SIS project in addition of the JUnit and
GeoAPI assertions.
+ * Assertion methods used by the {@code sis-referencing} module in addition of
the ones inherited
+ * from other modules and libraries.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.00)
* @version 0.3
* @module
*/
-public strictfp class Assert extends org.opengis.test.Assert {
+public strictfp class Assert extends org.apache.sis.test.Assert {
/**
* For subclass constructor only.
*/
@@ -56,194 +49,112 @@ public strictfp class Assert extends org
}
/**
- * Asserts that two strings are equal, ignoring the differences in EOL
characters.
- * The comparisons is performed one a line-by-line basis. For each line,
leading
- * and trailing spaces are ignored in order to make the comparison
independent of
- * indentation.
- *
- * @param expected The expected string.
- * @param actual The actual string.
- */
- public static void assertMultilinesEquals(final CharSequence expected,
final CharSequence actual) {
- assertArrayEquals(CharSequences.split(expected, '\n'),
CharSequences.split(actual, '\n'));
- }
-
- /**
- * Asserts that two strings are equal, ignoring the differences in EOL
characters.
- * The comparisons is performed one a line-by-line basis. For each line,
leading
- * and trailing spaces are ignored in order to make the comparison
independent of
- * indentation.
- *
- * @param message The message to print in case of failure, or {@code
null} if none.
- * @param expected The expected string.
- * @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'));
- }
-
- /**
- * Asserts that the given set contains the same elements.
- * In case of failure, this method lists the missing or unexpected
elements.
- *
- * @param expected The expected set, or {@code null}.
- * @param actual The actual set, or {@code null}.
+ * Asserts that the given parameter values are equal to the expected ones
within
+ * a positive delta. Only the elements in the given descriptor are
compared, and
+ * the comparisons are done in the units declared in the descriptor.
+ *
+ * @param expected The expected parameter values.
+ * @param actual The actual parameter values.
+ * @param tolerance The tolerance threshold for comparison of numerical
values.
*/
- public static void assertSetEquals(final Set<?> expected, final Set<?>
actual) {
- if (expected != null && actual != null && !expected.isEmpty()) {
- final Set<Object> r = new LinkedHashSet<>(expected);
- assertTrue("The two sets are disjoint.",
r.removeAll(actual));
- assertTrue("The set is missing elements: " + r,
r.isEmpty());
- assertTrue("The set unexpectedly became empty.",
r.addAll(actual));
- assertTrue("The two sets are disjoint.",
r.removeAll(expected));
- assertTrue("The set contains unexpected elements: " + r,
r.isEmpty());
- }
- assertEquals("Set.equals(Object) failed:", expected, actual);
- }
-
- /**
- * Asserts that the given map contains the same entries.
- * In case of failure, this method lists the missing or unexpected entries.
- *
- * @param expected The expected map, or {@code null}.
- * @param actual The actual map, or {@code null}.
- */
- public static void assertMapEquals(final Map<?,?> expected, final Map<?,?>
actual) {
- if (expected != null && actual != null && !expected.isEmpty()) {
- final Map<Object,Object> r = new LinkedHashMap<>(expected);
- for (final Map.Entry<?,?> entry : actual.entrySet()) {
- final Object key = entry.getKey();
- if (!r.containsKey(key)) {
- fail("Unexpected entry for key " + key);
- }
- final Object ve = r.remove(key);
- final Object va = entry.getValue();
- if (!Objects.equals(ve, va)) {
- fail("Wrong value for key " + key + ": expected " + ve + "
but got " + va);
- }
- }
- if (!r.isEmpty()) {
- fail("The map is missing entries: " + r);
- }
- r.putAll(actual);
- for (final Map.Entry<?,?> entry : expected.entrySet()) {
- final Object key = entry.getKey();
- if (!r.containsKey(key)) {
- fail("Missing an entry for key " + key);
- }
- final Object ve = entry.getValue();
- final Object va = r.remove(key);
- if (!Objects.equals(ve, va)) {
- fail("Wrong value for key " + key + ": expected " + ve + "
but got " + va);
- }
+ public static void assertParameterEquals(final ParameterValueGroup
expected,
+ final ParameterValueGroup actual, final double tolerance)
+ {
+ for (final GeneralParameterValue candidate : expected.values()) {
+ if (!(candidate instanceof ParameterValue<?>)) {
+ throw new UnsupportedOperationException("Not yet
implemented.");
}
- if (!r.isEmpty()) {
- fail("The map contains unexpected elements:" + r);
+ final ParameterValue<?> value = (ParameterValue<?>) candidate;
+ final ParameterDescriptor<?> descriptor = value.getDescriptor();
+ final String name = descriptor.getName().getCode();
+ final Unit<?> unit = descriptor.getUnit();
+ final Class<?> valueClass = descriptor.getValueClass();
+ final ParameterValue<?> e = expected.parameter(name);
+ final ParameterValue<?> a = actual .parameter(name);
+ if (unit != null) {
+ final double f = e.doubleValue(unit);
+ assertEquals(name, f, a.doubleValue(unit), tolerance);
+ } else if (valueClass == Float.class || valueClass ==
Double.class) {
+ final double f = e.doubleValue();
+ assertEquals(name, f, a.doubleValue(), tolerance);
+ } else {
+ assertEquals(name, e.getValue(), a.getValue());
}
}
- assertEquals("Map.equals(Object) failed:", expected, actual);
}
/**
- * Ensures that a tree is equals to an other tree.
- * This method invokes itself recursively for every child nodes.
- *
- * @param expected The expected tree, or {@code null}.
- * @param actual The tree to compare with the expected one, or {@code
null}.
- * @return The number of nodes.
+ * Asserts that the given matrix is diagonal, and that all elements on the
diagonal are equal
+ * to the given values. The matrix doesn't need to be square. The last row
is handled especially
+ * if the {@code affine} argument is {@code true}.
+ *
+ * @param expected The values which are expected on the diagonal. If the
length of this array
+ * is less than the matrix size, then the last element in
the array is repeated
+ * for all remaining diagonal elements.
+ * @param affine If {@code true}, then the last row is expected to
contains the value 1
+ * in the last column, and all other columns set to 0.
+ * @param matrix The matrix to test.
+ * @param tolerance The tolerance threshold while comparing floating point
values.
*/
- public static int assertTreeEquals(final TreeNode expected, final TreeNode
actual) {
- if (expected == null) {
- assertNull(actual);
- return 0;
- }
- int n = 1;
- assertNotNull(actual);
- assertEquals("isLeaf()", expected.isLeaf(),
actual.isLeaf());
- assertEquals("getAllowsChildren()", expected.getAllowsChildren(),
actual.getAllowsChildren());
- assertEquals("getChildCount()", expected.getChildCount(),
actual.getChildCount());
- @SuppressWarnings("unchecked") final Enumeration<? extends TreeNode>
ec = expected.children();
- @SuppressWarnings("unchecked") final Enumeration<? extends TreeNode>
ac = actual .children();
-
- int childIndex = 0;
- while (ec.hasMoreElements()) {
- assertTrue("hasMoreElements()", ac.hasMoreElements());
- final TreeNode nextExpected = ec.nextElement();
- final TreeNode nextActual = ac.nextElement();
- final String message = "getChildAt(" + childIndex + ')';
- assertSame(message, nextExpected, expected.getChildAt(childIndex));
- assertSame(message, nextActual, actual .getChildAt(childIndex));
- assertSame("getParent()", expected, nextExpected.getParent());
- assertSame("getParent()", actual, nextActual .getParent());
- assertSame("getIndex(TreeNode)", childIndex,
expected.getIndex(nextExpected));
- assertSame("getIndex(TreeNode)", childIndex, actual
.getIndex(nextActual));
- n += assertTreeEquals(nextExpected, nextActual);
- childIndex++;
+ public static void assertDiagonalEquals(final double[] expected, final
boolean affine,
+ final Matrix matrix, final double tolerance)
+ {
+ final int numRows = matrix.getNumRow();
+ final int numCols = matrix.getNumCol();
+ final StringBuilder buffer = new StringBuilder("matrix(");
+ final int bufferBase = buffer.length();
+ for (int j=0; j<numRows; j++) {
+ for (int i=0; i<numCols; i++) {
+ final double e;
+ if (affine && j == numRows-1) {
+ e = (i == numCols-1) ? 1 : 0;
+ } else if (i == j) {
+ e = expected[min(expected.length-1, i)];
+ } else {
+ e = 0;
+ }
+ buffer.setLength(bufferBase);
+
assertEquals(buffer.append(j).append(',').append(i).append(')').toString(),
+ e, matrix.getElement(j, i), tolerance);
+ }
}
- assertFalse("hasMoreElements()", ac.hasMoreElements());
- assertEquals("toString()", expected.toString(), actual.toString());
- return n;
}
/**
- * Parses two XML tree as DOM documents, and compares the nodes.
- * The inputs given to this method can be any of the following types:
- *
- * <ul>
- * <li>{@link org.w3c.dom.Node}: used directly without further
processing.</li>
- * <li>{@link java.io.File}, {@link java.net.URL} or {@link
java.net.URI}: the
- * stream is opened and parsed as a XML document.</li>
- * <li>{@link String}: The string content is parsed directly as a XML
document.
- * Encoding <strong>must</strong> be UTF-8 (no other encoding is
supported
- * by current implementation of this method).</li>
- * </ul>
- *
- * This method will ignore comments and the optional attributes given in
arguments.
+ * Compares two affine transforms for equality.
*
- * @param expected The expected XML document.
- * @param actual The XML document to compare.
- * @param ignoredAttributes The fully-qualified names of attributes to
ignore
- * (typically {@code "xmlns:*"} and {@code "xsi:schemaLocation"}).
- *
- * @see XMLComparator
- */
- public static void assertXmlEquals(final Object expected, final Object
actual,
- final String... ignoredAttributes)
- {
- assertXmlEquals(expected, actual, 0, ignoredAttributes);
+ * @param expected The expected affine transform.
+ * @param actual The actual affine transform.
+ * @param tolerance The tolerance threshold.
+ */
+ public static void assertTransformEquals(final AffineTransform expected,
final AffineTransform actual, final double tolerance) {
+ assertEquals("scaleX", expected.getScaleX(),
actual.getScaleX(), tolerance);
+ assertEquals("scaleY", expected.getScaleY(),
actual.getScaleY(), tolerance);
+ assertEquals("shearX", expected.getShearX(),
actual.getShearX(), tolerance);
+ assertEquals("shearY", expected.getShearY(),
actual.getShearY(), tolerance);
+ assertEquals("translateX", expected.getTranslateX(),
actual.getTranslateX(), tolerance);
+ assertEquals("translateY", expected.getTranslateY(),
actual.getTranslateY(), tolerance);
}
/**
- * Parses two XML tree as DOM documents, and compares the nodes with the
given tolerance
- * threshold for numerical values. The inputs given to this method can be
any of the types
- * documented {@linkplain #assertXmlEquals(Object, Object, String[])
above}. This method
- * will ignore comments and the optional attributes given in arguments.
- *
- * @param expected The expected XML document.
- * @param actual The XML document to compare.
- * @param tolerance The tolerance threshold for comparison of numerical
values.
- * @param ignoredAttributes The fully-qualified names of attributes to
ignore
- * (typically {@code "xmlns:*"} and {@code "xsi:schemaLocation"}).
+ * Asserts that two rectangles have the same location and the same size.
*
- * @see XMLComparator
+ * @param expected The expected rectangle.
+ * @param actual The rectangle to compare with the expected one.
+ * @param tolx The tolerance threshold on location along the
<var>x</var> axis.
+ * @param toly The tolerance threshold on location along the
<var>y</var> axis.
*/
- public static void assertXmlEquals(final Object expected, final Object
actual,
- final double tolerance, final String... ignoredAttributes)
+ public static void assertRectangleEquals(final RectangularShape expected,
+ final RectangularShape actual, final double tolx, final double
toly)
{
- final XMLComparator comparator;
- try {
- comparator = new XMLComparator(expected, actual);
- } catch (IOException | ParserConfigurationException | SAXException e) {
- // We don't throw directly those exceptions since failing to parse
the XML file can
- // be considered as part of test failures and the JUnit exception
for such failures
- // is AssertionError. Having no checked exception in "assert"
methods allow us to
- // declare the checked exceptions only for the library code being
tested.
- throw new AssertionError(e);
- }
- comparator.tolerance = tolerance;
- comparator.ignoreComments = true;
- comparator.ignoredAttributes.addAll(Arrays.asList(ignoredAttributes));
- comparator.compare();
+ assertEquals("Min X", expected.getMinX(), actual.getMinX(),
tolx);
+ assertEquals("Min Y", expected.getMinY(), actual.getMinY(),
toly);
+ assertEquals("Max X", expected.getMaxX(), actual.getMaxX(),
tolx);
+ assertEquals("Max Y", expected.getMaxY(), actual.getMaxY(),
toly);
+ assertEquals("Center X", expected.getCenterX(), actual.getCenterX(),
tolx);
+ assertEquals("Center Y", expected.getCenterY(), actual.getCenterY(),
toly);
+ assertEquals("Width", expected.getWidth(), actual.getWidth(),
tolx*2);
+ assertEquals("Height", expected.getHeight(), actual.getHeight(),
toly*2);
}
/**
@@ -269,6 +180,33 @@ public strictfp class Assert extends org
}
/**
+ * Tests if the given {@code outer} envelope contains the given {@code
inner} envelope.
+ * This method will also verify class consistency by invoking the {@code
intersects}
+ * method, and by interchanging the arguments.
+ *
+ * @param outer The envelope which is expected to contains the given inner
envelope.
+ * @param inner The envelope which should be contained by the outer
envelope.
+ */
+ public static void assertContains(final AbstractEnvelope outer, final
Envelope inner) {
+ assertTrue("outer.contains(inner)", outer.contains (inner, true));
+ assertTrue("outer.contains(inner)", outer.contains (inner, false));
+ assertTrue("outer.intersects(inner)", outer.intersects(inner, true));
+ assertTrue("outer.intersects(inner)", outer.intersects(inner, false));
+ if (inner instanceof AbstractEnvelope) {
+ final AbstractEnvelope ai = (AbstractEnvelope) inner;
+ assertTrue ("inner.intersects(outer)", ai.intersects(outer, true));
+ assertTrue ("inner.intersects(outer)", ai.intersects(outer,
false));
+ assertFalse("inner.contains(outer)", ai.contains (outer, true));
+ assertFalse("inner.contains(outer)", ai.contains (outer,
false));
+ }
+ final GeneralDirectPosition median = new
GeneralDirectPosition(inner.getDimension());
+ for (int i=median.getDimension(); --i>=0;) {
+ median.setOrdinate(i, inner.getMedian(i));
+ }
+ assertTrue("outer.contains(median)", outer.contains(median));
+ }
+
+ /**
* Tests if the given {@code r1} shape is disjoint with the given {@code
r2} rectangle.
* This method will also verify class consistency by invoking the {@code
contains}
* method, and by interchanging the arguments.
@@ -305,75 +243,43 @@ public strictfp class Assert extends org
}
/**
- * Asserts that two rectangles have the same location and the same size.
- *
- * @param expected The expected rectangle.
- * @param actual The rectangle to compare with the expected one.
- * @param tolx The tolerance threshold on location along the
<var>x</var> axis.
- * @param toly The tolerance threshold on location along the
<var>y</var> axis.
- */
- public static void assertRectangleEquals(final RectangularShape expected,
- final RectangularShape actual, final double tolx, final double
toly)
- {
- assertEquals("Min X", expected.getMinX(), actual.getMinX(),
tolx);
- assertEquals("Min Y", expected.getMinY(), actual.getMinY(),
toly);
- assertEquals("Max X", expected.getMaxX(), actual.getMaxX(),
tolx);
- assertEquals("Max Y", expected.getMaxY(), actual.getMaxY(),
toly);
- assertEquals("Center X", expected.getCenterX(), actual.getCenterX(),
tolx);
- assertEquals("Center Y", expected.getCenterY(), actual.getCenterY(),
toly);
- assertEquals("Width", expected.getWidth(), actual.getWidth(),
tolx*2);
- assertEquals("Height", expected.getHeight(), actual.getHeight(),
toly*2);
- }
-
- /**
- * Asserts that two images have the same origin and the same size.
- *
- * @param expected The image having the expected size.
- * @param actual The image to compare with the expected one.
- */
- public static void assertBoundEquals(final RenderedImage expected, final
RenderedImage actual) {
- assertEquals("Min X", expected.getMinX(), actual.getMinX());
- assertEquals("Min Y", expected.getMinY(), actual.getMinY());
- assertEquals("Width", expected.getWidth(), actual.getWidth());
- assertEquals("Height", expected.getHeight(), actual.getHeight());
- }
-
- /**
- * Serializes the given object in memory, deserialize it and ensures that
the deserialized
- * object is equals to the original one. This method doesn't write
anything to the disk.
- *
- * <p>If the serialization fails, then this method thrown an {@link
AssertionError}
- * as do the other JUnit assertion methods.</p>
- *
- * @param <T> The type of the object to serialize.
- * @param object The object to serialize.
- * @return The deserialized object.
- */
- public static <T> T assertSerializedEquals(final T object) {
- final Object deserialized;
- try {
- final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- try (ObjectOutputStream out = new ObjectOutputStream(buffer)) {
- out.writeObject(object);
- }
- // Now reads the object we just serialized.
- final byte[] data = buffer.toByteArray();
- try (ObjectInputStream in = new ObjectInputStream(new
ByteArrayInputStream(data))) {
- try {
- deserialized = in.readObject();
- } catch (ClassNotFoundException e) {
- throw new AssertionError(e);
+ * Tests if the given {@code e1} envelope is disjoint with the given
{@code e2} envelope.
+ * This method will also verify class consistency by invoking the {@code
contains} method,
+ * and by interchanging the arguments.
+ *
+ * @param e1 The first envelope to test.
+ * @param e2 The second envelope to test.
+ */
+ public static void assertDisjoint(final AbstractEnvelope e1, final
Envelope e2) {
+ assertFalse("e1.intersects(e2)", e1.intersects(e2, false));
+ assertFalse("e1.intersects(e2)", e1.intersects(e2, true));
+ assertFalse("e1.contains(e2)", e1.contains (e2, false));
+ assertFalse("e1.contains(e2)", e1.contains (e2, true));
+ if (e2 instanceof AbstractEnvelope) {
+ final AbstractEnvelope ae = (AbstractEnvelope) e2;
+ assertFalse("e2.intersects(e1)", ae.intersects(e1, false));
+ assertFalse("e2.intersects(e1)", ae.intersects(e1, true));
+ assertFalse("e2.contains(e1)", ae.contains (e1, false));
+ assertFalse("e2.contains(e1)", ae.contains (e1, true));
+ }
+ final int dimension = e1.getDimension();
+ final int numCases = (int) round(pow(3, dimension));
+ final GeneralDirectPosition pos = new GeneralDirectPosition(dimension);
+ for (int index=0; index<numCases; index++) {
+ int n = index;
+ for (int i=0; i<dimension; i++) {
+ final double ordinate;
+ switch (n % 3) {
+ case 0: ordinate = e2.getMinimum(i); break;
+ case 1: ordinate = e2.getMedian (i); break;
+ case 2: ordinate = e2.getMaximum(i); break;
+ default: throw new AssertionError(i);
}
+ pos.setOrdinate(i, ordinate);
+ n /= 3;
}
- } catch (IOException e) {
- throw new AssertionError(e.toString(), e);
+ assertEquals(0, n); // Opportunist check of this assert method.
+ assertFalse("e1.contains(" + pos + ')', e1.contains(pos));
}
- // Compares with the original object and returns it.
- @SuppressWarnings("unchecked")
- final Class<? extends T> type = (Class<? extends T>) object.getClass();
- assertEquals("Deserialized object not equal to the original one.",
object, deserialized);
- assertEquals("Deserialized object has a different hash code.",
- object.hashCode(), deserialized.hashCode());
- return type.cast(deserialized);
}
}
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java?rev=1422779&r1=1422778&r2=1422779&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java
(original)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java
Mon Dec 17 07:52:55 2012
@@ -153,7 +153,7 @@ public final strictfp class MathFunction
final double y = atanh(x);
switch (i) {
case -10: assertEquals(Double.NEGATIVE_INFINITY, y, EPS);
break;
- default: assertEquals(x, Math.tanh(y), EPS);
break;
+ default: assertEquals(x, StrictMath.tanh(y), EPS);
break;
case +10: assertEquals(Double.POSITIVE_INFINITY, y, EPS);
break;
}
}
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java?rev=1422779&r1=1422778&r2=1422779&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/Assert.java
Mon Dec 17 07:52:55 2012
@@ -27,14 +27,12 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.awt.geom.Rectangle2D;
-import java.awt.geom.RectangularShape;
-import java.awt.image.RenderedImage;
import javax.swing.tree.TreeNode;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
-
+import org.apache.sis.util.Utilities;
import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.ComparisonMode;
// Related to JDK7
import java.util.Objects;
@@ -56,6 +54,52 @@ public strictfp class Assert extends org
}
/**
+ * Asserts that the two given objects are not equal.
+ * This method tests all {@link ComparisonMode} except {@code DEBUG}.
+ *
+ * @param o1 The first object.
+ * @param o2 The second object.
+ */
+ public static void assertNotDeepEquals(final Object o1, final Object o2) {
+ assertNotSame("same", o1, o2);
+ assertFalse("equals", Objects .equals (o1,
o2));
+ assertFalse("deepEquals", Objects .deepEquals(o1,
o2));
+ assertFalse("deepEquals(STRICT)", Utilities.deepEquals(o1,
o2, ComparisonMode.STRICT));
+ assertFalse("deepEquals(BY_CONTRACT)", Utilities.deepEquals(o1,
o2, ComparisonMode.BY_CONTRACT));
+ assertFalse("deepEquals(IGNORE_METADATA)", Utilities.deepEquals(o1,
o2, ComparisonMode.IGNORE_METADATA));
+ assertFalse("deepEquals(APPROXIMATIVE)", Utilities.deepEquals(o1,
o2, ComparisonMode.APPROXIMATIVE));
+ }
+
+ /**
+ * Asserts that the two given objects are approximatively equal, while
slightly different.
+ * More specifically, this method asserts that the given objects are equal
according the
+ * {@link ComparisonMode#APPROXIMATIVE} criterion, but not equal according
the
+ * {@link ComparisonMode#IGNORE_METADATA} criterion.
+ *
+ * @param expected The expected object.
+ * @param actual The actual object.
+ */
+ public static void assertAlmostEquals(final Object expected, final Object
actual) {
+ assertFalse("Shall not be strictly equals",
Utilities.deepEquals(expected, actual, ComparisonMode.STRICT));
+ assertFalse("Shall be slightly different",
Utilities.deepEquals(expected, actual, ComparisonMode.IGNORE_METADATA));
+ assertTrue ("Shall be approximatively equals",
Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG));
+ assertTrue ("DEBUG inconsistent with APPROXIMATIVE",
Utilities.deepEquals(expected, actual, ComparisonMode.APPROXIMATIVE));
+ }
+
+ /**
+ * Asserts that the two given objects are equal ignoring metadata.
+ * See {@link ComparisonMode#IGNORE_METADATA} for more information.
+ *
+ * @param expected The expected object.
+ * @param actual The actual object.
+ */
+ public static void assertEqualsIgnoreMetadata(final Object expected, final
Object actual) {
+ assertTrue("Shall be approximatively equals",
Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG));
+ assertTrue("DEBUG inconsistent with APPROXIMATIVE",
Utilities.deepEquals(expected, actual, ComparisonMode.APPROXIMATIVE));
+ assertTrue("Shall be equals, ignoring metadata",
Utilities.deepEquals(expected, actual, ComparisonMode.IGNORE_METADATA));
+ }
+
+ /**
* Asserts that two strings are equal, ignoring the differences in EOL
characters.
* The comparisons is performed one a line-by-line basis. For each line,
leading
* and trailing spaces are ignored in order to make the comparison
independent of
@@ -247,98 +291,6 @@ public strictfp class Assert extends org
}
/**
- * Tests if the given {@code outer} shape contains the given {@code inner}
rectangle.
- * This method will also verify class consistency by invoking the {@code
intersects}
- * method, and by interchanging the arguments.
- *
- * <p>This method can be used for testing the {@code outer} implementation
-
- * it should not be needed for standard JDK implementations.</p>
- *
- * @param outer The shape which is expected to contains the given
rectangle.
- * @param inner The rectangle which should be contained by the shape.
- */
- public static void assertContains(final RectangularShape outer, final
Rectangle2D inner) {
- assertTrue("outer.contains(inner)", outer.contains (inner));
- assertTrue("outer.intersects(inner)", outer.intersects(inner));
- if (outer instanceof Rectangle2D) {
- assertTrue ("inner.intersects(outer)",
inner.intersects((Rectangle2D) outer));
- assertFalse("inner.contains(outer)", inner.contains
((Rectangle2D) outer));
- }
- assertTrue("outer.contains(centerX, centerY)",
- outer.contains(inner.getCenterX(), inner.getCenterY()));
- }
-
- /**
- * Tests if the given {@code r1} shape is disjoint with the given {@code
r2} rectangle.
- * This method will also verify class consistency by invoking the {@code
contains}
- * method, and by interchanging the arguments.
- *
- * <p>This method can be used for testing the {@code r1} implementation -
it should not
- * be needed for standard implementations.</p>
- *
- * @param r1 The first shape to test.
- * @param r2 The second rectangle to test.
- */
- public static void assertDisjoint(final RectangularShape r1, final
Rectangle2D r2) {
- assertFalse("r1.intersects(r2)", r1.intersects(r2));
- assertFalse("r1.contains(r2)", r1.contains(r2));
- if (r1 instanceof Rectangle2D) {
- assertFalse("r2.intersects(r1)", r2.intersects((Rectangle2D) r1));
- assertFalse("r2.contains(r1)", r2.contains ((Rectangle2D) r1));
- }
- for (int i=0; i<9; i++) {
- final double x, y;
- switch (i % 3) {
- case 0: x = r2.getMinX(); break;
- case 1: x = r2.getCenterX(); break;
- case 2: x = r2.getMaxX(); break;
- default: throw new AssertionError(i);
- }
- switch (i / 3) {
- case 0: y = r2.getMinY(); break;
- case 1: y = r2.getCenterY(); break;
- case 2: y = r2.getMaxY(); break;
- default: throw new AssertionError(i);
- }
- assertFalse("r1.contains(" + x + ", " + y + ')', r1.contains(x,
y));
- }
- }
-
- /**
- * Asserts that two rectangles have the same location and the same size.
- *
- * @param expected The expected rectangle.
- * @param actual The rectangle to compare with the expected one.
- * @param tolx The tolerance threshold on location along the
<var>x</var> axis.
- * @param toly The tolerance threshold on location along the
<var>y</var> axis.
- */
- public static void assertRectangleEquals(final RectangularShape expected,
- final RectangularShape actual, final double tolx, final double
toly)
- {
- assertEquals("Min X", expected.getMinX(), actual.getMinX(),
tolx);
- assertEquals("Min Y", expected.getMinY(), actual.getMinY(),
toly);
- assertEquals("Max X", expected.getMaxX(), actual.getMaxX(),
tolx);
- assertEquals("Max Y", expected.getMaxY(), actual.getMaxY(),
toly);
- assertEquals("Center X", expected.getCenterX(), actual.getCenterX(),
tolx);
- assertEquals("Center Y", expected.getCenterY(), actual.getCenterY(),
toly);
- assertEquals("Width", expected.getWidth(), actual.getWidth(),
tolx*2);
- assertEquals("Height", expected.getHeight(), actual.getHeight(),
toly*2);
- }
-
- /**
- * Asserts that two images have the same origin and the same size.
- *
- * @param expected The image having the expected size.
- * @param actual The image to compare with the expected one.
- */
- public static void assertBoundEquals(final RenderedImage expected, final
RenderedImage actual) {
- assertEquals("Min X", expected.getMinX(), actual.getMinX());
- assertEquals("Min Y", expected.getMinY(), actual.getMinY());
- assertEquals("Width", expected.getWidth(), actual.getWidth());
- assertEquals("Height", expected.getHeight(), actual.getHeight());
- }
-
- /**
* Serializes the given object in memory, deserialize it and ensures that
the deserialized
* object is equals to the original one. This method doesn't write
anything to the disk.
*