Added a convenience createConstant method for DerivativeStructure.

Thanks to Ajo Fod.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1517789 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2013-08-27 11:15:50 +00:00
parent ee9383b770
commit db0ad53076
2 changed files with 23 additions and 0 deletions

View File

@ -232,6 +232,20 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
return compiler.getOrder();
}
/** Create a constant compatible with instance order and number of parameters.
* <p>
* This method is a convenience factory method, it simply calls
* {@code new DerivativeStructure(getFreeParameters(), getOrder(), c)}
* </p>
* @param c value of the constant
* @return a constant compatible with instance order and number of parameters
* @see #DerivativeStructure(int, int, double)
* @since 3.3
*/
public DerivativeStructure createConstant(final double c) {
return new DerivativeStructure(getFreeParameters(), getOrder(), c);
}
/** {@inheritDoc}
* @since 3.2
*/

View File

@ -89,6 +89,15 @@ public class DerivativeStructureTest extends ExtendedFieldElementAbstractTest<De
}
}
@Test
public void testCreateConstant() {
DerivativeStructure a = new DerivativeStructure(3, 2, 0, 1.3);
DerivativeStructure b = a.createConstant(2.5);
Assert.assertEquals(a.getFreeParameters(), b.getFreeParameters());
Assert.assertEquals(a.getOrder(), b.getOrder());
checkEquals(a.getField().getOne().multiply(2.5), b, 1.0e-15);
}
@Test
public void testPrimitiveAdd() {
for (int maxOrder = 1; maxOrder < 5; ++maxOrder) {