2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import junit.framework.TestCase;
22 * PackedIntVectorTest tests the features of android.util.PackedIntVector.
24 public class PackedIntVectorTest extends TestCase {
26 public void testBasic() throws Exception {
27 for (int width = 0; width < 10; width++) {
28 PackedIntVector p = new PackedIntVector(width);
29 int[] ins = new int[width];
31 for (int height = width * 2; height < width * 4; height++) {
32 assertEquals(p.width(), width);
36 for (int i = 0; i < height; i++) {
45 for (int j = 0; j < width; j++) {
49 if (i == height / 2) {
55 assertEquals(p.size(), i + 1);
57 for (int j = 0; j < width; j++) {
58 if (i == height / 2) {
59 assertEquals(0, p.getValue(at, j));
61 assertEquals(p.getValue(at, j), i + j);
66 // Test setting values.
68 for (int i = 0; i < height; i++) {
69 for (int j = 0; j < width; j++) {
70 p.setValue(i, j, i * j);
72 assertEquals(p.getValue(i, j), i * j);
76 // Test offsetting values.
78 for (int j = 0; j < width; j++) {
79 p.adjustValuesBelow(j * 2, j, j + 27);
82 for (int i = 0; i < height; i++) {
83 for (int j = 0; j < width; j++) {
90 assertEquals(p.getValue(i, j), expect);
94 for (int j = 0; j < width; j++) {
95 p.adjustValuesBelow(j, j, j * j + 14);
98 for (int i = 0; i < height; i++) {
99 for (int j = 0; j < width; j++) {
106 expect += j * j + 14;
109 assertEquals(p.getValue(i, j), expect);
113 // Test undoing offsets.
115 for (int j = 0; j < width; j++) {
116 p.adjustValuesBelow(j * 2, j, -(j + 27));
117 p.adjustValuesBelow(j, j, -(j * j + 14));
120 for (int i = 0; i < height; i++) {
121 for (int j = 0; j < width; j++) {
122 assertEquals(p.getValue(i, j), i * j);
126 // Test deleting rows.
128 while (p.size() > 0) {
129 int osize = p.size();
136 int at = (osize - del) / 2;
139 assertEquals(p.size(), osize - del);
141 for (int i = 0; i < at; i++) {
142 for (int j = 0; j < width; j++) {
143 assertEquals(p.getValue(i, j), i * j);
147 for (int i = at; i < p.size(); i++) {
148 for (int j = 0; j < width; j++) {
149 assertEquals(p.getValue(i, j), (i + height - p.size()) * j);
154 assertEquals(0, p.size());