1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.graphics; 18 19 import java.util.Arrays; 20 21 import junit.framework.TestCase; 22 23 /** 24 * 25 */ 26 public class Matrix_DelegateTest extends TestCase { 27 testIdentity()28 public void testIdentity() { 29 Matrix m1 = new Matrix(); 30 31 assertTrue(m1.isIdentity()); 32 33 m1.setValues(new float[]{1, 0, 0, 0, 1, 0, 0, 0, 1}); 34 assertTrue(m1.isIdentity()); 35 } 36 testCopyConstructor()37 public void testCopyConstructor() { 38 Matrix m1 = new Matrix(); 39 Matrix m2 = new Matrix(m1); 40 41 float[] v1 = new float[9]; 42 float[] v2 = new float[9]; 43 m1.getValues(v1); 44 m2.getValues(v2); 45 46 for (int i = 0; i < 9; i++) { 47 assertEquals(v1[i], v2[i]); 48 } 49 } 50 testInvert()51 public void testInvert() { 52 Matrix m1 = new Matrix(); 53 Matrix inverse = new Matrix(); 54 m1.setValues(new float[]{1, 2, 3, 4, 5, 6, 7, 8, 9}); 55 assertFalse(m1.invert(inverse)); 56 57 m1.setValues(new float[]{3, 5, 6, 2, 5, 7, 4, 8, 2}); 58 m1.invert(inverse); 59 float[] values = new float[9]; 60 inverse.getValues(values); 61 62 assertTrue(Arrays.equals(values, 63 new float[]{1.0952381f, -0.9047619f, -0.11904762f, -0.5714286f, 0.42857143f, 64 0.21428572f, 0.0952381f, 0.0952381f, -0.11904762f})); 65 } 66 } 67