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
17package android.graphics;
18
19import java.util.Arrays;
20
21import junit.framework.TestCase;
22
23/**
24 *
25 */
26public class Matrix_DelegateTest extends TestCase {
27
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
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
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        m1.invert(inverse);
56
57        float[] values = new float[9];
58        inverse.getValues(values);
59
60        assertTrue(Arrays.equals(values,
61                new float[]{-1.6666666f, 0.6666667f, 1.0f, 1.3333334f, -0.33333334f, -2.0f, 0.0f,
62                        0.0f, 1.0f}));
63    }
64}
65