1
package org.apache.lucene.util.collections;
5
import org.apache.lucene.util.LuceneTestCase;
6
import org.apache.lucene.util.collections.IntArray;
9
* Licensed to the Apache Software Foundation (ASF) under one or more
10
* contributor license agreements. See the NOTICE file distributed with
11
* this work for additional information regarding copyright ownership.
12
* The ASF licenses this file to You under the Apache License, Version 2.0
13
* (the "License"); you may not use this file except in compliance with
14
* the License. You may obtain a copy of the License at
16
* http://www.apache.org/licenses/LICENSE-2.0
18
* Unless required by applicable law or agreed to in writing, software
19
* distributed under the License is distributed on an "AS IS" BASIS,
20
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
* See the License for the specific language governing permissions and
22
* limitations under the License.
25
public class IntArrayTest extends LuceneTestCase {
29
IntArray array = new IntArray();
31
assertEquals(0, array.size());
33
for (int i = 0; i < 100; ++i) {
37
assertEquals(100, array.size());
38
for (int i = 0; i < 100; ++i) {
39
assertEquals(i, array.get(i));
42
assertTrue(array.equals(array));
47
IntArray array = new IntArray();
48
IntArray array2 = new IntArray();
50
assertEquals(0, array.size());
52
for (int i = 0; i < 100; ++i) {
53
array.addToArray(99-i);
54
array2.addToArray(99-i);
57
assertEquals(100, array.size());
58
for (int i = 0; i < 100; ++i) {
59
assertEquals(i, array.get(99-i));
63
for (int i = 0; i < 100; ++i) {
64
assertEquals(i, array.get(i));
67
assertTrue(array.equals(array2));
72
IntArray array = new IntArray();
73
IntArray array2 = new IntArray();
74
IntArray array3 = new IntArray();
76
for (int i = 0; i < 100; ++i) {
80
for (int i = 0; i < 100; ++i) {
81
array2.addToArray(i*2);
84
for (int i = 0; i < 50; ++i) {
85
array3.addToArray(i*2);
88
assertFalse(array.equals(array2));
90
array.intersect(array2);
91
assertTrue(array.equals(array3));
92
assertFalse(array.equals(array2));
96
public void testSet() {
97
int[] original = new int[] { 2,4,6,8,10,12,14 };
98
int[] toSet = new int[] { 1,3,5,7,9,11};
100
IntArray arr = new IntArray();
101
for (int val : original) {
105
for (int i = 0; i < toSet.length; i++ ) {
110
// Test to see if the set worked correctly
111
for (int i = 0; i < toSet.length; i++ ) {
112
assertEquals(toSet[i], arr.get(i));
115
// Now attempt to set something outside of the array
118
fail("IntArray.set should have thrown an exception for attempting to set outside the array");
119
} catch (ArrayIndexOutOfBoundsException e) {
120
// We expected this to happen so let it fall through