Author: desruisseaux
Date: Sun Mar 16 23:11:48 2014
New Revision: 1578177
URL: http://svn.apache.org/r1578177
Log:
Added tests.
Added:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterValueGroupWrapper.java
(with props)
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
(with props)
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java?rev=1578177&r1=1578176&r2=1578177&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorParameters.java
[UTF-8] Sun Mar 16 23:11:48 2014
@@ -62,7 +62,7 @@ import java.util.Objects;
*
* For all matrix or tensor elements, the default value is 1 for elements on
the diagonal (where all indices have
* the same value) and 0 for all other elements. Those default values defines
an <cite>identity matrix</cite>,
- * or <cite>Kroenecker delta tensor</cite>.
+ * or (more generally) <cite>Kroenecker delta tensor</cite>.
*
* <p><b>Parameters are not an efficient storage format for large tensors.</b>
* Parameters are used only for small matrices/tensors to be specified in
coordinate operations or processing libraries.
@@ -89,6 +89,15 @@ import java.util.Objects;
* depends on the {@code "num_row"} and {@code "num_col"} parameter values.
For this reason, the descriptor of
* matrix or tensor parameters is not immutable.
*
+ * {@section Usage}
+ * For creating a new group of parameters for a matrix using the {@link #WKT1}
naming conventions,
+ * on can use the following code:
+ *
+ * {@preformat java
+ * Map<String,?> properties = Collections.singletonMap("name", "My
operation");
+ * ParameterValueGroup p =
TensorParameters.WKT1.createValueGroup(properties);
+ * }
+ *
* @param <E> The type of tensor element values.
*
* @author Martin Desruisseaux (IRD, Geomatys)
@@ -142,7 +151,7 @@ public class TensorParameters<E> impleme
* A small value is sufficient since matrix sizes are usually the maximum
number of
* CRS dimensions (usually 4) plus one.
*/
- private static final int CACHE_SIZE = 5;
+ static final int CACHE_SIZE = 5;
/**
* Maximal cache rank. Memory required by the cache will be {@code
pow(CACHE_SIZE, CACHE_RANK)},
@@ -219,8 +228,8 @@ public class TensorParameters<E> impleme
}
/**
- * Initializes the fields used for cached values: {@link #zero}, {@link
#one}, {@link #valuesArrayType} and the
- * {@link #parameters} array. The later is not assigned to the {@code
parameters} field, but rather returned.
+ * Initializes the fields used for cached values: {@link #zero}, {@link
#one} and the {@link #parameters} array.
+ * The later is not assigned to the {@code parameters} field, but rather
returned.
* Caller shall assign himself the returned value to the {@link
#parameters} field.
*
* <p>This method is invoked by constructor and on deserialization.</p>
@@ -233,12 +242,8 @@ public class TensorParameters<E> impleme
} catch (IllegalArgumentException e) {
// Ignore - zero and one will be left to null.
}
- int rank = dimensions.length;
- if (rank > CACHE_RANK) {
- rank = CACHE_RANK;
- }
int length = 1;
- while (--rank >= 0) {
+ for (int i = Math.min(dimensions.length, CACHE_RANK); --i >= 0;) {
length *= CACHE_SIZE;
}
return new ParameterDescriptor[length];
@@ -291,7 +296,7 @@ public class TensorParameters<E> impleme
* @return The parameter descriptor for the given tensor element.
* @throws IllegalArgumentException If the given array does not have the
expected length or have illegal value.
*/
- public final ParameterDescriptor<E> getElementDescriptor(final int[]
indices) {
+ public final ParameterDescriptor<E> getElementDescriptor(final int...
indices) {
final int cacheIndex = cacheIndex(indices);
if (cacheIndex >= 0) {
final ParameterDescriptor<E> param;
@@ -611,7 +616,7 @@ public class TensorParameters<E> impleme
if (param == numRow || param == numCol) {
continue;
}
- final String name = param.getDescriptor().getName().toString();
+ final String name = param.getDescriptor().getName().getCode();
IllegalArgumentException cause = null;
int[] indices = null;
try {
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java?rev=1578177&r1=1578176&r2=1578177&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/TensorValues.java
[UTF-8] Sun Mar 16 23:11:48 2014
@@ -274,7 +274,7 @@ final class TensorValues<E> extends Abst
* For rank 3, creates ParameterValue[][][];
* etc.
*/
- final Class<?> componentType =
Classes.changeArrayDimension(ParameterValue.class, rank - i);
+ final Class<?> componentType =
Classes.changeArrayDimension(ParameterValue.class, rank - i - 1);
element = Array.newInstance(componentType, actualSize[i]);
if (parent != null) {
parent[indices[i-1]] = element;
@@ -301,7 +301,7 @@ final class TensorValues<E> extends Abst
element = parent[indices[i]];
}
if (element == null) {
- element = descriptors.getElementDescriptor(indices);
+ element = descriptors.getElementDescriptor(indices).createValue();
parent[indices[rank - 1]] = element;
}
return Parameters.cast((ParameterValue<?>) element,
descriptors.getElementType());
@@ -433,7 +433,7 @@ final class TensorValues<E> extends Abst
if (object == this) {
return true; // Slight optimization.
}
- if (super.equals(object)) {
+ if (super.equals(object, mode)) {
final TensorValues<?> that = (TensorValues<?>) object;
return Utilities.deepEquals(descriptors, that.descriptors, mode) &&
Utilities.deepEquals(values(), that.values(), mode);
Added:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterValueGroupWrapper.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterValueGroupWrapper.java?rev=1578177&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterValueGroupWrapper.java
(added)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterValueGroupWrapper.java
[UTF-8] Sun Mar 16 23:11:48 2014
@@ -0,0 +1,55 @@
+/*
+ * 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.parameter;
+
+import java.util.List;
+import org.opengis.parameter.ParameterValue;
+import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptorGroup;
+
+
+/**
+ * {@link ParameterValueGroup} wrapper for hiding the implementation class.
+ * Used when we want to prevent the optimizations detected by checks like
+ * {@code if (x instanceof DefaultParameterValueGroup)}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+final class ParameterValueGroupWrapper implements ParameterValueGroup {
+ /**
+ * The implementation to hide.
+ */
+ private final ParameterValueGroup impl;
+
+ /**
+ * Creates a new wrapper for the given implementation.
+ */
+ ParameterValueGroupWrapper(final ParameterValueGroup impl) {
+ this.impl = impl;
+ }
+
+ @Override public ParameterDescriptorGroup getDescriptor()
{return impl.getDescriptor();}
+ @Override public List<GeneralParameterValue> values()
{return impl.values();}
+ @Override public ParameterValue<?> parameter(String name)
{return impl.parameter(name);}
+ @Override public List<ParameterValueGroup> groups(String name)
{return impl.groups(name);}
+ @Override public ParameterValueGroup addGroup(String name)
{return impl.addGroup(name);}
+ @Override public ParameterValueGroup clone()
{return impl.clone();}
+}
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterValueGroupWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterValueGroupWrapper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java?rev=1578177&r1=1578176&r2=1578177&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorParametersTest.java
[UTF-8] Sun Mar 16 23:11:48 2014
@@ -20,6 +20,7 @@ import java.util.Map;
import java.util.List;
import java.util.Random;
import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptor;
import org.opengis.parameter.GeneralParameterDescriptor;
import org.opengis.referencing.operation.Matrix;
import org.apache.sis.referencing.operation.matrix.Matrices;
@@ -33,7 +34,7 @@ import static java.util.Collections.sing
import static org.opengis.test.Validators.validate;
import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
import static org.apache.sis.parameter.TensorParameters.WKT1;
-import static org.apache.sis.test.MetadataAssert.*;
+import static org.apache.sis.test.Assert.*;
/**
@@ -47,39 +48,117 @@ import static org.apache.sis.test.Metada
@DependsOn(ParametersTest.class)
public final strictfp class TensorParametersTest extends TestCase {
/**
- * Tests the list of WKT descriptors for a 1×1, 2×3 and 3×3 matrices.
+ * Asserts that the given descriptor has the given name and default value.
+ */
+ static void assertDescriptorEquals(final String name, final Number
defaultValue,
+ final GeneralParameterDescriptor actual)
+ {
+ assertEquals(name, actual.getName().getCode());
+ assertEquals(name, defaultValue, ((ParameterDescriptor<?>)
actual).getDefaultValue());
+ }
+
+ /**
+ * Tests {@link TensorParameters#getDimensionDescriptor(int[])}.
+ */
+ @Test
+ public void testGetDimensionDescriptor() {
+ final Integer THREE = 3;
+ assertDescriptorEquals("num_row", THREE,
WKT1.getDimensionDescriptor(0));
+ assertDescriptorEquals("num_col", THREE,
WKT1.getDimensionDescriptor(1));
+ }
+
+ /**
+ * Tests {@link TensorParameters#getElementDescriptor(int[])}.
+ */
+ @Test
+ @DependsOnMethod("testIndicesToName")
+ public void testGetElementDescriptor() {
+ final Double ZERO = 0.0;
+ final Double ONE = 1.0;
+ final ParameterDescriptor<Double> e00 = WKT1.getElementDescriptor(0,
0);
+ final ParameterDescriptor<Double> e01 = WKT1.getElementDescriptor(0,
1);
+ final ParameterDescriptor<Double> e10 = WKT1.getElementDescriptor(1,
0);
+ final ParameterDescriptor<Double> e11 = WKT1.getElementDescriptor(1,
1);
+ assertDescriptorEquals("elt_0_0", ONE, e00);
+ assertDescriptorEquals("elt_0_1", ZERO, e01);
+ assertDescriptorEquals("elt_1_0", ZERO, e10);
+ assertDescriptorEquals("elt_1_1", ONE, e11);
+ assertSame(e00, WKT1.getElementDescriptor(0, 0)); // Test caching.
+ assertSame(e01, WKT1.getElementDescriptor(0, 1));
+ assertSame(e10, WKT1.getElementDescriptor(1, 0));
+ assertSame(e11, WKT1.getElementDescriptor(1, 1));
+ /*
+ * Tests a value outside the cache capacity.
+ */
+ final int row = TensorParameters.CACHE_SIZE + 1;
+ final int col = TensorParameters.CACHE_SIZE + 2;
+ assertDescriptorEquals("elt_" + row + "_" + col, ZERO,
WKT1.getElementDescriptor(row, col));
+ }
+
+ /**
+ * Tests {@link TensorParameters#indicesToName(int[])}.
+ */
+ @Test
+ public void testIndicesToName() {
+ assertEquals("elt_4_8", WKT1.indicesToName(new int[] {4, 8}));
+ assertEquals("elt_7_2", WKT1.indicesToName(new int[] {7, 2}));
+ }
+
+ /**
+ * Tests {@link TensorParameters#nameToIndices(String)}.
*/
@Test
+ public void testNameToIndices() {
+ assertArrayEquals(new int[] {4, 8}, WKT1.nameToIndices("elt_4_8"));
+ assertArrayEquals(new int[] {7, 2}, WKT1.nameToIndices("elt_7_2"));
+ assertNull(WKT1.nameToIndices("other_7_2"));
+ assertNull(WKT1.nameToIndices("elt_7"));
+ try {
+ WKT1.nameToIndices("elt_7_2_3");
+ fail("Should not have parsed a name with too many indices.");
+ } catch (IllegalArgumentException e) {
+ // This is the expected exception.
+ }
+ }
+
+ /**
+ * Tests {@link TensorParameters#descriptors(int[])} for a 1×1, 2×3 and
3×3 matrices.
+ */
+ @Test
+ @DependsOnMethod("testGetElementDescriptor")
public void testDescriptors() {
+ final Double ZERO = 0.0;
+ final Double ONE = 1.0;
+ final Integer THREE = 3;
List<GeneralParameterDescriptor> descriptors = WKT1.descriptors(new
int[] {1, 1});
- assertEquals("num_row", descriptors.get(0).getName().getCode());
- assertEquals("num_col", descriptors.get(1).getName().getCode());
- assertEquals("elt_0_0", descriptors.get(2).getName().getCode());
+ assertDescriptorEquals("num_row", THREE, descriptors.get(0));
+ assertDescriptorEquals("num_col", THREE, descriptors.get(1));
+ assertDescriptorEquals("elt_0_0", ONE, descriptors.get(2));
assertEquals("size", 3, descriptors.size());
descriptors = WKT1.descriptors(new int[] {2, 3});
- assertEquals("num_row", descriptors.get(0).getName().getCode());
- assertEquals("num_col", descriptors.get(1).getName().getCode());
- assertEquals("elt_0_0", descriptors.get(2).getName().getCode());
- assertEquals("elt_0_1", descriptors.get(3).getName().getCode());
- assertEquals("elt_0_2", descriptors.get(4).getName().getCode());
- assertEquals("elt_1_0", descriptors.get(5).getName().getCode());
- assertEquals("elt_1_1", descriptors.get(6).getName().getCode());
- assertEquals("elt_1_2", descriptors.get(7).getName().getCode());
+ assertDescriptorEquals("num_row", THREE, descriptors.get(0));
+ assertDescriptorEquals("num_col", THREE, descriptors.get(1));
+ assertDescriptorEquals("elt_0_0", ONE, descriptors.get(2));
+ assertDescriptorEquals("elt_0_1", ZERO, descriptors.get(3));
+ assertDescriptorEquals("elt_0_2", ZERO, descriptors.get(4));
+ assertDescriptorEquals("elt_1_0", ZERO, descriptors.get(5));
+ assertDescriptorEquals("elt_1_1", ONE, descriptors.get(6));
+ assertDescriptorEquals("elt_1_2", ZERO, descriptors.get(7));
assertEquals("size", 8, descriptors.size());
descriptors = WKT1.descriptors(new int[] {3, 3});
- assertEquals("num_row", descriptors.get( 0).getName().getCode());
- assertEquals("num_col", descriptors.get( 1).getName().getCode());
- assertEquals("elt_0_0", descriptors.get( 2).getName().getCode());
- assertEquals("elt_0_1", descriptors.get( 3).getName().getCode());
- assertEquals("elt_0_2", descriptors.get( 4).getName().getCode());
- assertEquals("elt_1_0", descriptors.get( 5).getName().getCode());
- assertEquals("elt_1_1", descriptors.get( 6).getName().getCode());
- assertEquals("elt_1_2", descriptors.get( 7).getName().getCode());
- assertEquals("elt_2_0", descriptors.get( 8).getName().getCode());
- assertEquals("elt_2_1", descriptors.get( 9).getName().getCode());
- assertEquals("elt_2_2", descriptors.get(10).getName().getCode());
+ assertDescriptorEquals("num_row", THREE, descriptors.get( 0));
+ assertDescriptorEquals("num_col", THREE, descriptors.get( 1));
+ assertDescriptorEquals("elt_0_0", ONE, descriptors.get( 2));
+ assertDescriptorEquals("elt_0_1", ZERO, descriptors.get( 3));
+ assertDescriptorEquals("elt_0_2", ZERO, descriptors.get( 4));
+ assertDescriptorEquals("elt_1_0", ZERO, descriptors.get( 5));
+ assertDescriptorEquals("elt_1_1", ONE, descriptors.get( 6));
+ assertDescriptorEquals("elt_1_2", ZERO, descriptors.get( 7));
+ assertDescriptorEquals("elt_2_0", ZERO, descriptors.get( 8));
+ assertDescriptorEquals("elt_2_1", ZERO, descriptors.get( 9));
+ assertDescriptorEquals("elt_2_2", ONE, descriptors.get(10));
assertEquals("size", 11, descriptors.size());
}
@@ -105,32 +184,12 @@ public final strictfp class TensorParame
assertEquals("num_row", numRow,
group.parameter("num_row").intValue());
assertEquals("num_col", numCol,
group.parameter("num_col").intValue());
assertEquals("elements", matrix, WKT1.toMatrix(group));
+ assertEquals("elements", matrix, WKT1.toMatrix(new
ParameterValueGroupWrapper(group)));
}
}
}
/**
- * Tests WKT formatting.
- */
- @Test
- @DependsOnMethod("testMatrixConversion")
- public void testWKT() {
- final Matrix matrix = Matrices.createIdentity(4);
- matrix.setElement(0,2, 4);
- matrix.setElement(1,0, -2);
- matrix.setElement(2,3, 7);
- final ParameterValueGroup group =
WKT1.createValueGroup(singletonMap(NAME_KEY, "Affine"), matrix);
- validate(group);
- assertWktEquals(
- "ParameterGroup[“Affine”,\n" +
- " Parameter[“num_row”, 4],\n" +
- " Parameter[“num_col”, 4],\n" +
- " Parameter[“elt_0_2”, 4.0],\n" +
- " Parameter[“elt_1_0”, -2.0],\n" +
- " Parameter[“elt_2_3”, 7.0]]", group);
- }
-
- /**
* Tests serialization.
*/
@Test
Added:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java?rev=1578177&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
(added)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
[UTF-8] Sun Mar 16 23:11:48 2014
@@ -0,0 +1,239 @@
+/*
+ * 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.parameter;
+
+import java.util.List;
+import org.opengis.parameter.ParameterValue;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.parameter.GeneralParameterDescriptor;
+import org.opengis.parameter.ParameterNotFoundException;
+import org.opengis.referencing.operation.Matrix;
+import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static java.util.Collections.singletonMap;
+import static org.opengis.test.Validators.validate;
+import static org.apache.sis.parameter.TensorParameters.WKT1;
+import static
org.apache.sis.parameter.TensorParametersTest.assertDescriptorEquals;
+import static org.apache.sis.test.MetadataAssert.*;
+
+
+/**
+ * Tests the {@link TensorValues} class.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+@DependsOn(TensorParametersTest.class)
+public final strictfp class TensorValuesTest extends TestCase {
+ /**
+ * The name of the parameter group created in this test class.
+ */
+ private static final String GROUP_NAME = "Group test";
+
+ /**
+ * Creates an instance for a matrix.
+ */
+ private static ParameterValueGroup create() {
+ return WKT1.createValueGroup(singletonMap(TensorValues.NAME_KEY,
GROUP_NAME));
+ }
+
+ /**
+ * Asserts that the given parameter has the given name and value.
+ */
+ private static void assertValueEquals(final String name, final Number
value, final GeneralParameterValue actual) {
+ assertEquals(name, actual.getDescriptor().getName().getCode());
+ assertEquals(name, value, ((ParameterValue<?>) actual).getValue());
+ }
+
+ /**
+ * Tests {@link TensorValues#descriptors()}.
+ */
+ @Test
+ public void testDescriptors() {
+ final Double ZERO = 0.0;
+ final Double ONE = 1.0;
+ final Integer THREE = 3;
+ final ParameterValueGroup group = create();
+
+ group.parameter("num_row").setValue(1);
+ group.parameter("num_col").setValue(1);
+ List<GeneralParameterDescriptor> descriptors =
group.getDescriptor().descriptors();
+ assertDescriptorEquals("num_row", THREE, descriptors.get(0));
+ assertDescriptorEquals("num_col", THREE, descriptors.get(1));
+ assertDescriptorEquals("elt_0_0", ONE, descriptors.get(2));
+ assertEquals("size", 3, descriptors.size());
+
+ group.parameter("num_row").setValue(2);
+ group.parameter("num_col").setValue(3);
+ descriptors = group.getDescriptor().descriptors();
+ assertDescriptorEquals("num_row", THREE, descriptors.get(0));
+ assertDescriptorEquals("num_col", THREE, descriptors.get(1));
+ assertDescriptorEquals("elt_0_0", ONE, descriptors.get(2));
+ assertDescriptorEquals("elt_0_1", ZERO, descriptors.get(3));
+ assertDescriptorEquals("elt_0_2", ZERO, descriptors.get(4));
+ assertDescriptorEquals("elt_1_0", ZERO, descriptors.get(5));
+ assertDescriptorEquals("elt_1_1", ONE, descriptors.get(6));
+ assertDescriptorEquals("elt_1_2", ZERO, descriptors.get(7));
+ assertEquals("size", 8, descriptors.size());
+ }
+
+ /**
+ * Tests {@link TensorValues#values()}.
+ */
+ @Test
+ @DependsOnMethod("testParameter")
+ public void testValues() {
+ final ParameterValueGroup group = create();
+ group.parameter("num_row").setValue(2);
+ group.parameter("num_col").setValue(3);
+ List<GeneralParameterValue> values = group.values();
+ assertValueEquals("num_row", 2, values.get(0));
+ assertValueEquals("num_col", 3, values.get(1));
+ assertEquals("size", 2, values.size());
+
+ group.parameter("elt_0_1").setValue(8);
+ group.parameter("elt_1_1").setValue(7);
+ group.parameter("elt_1_2").setValue(6);
+ values = group.values();
+ assertValueEquals("num_row", 2, values.get(0));
+ assertValueEquals("num_col", 3, values.get(1));
+ assertValueEquals("elt_0_1", 8.0, values.get(2));
+ assertValueEquals("elt_1_1", 7.0, values.get(3));
+ assertValueEquals("elt_1_2", 6.0, values.get(4));
+ assertEquals("size", 5, values.size());
+ }
+
+ /**
+ * Tests {@link TensorValues#descriptor(String)}.
+ */
+ @Test
+ public void testDescriptor() {
+ final ParameterValueGroup group = create();
+ final ParameterDescriptorGroup d = group.getDescriptor();
+ assertDescriptorEquals("num_row", 3, d.descriptor("num_row"));
+ assertDescriptorEquals("num_col", 3, d.descriptor("num_col"));
+ assertDescriptorEquals("elt_0_0", 1.0, d.descriptor("elt_0_0"));
+ assertDescriptorEquals("elt_2_2", 1.0, d.descriptor("elt_2_2"));
+ /*
+ * If we reduce the matrix size, than it shall not be possible
+ * anymore to get the descriptor in the row that we removed.
+ */
+ group.parameter("num_col").setValue(2);
+ try {
+ d.descriptor("elt_2_2");
+ fail("elt_2_2 should not exist.");
+ } catch (ParameterNotFoundException e) {
+ final String message = e.getMessage();
+ assertTrue(message, message.contains("elt_2_2"));
+ assertTrue(message, message.contains(GROUP_NAME));
+ }
+ }
+
+ /**
+ * Tests {@link TensorValues#parameter(String)}.
+ */
+ @Test
+ public void testParameter() {
+ final ParameterValueGroup group = create();
+ assertValueEquals("num_row", 3, group.parameter("num_row"));
+ assertValueEquals("num_col", 3, group.parameter("num_col"));
+ assertValueEquals("elt_0_0", 1.0, group.parameter("elt_0_0"));
+ assertValueEquals("elt_2_2", 1.0, group.parameter("elt_2_2"));
+
+ group.parameter("elt_2_2").setValue(8);
+ group.parameter("elt_0_1").setValue(6);
+ assertValueEquals("elt_2_2", 8.0, group.parameter("elt_2_2"));
+ assertValueEquals("elt_0_1", 6.0, group.parameter("elt_0_1"));
+ /*
+ * If we reduce the matrix size, than it shall not be possible
+ * anymore to get the descriptor in the row that we removed.
+ */
+ group.parameter("num_col").setValue(2);
+ try {
+ group.parameter("elt_2_2");
+ fail("elt_2_2 should not exist.");
+ } catch (ParameterNotFoundException e) {
+ final String message = e.getMessage();
+ assertTrue(message, message.contains("elt_2_2"));
+ assertTrue(message, message.contains(GROUP_NAME));
+ }
+ }
+
+ /**
+ * Tests {@link TensorValues#clone()}.
+ */
+ @Test
+ @DependsOnMethod("testParameter")
+ public void testClone() {
+ final ParameterValueGroup group = create();
+ group.parameter("num_row").setValue(2);
+ group.parameter("elt_0_1").setValue(4);
+ group.parameter("elt_1_0").setValue(2);
+ /*
+ * Creates a clone, modify some values, keep other values.
+ */
+ final ParameterValueGroup clone = group.clone();
+ clone.parameter("num_row").setValue(4);
+ clone.parameter("elt_0_1").setValue(3);
+ /*
+ * Verify that changes in cloned values did not affected
+ * values in the original object.
+ */
+ assertEquals(2, group.parameter("num_row").intValue());
+ assertEquals(4, clone.parameter("num_row").intValue());
+ assertEquals(4, group.parameter("elt_0_1").intValue());
+ assertEquals(3, clone.parameter("elt_0_1").intValue());
+ assertEquals(2, group.parameter("elt_1_0").intValue());
+ assertEquals(2, clone.parameter("elt_1_0").intValue());
+ }
+
+ /**
+ * Tests WKT formatting.
+ */
+ @Test
+ public void testWKT() {
+ final Matrix matrix = Matrices.createIdentity(4);
+ matrix.setElement(0,2, 4);
+ matrix.setElement(1,0, -2);
+ matrix.setElement(2,3, 7);
+ final ParameterValueGroup group =
WKT1.createValueGroup(singletonMap(TensorValues.NAME_KEY, "Affine"), matrix);
+ validate(group);
+ assertWktEquals(
+ "ParameterGroup[“Affine”,\n" +
+ " Parameter[“num_row”, 4],\n" +
+ " Parameter[“num_col”, 4],\n" +
+ " Parameter[“elt_0_2”, 4.0],\n" +
+ " Parameter[“elt_1_0”, -2.0],\n" +
+ " Parameter[“elt_2_3”, 7.0]]", group);
+ }
+
+ /**
+ * Tests serialization.
+ */
+ @Test
+ public void testSerialization() {
+ assertSerializedEquals(create());
+ }
+}
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/TensorValuesTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1578177&r1=1578176&r2=1578177&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Sun Mar 16 23:11:48 2014
@@ -59,6 +59,7 @@ import org.junit.BeforeClass;
org.apache.sis.parameter.ParameterBuilderTest.class,
org.apache.sis.parameter.ParameterFormatTest.class,
org.apache.sis.parameter.TensorParametersTest.class,
+ org.apache.sis.parameter.TensorValuesTest.class,
org.apache.sis.referencing.datum.BursaWolfParametersTest.class,
org.apache.sis.referencing.datum.TimeDependentBWPTest.class,
org.apache.sis.referencing.datum.DefaultEllipsoidTest.class,