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.euclidean.threed.Vector3D;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.Test;
22  
23  class AxisSequenceTest {
24  
25      @Test
26      void testAxes() {
27          // act/assert
28          for (final AxisSequence axes : AxisSequence.values()) {
29              checkAxes(axes);
30          }
31      }
32  
33      private void checkAxes(final AxisSequence axes) {
34          // make sure that the name of the enum value matches
35          // the axes it contains
36          final String name = axes.toString();
37  
38          final Vector3D a1 = getAxisForName(name.substring(0, 1));
39          final Vector3D a2 = getAxisForName(name.substring(1, 2));
40          final Vector3D a3 = getAxisForName(name.substring(2, 3));
41  
42          // assert
43          Assertions.assertEquals(a1, axes.getAxis1());
44          Assertions.assertEquals(a2, axes.getAxis2());
45          Assertions.assertEquals(a3, axes.getAxis3());
46  
47          Assertions.assertArrayEquals(new Vector3D[] {a1, a2, a3}, axes.toArray());
48      }
49  
50      private Vector3D getAxisForName(final String name) {
51          if ("X".equals(name)) {
52              return Vector3D.Unit.PLUS_X;
53          }
54          if ("Y".equals(name)) {
55              return Vector3D.Unit.PLUS_Y;
56          }
57          if ("Z".equals(name)) {
58              return Vector3D.Unit.PLUS_Z;
59          }
60          throw new IllegalArgumentException("Unknown axis: " + name);
61      }
62  }