Fixed bug found by PMD.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1421249 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2012-12-13 12:32:03 +00:00
parent 4a75bce80e
commit f25ba664ed
2 changed files with 18 additions and 1 deletions

View File

@ -90,7 +90,7 @@ public final class Quaternion implements Serializable {
if (v.length != 3) {
throw new DimensionMismatchException(v.length, 3);
}
this.q0 = 0;
this.q0 = scalar;
this.q1 = v[0];
this.q2 = v[1];
this.q3 = v[2];

View File

@ -47,6 +47,23 @@ public class QuaternionTest {
Assert.assertEquals(q3, vP[2], 0);
}
@Test
public final void testAccessors3() {
final double q0 = 2;
final double q1 = 5.4;
final double q2 = 17;
final double q3 = 0.0005;
final Quaternion q = new Quaternion(q0, new double[] { q1, q2, q3 });
final double sP = q.getScalarPart();
final double[] vP = q.getVectorPart();
Assert.assertEquals(q0, sP, 0);
Assert.assertEquals(q1, vP[0], 0);
Assert.assertEquals(q2, vP[1], 0);
Assert.assertEquals(q3, vP[2], 0);
}
@Test(expected=DimensionMismatchException.class)
public void testWrongDimension() {
new Quaternion(new double[] { 1, 2 });