View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.commons.geometry.euclidean.threed.rotation;
    18
    19  import org.junit.Assert;
    20  import org.junit.Test;
    21
    22  public class AxisAngleSequenceTest {
    23
    24      @Test
    25      public void testConstructor() {
    26          // act
    27          final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.RELATIVE, AxisSequence.XYZ, 1, 2, 3);
    28
    29          // assert
    30          Assert.assertEquals(AxisReferenceFrame.RELATIVE, seq.getReferenceFrame());
    31          Assert.assertEquals(AxisSequence.XYZ, seq.getAxisSequence());
    32          Assert.assertEquals(1, seq.getAngle1(), 0.0);
    33          Assert.assertEquals(2, seq.getAngle2(), 0.0);
    34          Assert.assertEquals(3, seq.getAngle3(), 0.0);
    35      }
    36
    37      @Test
    38      public void testGetAngles() {
    39          // arrange
    40          final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.RELATIVE, AxisSequence.XYZ, 1, 2, 3);
    41
    42          // act
    43          final double[] angles = seq.getAngles();
    44
    45          // assert
    46          Assert.assertArrayEquals(new double[] {1, 2, 3}, angles, 0.0);
    47      }
    48
    49      @Test
    50      public void testHashCode() {
    51          // arrange
    52          final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3);
    53
    54          // act/assert
    55          Assert.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.RELATIVE, AxisSequence.XYZ, 1, 2, 3).hashCode());
    56          Assert.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.ZYX, 1, 2, 3).hashCode());
    57          Assert.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 9, 2, 3).hashCode());
    58          Assert.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 9, 3).hashCode());
    59          Assert.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 9).hashCode());
    60
    61          Assert.assertEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3).hashCode());
    62      }
    63
    64      @Test
    65      public void testEquals() {
    66          // arrange
    67          final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3);
    68
    69          // act/assert
    70          Assert.assertFalse(seq.equals(null));
    71          Assert.assertNotEquals(seq, new Object());
    72
    73          Assert.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.RELATIVE, AxisSequence.XYZ, 1, 2, 3));
    74          Assert.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.ZYX, 1, 2, 3));
    75          Assert.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 9, 2, 3));
    76          Assert.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 9, 3));
    77          Assert.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 9));
    78
    79          Assert.assertEquals(seq, seq);
    80          Assert.assertEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3));
    81      }
    82
    83      @Test
    84      public void testEqualsAndHashCode_signedZeroConsistency() {
    85          // arrange
    86          final AxisAngleSequence a = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ,
    87                  0.0, -0.0, 0.0);
    88          final AxisAngleSequence b = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ,
    89                  -0.0, 0.0, -0.0);
    90          final AxisAngleSequence c = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ,
    91                  0.0, -0.0, 0.0);
    92          final AxisAngleSequence d = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ,
    93                  -0.0, 0.0, -0.0);
    94
    95          // act/assert
    96          Assert.assertFalse(a.equals(b));
    97          Assert.assertNotEquals(a.hashCode(), b.hashCode());
    98
    99          Assert.assertTrue(a.equals(c));
    100         Assert.assertEquals(a.hashCode(), c.hashCode());
    101
    102         Assert.assertTrue(b.equals(d));
    103         Assert.assertEquals(b.hashCode(), d.hashCode());
    104     }
    105
    106     @Test
    107     public void testToString() {
    108         // arrange
    109         final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3);
    110
    111         // act
    112         final String str = seq.toString();
    113
    114         // assert
    115         Assert.assertTrue(str.contains("ABSOLUTE"));
    116         Assert.assertTrue(str.contains("XYZ"));
    117         Assert.assertTrue(str.contains("1"));
    118         Assert.assertTrue(str.contains("2"));
    119         Assert.assertTrue(str.contains("3"));
    120     }
    121
    122     @Test
    123     public void testCreateRelative() {
    124         // act
    125         final AxisAngleSequence seq = AxisAngleSequence.createRelative(AxisSequence.XYZ, 1, 2, 3);
    126
    127         // assert
    128         Assert.assertEquals(AxisReferenceFrame.RELATIVE, seq.getReferenceFrame());
    129         Assert.assertEquals(AxisSequence.XYZ, seq.getAxisSequence());
    130         Assert.assertEquals(1, seq.getAngle1(), 0.0);
    131         Assert.assertEquals(2, seq.getAngle2(), 0.0);
    132         Assert.assertEquals(3, seq.getAngle3(), 0.0);
    133     }
    134
    135     @Test
    136     public void testCreateAbsolute() {
    137         // act
    138         final AxisAngleSequence seq = AxisAngleSequence.createAbsolute(AxisSequence.XYZ, 1, 2, 3);
    139
    140         // assert
    141         Assert.assertEquals(AxisReferenceFrame.ABSOLUTE, seq.getReferenceFrame());
    142         Assert.assertEquals(AxisSequence.XYZ, seq.getAxisSequence());
    143         Assert.assertEquals(1, seq.getAngle1(), 0.0);
    144         Assert.assertEquals(2, seq.getAngle2(), 0.0);
    145         Assert.assertEquals(3, seq.getAngle3(), 0.0);
    146     }
    147 }