Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2010 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 com.android.gallery3d.util;
     18 
     19 import com.android.gallery3d.util.IntArray;
     20 
     21 import android.test.suitebuilder.annotation.SmallTest;
     22 import android.util.Log;
     23 
     24 import java.util.Arrays;
     25 import junit.framework.TestCase;
     26 
     27 @SmallTest
     28 public class IntArrayTest extends TestCase {
     29     private static final String TAG = "IntArrayTest";
     30 
     31     public void testIntArray() {
     32         IntArray a = new IntArray();
     33         assertEquals(0, a.size());
     34         assertTrue(Arrays.equals(new int[] {}, a.toArray(null)));
     35 
     36         a.add(0);
     37         assertEquals(1, a.size());
     38         assertTrue(Arrays.equals(new int[] {0}, a.toArray(null)));
     39 
     40         a.add(1);
     41         assertEquals(2, a.size());
     42         assertTrue(Arrays.equals(new int[] {0, 1}, a.toArray(null)));
     43 
     44         int[] buf = new int[2];
     45         int[] result = a.toArray(buf);
     46         assertSame(buf, result);
     47 
     48         IntArray b = new IntArray();
     49         for (int i = 0; i < 100; i++) {
     50             b.add(i * i);
     51         }
     52 
     53         assertEquals(100, b.size());
     54         result = b.toArray(buf);
     55         assertEquals(100, result.length);
     56         for (int i = 0; i < 100; i++) {
     57             assertEquals(i * i, result[i]);
     58         }
     59     }
     60 }
     61