IntListTest.java revision 4cd7b39876bcec03bb1d0c2afa61cbdb7d119eba
1/*
2 * Copyright (C) 2007 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 com.android.dx.util;
18
19import junit.framework.TestCase;
20
21public final class IntListTest extends TestCase {
22    public void test_contains() {
23        for (int sz = 0; sz < 100; sz++) {
24            IntList list = new IntList(sz);
25            for (int i = 0; i < sz; i++) {
26                list.add(i * 2);
27            }
28            for (int i = (sz * 2) - 1; i >= 0; i--) {
29                boolean contains = list.contains(i);
30                if ((i & 1) == 0) {
31                    assertTrue(label(sz, i), contains);
32                } else {
33                    assertFalse(label(sz, i), contains);
34                }
35            }
36            assertFalse(label(sz, -1), list.contains(-1));
37            assertFalse(label(sz, sz * 2), list.contains(sz * 2));
38        }
39    }
40
41    public void test_addSorted() {
42        IntList list = new IntList(2);
43
44        list.add(9);
45        list.add(12);
46
47        assertTrue(list.contains(9));
48        assertTrue(list.contains(12));
49    }
50
51    public void test_addUnsorted() {
52        IntList list = new IntList(2);
53
54        list.add(12);
55        list.add(9);
56
57        assertTrue(list.contains(12));
58        assertTrue(list.contains(9));
59    }
60
61    private static String label(int n, int m) {
62        return "(" + n + "/" + m + ")";
63    }
64}
65