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.apache.commons.geometry.core.GeometryTestUtils;
    20  import org.junit.jupiter.api.Assertions;
    21  import org.junit.jupiter.api.Test;
    22
    23  class AxisAngleSequenceTest {
    24
    25      @Test
    26      void testConstructor() {
    27          // act
    28          final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.RELATIVE, AxisSequence.XYZ, 1, 2, 3);
    29
    30          // assert
    31          Assertions.assertEquals(AxisReferenceFrame.RELATIVE, seq.getReferenceFrame());
    32          Assertions.assertEquals(AxisSequence.XYZ, seq.getAxisSequence());
    33          Assertions.assertEquals(1, seq.getAngle1(), 0.0);
    34          Assertions.assertEquals(2, seq.getAngle2(), 0.0);
    35          Assertions.assertEquals(3, seq.getAngle3(), 0.0);
    36      }
    37
    38      @Test
    39      void testGetAngles() {
    40          // arrange
    41          final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.RELATIVE, AxisSequence.XYZ, 1, 2, 3);
    42
    43          // act
    44          final double[] angles = seq.getAngles();
    45
    46          // assert
    47          Assertions.assertArrayEquals(new double[] {1, 2, 3}, angles, 0.0);
    48      }
    49
    50      @Test
    51      void testHashCode() {
    52          // arrange
    53          final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3);
    54
    55          // act/assert
    56          Assertions.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.RELATIVE, AxisSequence.XYZ, 1, 2, 3).hashCode());
    57          Assertions.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.ZYX, 1, 2, 3).hashCode());
    58          Assertions.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 9, 2, 3).hashCode());
    59          Assertions.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 9, 3).hashCode());
    60          Assertions.assertNotEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 9).hashCode());
    61
    62          Assertions.assertEquals(seq.hashCode(), new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3).hashCode());
    63      }
    64
    65      @Test
    66      void testEquals() {
    67          // arrange
    68          final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3);
    69
    70          // act/assert
    71          GeometryTestUtils.assertSimpleEqualsCases(seq);
    72
    73          Assertions.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.RELATIVE, AxisSequence.XYZ, 1, 2, 3));
    74          Assertions.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.ZYX, 1, 2, 3));
    75          Assertions.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 9, 2, 3));
    76          Assertions.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 9, 3));
    77          Assertions.assertNotEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 9));
    78
    79          Assertions.assertEquals(seq, new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3));
    80      }
    81
    82      @Test
    83      void testEqualsAndHashCode_signedZeroConsistency() {
    84          // arrange
    85          final AxisAngleSequence a = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ,
    86                  0.0, -0.0, 0.0);
    87          final AxisAngleSequence b = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ,
    88                  -0.0, 0.0, -0.0);
    89          final AxisAngleSequence c = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ,
    90                  0.0, -0.0, 0.0);
    91          final AxisAngleSequence d = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ,
    92                  -0.0, 0.0, -0.0);
    93
    94          // act/assert
    95          Assertions.assertFalse(a.equals(b));
    96          Assertions.assertNotEquals(a.hashCode(), b.hashCode());
    97
    98          Assertions.assertTrue(a.equals(c));
    99          Assertions.assertEquals(a.hashCode(), c.hashCode());
    100
    101         Assertions.assertTrue(b.equals(d));
    102         Assertions.assertEquals(b.hashCode(), d.hashCode());
    103     }
    104
    105     @Test
    106     void testToString() {
    107         // arrange
    108         final AxisAngleSequence seq = new AxisAngleSequence(AxisReferenceFrame.ABSOLUTE, AxisSequence.XYZ, 1, 2, 3);
    109
    110         // act
    111         final String str = seq.toString();
    112
    113         // assert
    114         Assertions.assertTrue(str.contains("ABSOLUTE"));
    115         Assertions.assertTrue(str.contains("XYZ"));
    116         Assertions.assertTrue(str.contains("1"));
    117         Assertions.assertTrue(str.contains("2"));
    118         Assertions.assertTrue(str.contains("3"));
    119     }
    120
    121     @Test
    122     void testCreateRelative() {
    123         // act
    124         final AxisAngleSequence seq = AxisAngleSequence.createRelative(AxisSequence.XYZ, 1, 2, 3);
    125
    126         // assert
    127         Assertions.assertEquals(AxisReferenceFrame.RELATIVE, seq.getReferenceFrame());
    128         Assertions.assertEquals(AxisSequence.XYZ, seq.getAxisSequence());
    129         Assertions.assertEquals(1, seq.getAngle1(), 0.0);
    130         Assertions.assertEquals(2, seq.getAngle2(), 0.0);
    131         Assertions.assertEquals(3, seq.getAngle3(), 0.0);
    132     }
    133
    134     @Test
    135     void testCreateAbsolute() {
    136         // act
    137         final AxisAngleSequence seq = AxisAngleSequence.createAbsolute(AxisSequence.XYZ, 1, 2, 3);
    138
    139         // assert
    140         Assertions.assertEquals(AxisReferenceFrame.ABSOLUTE, seq.getReferenceFrame());
    141         Assertions.assertEquals(AxisSequence.XYZ, seq.getAxisSequence());
    142         Assertions.assertEquals(1, seq.getAngle1(), 0.0);
    143         Assertions.assertEquals(2, seq.getAngle2(), 0.0);
    144         Assertions.assertEquals(3, seq.getAngle3(), 0.0);
    145     }
    146 }