sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1566554 - in /sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter: DefaultParameterDescriptorTest.java DefaultParameterValueTest.java
Date Mon, 10 Feb 2014 10:07:50 GMT
Author: desruisseaux
Date: Mon Feb 10 10:07:50 2014
New Revision: 1566554

URL: http://svn.apache.org/r1566554
Log:
Moved a ParameterDescriptor test which was actually a ParameterValue test.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java?rev=1566554&r1=1566553&r2=1566554&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
[UTF-8] Mon Feb 10 10:07:50 2014
@@ -19,17 +19,15 @@ package org.apache.sis.parameter;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Locale;
+import javax.measure.unit.SI;
 import javax.measure.unit.Unit;
-import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.parameter.InvalidParameterValueException;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
-import static javax.measure.unit.SI.*;
 import static org.opengis.test.Validators.*;
 
 
@@ -44,18 +42,6 @@ import static org.opengis.test.Validator
 @DependsOn(org.apache.sis.referencing.AbstractIdentifiedObjectTest.class)
 public final strictfp class DefaultParameterDescriptorTest extends TestCase {
     /**
-     * Strict tolerance factor for floating point comparisons. In the particular
-     * case of this test suite, we can afford to be strict since we will perform
-     * arithmetic only on integer values.
-     */
-    private static final double STRICT = 0.0;
-
-    /**
-     * Small tolerance factor for floating point comparisons resulting from some calculation.
-     */
-    private static final double EPS = 1E-10;
-
-    /**
      * Creates the map of properties to be given to {@link DefaultParameterDescriptor} constructor.
      *
      * @param  name The parameter name.
@@ -187,13 +173,12 @@ public final strictfp class DefaultParam
 
     /**
      * Tests {@code DefaultParameterDescriptor} construction for {@link Double} type.
-     * Also tests the {@link Parameter} created from the {@code createValue} method.
      */
     @Test
     public void testDoubleType() {
-        final ParameterDescriptor<Double> descriptor = create("Length measure", 12,
4, 20, METRE);
+        final ParameterDescriptor<Double> descriptor = create("Length measure", 12,
4, 20, SI.METRE);
         assertEquals("name",         "Length measure",   descriptor.getName().getCode());
-        assertEquals("unit",         METRE,              descriptor.getUnit());
+        assertEquals("unit",         SI.METRE,           descriptor.getUnit());
         assertEquals("class",        Double.class,       descriptor.getValueClass());
         assertEquals("defaultValue", Double.valueOf(12), descriptor.getDefaultValue());
         assertEquals("minimum",      Double.valueOf( 4), descriptor.getMinimumValue());
@@ -201,47 +186,6 @@ public final strictfp class DefaultParam
         validate(descriptor);
         assertEquals("DefaultParameterDescriptor[\"Length measure\", mandatory, class=Double,
" +
                 "valid=[4.0 … 20.0], default=12.0, unit=m]", descriptor.toString());
-
-        testDoubleValue(new DefaultParameterValue<>(descriptor));
-    }
-
-    /**
-     * Helper method for {@link #testDoubleType()}.
-     * This method tests a parameter value associated to the descriptor of the above test.
-     *
-     * @return The class of the given parameter, for convenience.
-     */
-    private static void testDoubleValue(final ParameterValue<Double> parameter) {
-        assertEquals("value",    Double.valueOf(12), parameter.getValue());
-        assertEquals("intValue", 12,                 parameter.intValue());
-        assertEquals("unit",     METRE,              parameter.getUnit());
-        validate(parameter);
-
-        for (int i=4; i<=20; i++) {
-            parameter.setValue(i);
-            assertEquals("value", Double.valueOf(i), parameter.getValue());
-            assertEquals("unit",  METRE,             parameter.getUnit());
-            assertEquals("value", i,                 parameter.doubleValue(METRE), STRICT);
-            assertEquals("value", 100*i,             parameter.doubleValue(CENTIMETRE), STRICT);
-        }
-        try {
-            parameter.setValue(3.0);
-            fail("setValue(< min)");
-        } catch (InvalidParameterValueException exception) {
-            assertEquals("Length measure", exception.getParameterName());
-        }
-        try {
-            parameter.setValue("12");
-            fail("setValue(Sring)");
-        } catch (InvalidParameterValueException exception) {
-            assertEquals("Length measure", exception.getParameterName());
-        }
-        for (int i=400; i<=2000; i+=100) {
-            parameter.setValue(i, CENTIMETRE);
-            assertEquals("value", Double.valueOf(i), parameter.getValue());
-            assertEquals("unit",  CENTIMETRE,        parameter.getUnit());
-            assertEquals("value", i/100,             parameter.doubleValue(METRE), EPS);
-        }
     }
 
     /**
@@ -265,7 +209,7 @@ public final strictfp class DefaultParam
          */
         try {
             new DefaultParameterDescriptor<>(properties("Invalid param"),
-                     String.class, null, "ABC", "AAA", "BBB", METRE, false);
+                     String.class, null, "ABC", "AAA", "BBB", SI.METRE, false);
         } catch (IllegalArgumentException e) {
             assertEquals("Unit of measurement “m” is not valid for “Invalid param”
values.", e.getMessage());
         }

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java?rev=1566554&r1=1566553&r2=1566554&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
[UTF-8] Mon Feb 10 10:07:50 2014
@@ -94,7 +94,7 @@ public final strictfp class DefaultParam
      * invalid operations on it. We test that the invalid operations throw the expected exceptions.
      */
     @Test
-    public void testIntegerType() {
+    public void testInteger() {
         final ParameterValue<Integer> parameter = createOptional("Integer param", 14);
         final ParameterDescriptor<Integer> descriptor = parameter.getDescriptor();
         validate(parameter);
@@ -145,11 +145,12 @@ public final strictfp class DefaultParam
     }
 
     /**
-     * Creates a parameter bounded by some range of integer numbers, and tests values
-     * inside and outside that range. Tests also the usage of values of the wrong type.
+     * Tests a parameter bounded by some range of integer numbers. This method try to set
values inside and
+     * outside the range of valid values, and verify that invalid values causes an exception
to be thrown.
+     * This method tests also the usage of values of the wrong type.
      */
     @Test
-    @DependsOnMethod("testIntegerType")
+    @DependsOnMethod("testInteger")
     public void testBoundedInteger() {
         final DefaultParameterValue<Integer> parameter = new DefaultParameterValue<>(
                 DefaultParameterDescriptorTest.create("Bounded param", 15, -30, +40));
@@ -223,7 +224,7 @@ public final strictfp class DefaultParam
      * Tests a parameter for a floating point value with a unit of measurement.
      */
     @Test
-    public void testDoubleType() {
+    public void testMeasure() {
         final DefaultParameterValue<Double> parameter = create("Numerical param", 3,
SI.METRE);
         final ParameterDescriptor<Double> descriptor = parameter.getDescriptor();
         validate(parameter);
@@ -264,11 +265,11 @@ public final strictfp class DefaultParam
     }
 
     /**
-     * Creates a parameter bounded by some range of floating point numbers, and tests values
+     * Tests a parameter bounded by some range of floating point numbers, and tests values
      * inside and outside that range. Tests also the usage of values of the wrong type.
      */
     @Test
-    @DependsOnMethod("testDoubleType")
+    @DependsOnMethod("testMeasure")
     public void testBoundedDouble() {
         final DefaultParameterValue<Double> parameter = new DefaultParameterValue<>(
                 DefaultParameterDescriptorTest.create("Bounded param", 15.0, -30.0, +40.0,
null));
@@ -309,6 +310,46 @@ public final strictfp class DefaultParam
     }
 
     /**
+     * Tests a floating point parameter with a unit of measurement bounded by a minimum and
maximum values.
+     */
+    @Test
+    @DependsOnMethod({"testMeasure", "testBoundedDouble"})
+    public void testBoundedMeasure() {
+        final DefaultParameterValue<Double> parameter = new DefaultParameterValue<>(
+                DefaultParameterDescriptorTest.create("Length measure", 12, 4, 20, SI.METRE));
+        assertEquals("value",    Double.valueOf(12), parameter.getValue());
+        assertEquals("intValue", 12,                 parameter.intValue());
+        assertEquals("unit",     SI.METRE,           parameter.getUnit());
+        validate(parameter);
+
+        for (int i=4; i<=20; i++) {
+            parameter.setValue(i);
+            assertEquals("value", Double.valueOf(i), parameter.getValue());
+            assertEquals("unit",  SI.METRE,          parameter.getUnit());
+            assertEquals("value", i,                 parameter.doubleValue(SI.METRE), STRICT);
+            assertEquals("value", 100*i,             parameter.doubleValue(SI.CENTIMETRE),
STRICT);
+        }
+        try {
+            parameter.setValue(3.0);
+            fail("setValue(< min)");
+        } catch (InvalidParameterValueException exception) {
+            assertEquals("Length measure", exception.getParameterName());
+        }
+        try {
+            parameter.setValue("12");
+            fail("setValue(Sring)");
+        } catch (InvalidParameterValueException exception) {
+            assertEquals("Length measure", exception.getParameterName());
+        }
+        for (int i=400; i<=2000; i+=100) {
+            parameter.setValue(i, SI.CENTIMETRE);
+            assertEquals("value", Double.valueOf(i), parameter.getValue());
+            assertEquals("unit",  SI.CENTIMETRE,     parameter.getUnit());
+            assertEquals("value", i/100,             parameter.doubleValue(SI.METRE), EPS);
+        }
+    }
+
+    /**
      * Tests a parameter for a code list.
      */
     @Test



Mime
View raw message