001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.math.geometry;
019    
020    import java.lang.reflect.Field;
021    
022    import org.apache.commons.math.geometry.RotationOrder;
023    
024    import junit.framework.*;
025    
026    public class RotationOrderTest
027      extends TestCase {
028    
029      public RotationOrderTest(String name) {
030        super(name);
031      }
032    
033      public void testName() {
034    
035        RotationOrder[] orders = {
036          RotationOrder.XYZ, RotationOrder.XZY, RotationOrder.YXZ,
037          RotationOrder.YZX, RotationOrder.ZXY, RotationOrder.ZYX,
038          RotationOrder.XYX, RotationOrder.XZX, RotationOrder.YXY,
039          RotationOrder.YZY, RotationOrder.ZXZ, RotationOrder.ZYZ
040        };
041    
042        for (int i = 0; i < orders.length; ++i) {
043          assertEquals(getFieldName(orders[i]), orders[i].toString());
044        }
045    
046      }
047    
048      private String getFieldName(RotationOrder order) {
049        try {
050          Field[] fields = RotationOrder.class.getFields();
051          for (int i = 0; i < fields.length; ++i) {
052            if (fields[i].get(null) == order) {
053              return fields[i].getName();
054            }
055          }
056        } catch (IllegalAccessException iae) {
057          // ignored
058        }
059        return "unknown";
060      }
061    
062      public static Test suite() {
063        return new TestSuite(RotationOrderTest.class);
064      }
065    
066    }