~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/facet/src/test/org/apache/lucene/util/collections/IntArrayTest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.util.collections;
2
 
 
3
 
import org.junit.Test;
4
 
 
5
 
import org.apache.lucene.util.LuceneTestCase;
6
 
import org.apache.lucene.util.collections.IntArray;
7
 
 
8
 
/**
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
15
 
 *
16
 
 *     http://www.apache.org/licenses/LICENSE-2.0
17
 
 *
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.
23
 
 */
24
 
 
25
 
public class IntArrayTest extends LuceneTestCase {
26
 
  
27
 
  @Test
28
 
  public void test0() {
29
 
    IntArray array = new IntArray();
30
 
    
31
 
    assertEquals(0, array.size());
32
 
    
33
 
    for (int i = 0; i < 100; ++i) {
34
 
      array.addToArray(i);
35
 
    }
36
 
    
37
 
    assertEquals(100, array.size());
38
 
    for (int i = 0; i < 100; ++i) {
39
 
      assertEquals(i, array.get(i));
40
 
    }
41
 
    
42
 
    assertTrue(array.equals(array));
43
 
  }
44
 
  
45
 
  @Test
46
 
  public void test1() {
47
 
    IntArray array = new IntArray();
48
 
    IntArray array2 = new IntArray();
49
 
    
50
 
    assertEquals(0, array.size());
51
 
    
52
 
    for (int i = 0; i < 100; ++i) {
53
 
      array.addToArray(99-i);
54
 
      array2.addToArray(99-i);
55
 
    }
56
 
    
57
 
    assertEquals(100, array.size());
58
 
    for (int i = 0; i < 100; ++i) {
59
 
      assertEquals(i, array.get(99-i));
60
 
    }
61
 
    
62
 
    array.sort();
63
 
    for (int i = 0; i < 100; ++i) {
64
 
      assertEquals(i, array.get(i));
65
 
    }
66
 
 
67
 
    assertTrue(array.equals(array2));
68
 
  }
69
 
  
70
 
  @Test
71
 
  public void test2() {
72
 
    IntArray array = new IntArray();
73
 
    IntArray array2 = new IntArray();
74
 
    IntArray array3 = new IntArray();
75
 
    
76
 
    for (int i = 0; i < 100; ++i) {
77
 
      array.addToArray(i);
78
 
    }
79
 
 
80
 
    for (int i = 0; i < 100; ++i) {
81
 
      array2.addToArray(i*2);
82
 
    }
83
 
 
84
 
    for (int i = 0; i < 50; ++i) {
85
 
      array3.addToArray(i*2);
86
 
    }
87
 
 
88
 
    assertFalse(array.equals(array2));
89
 
    
90
 
    array.intersect(array2);
91
 
    assertTrue(array.equals(array3));
92
 
    assertFalse(array.equals(array2));
93
 
  }
94
 
  
95
 
  @Test
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};
99
 
    
100
 
    IntArray arr = new IntArray();
101
 
    for (int val : original) {
102
 
      arr.addToArray(val);
103
 
    }
104
 
    
105
 
    for (int i = 0; i < toSet.length; i++ ) {
106
 
      int val = toSet[i];
107
 
      arr.set(i, val);
108
 
    }
109
 
    
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));
113
 
    }
114
 
    
115
 
    // Now attempt to set something outside of the array
116
 
    try {
117
 
      arr.set(100, 99);
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
121
 
      // silently
122
 
    }
123
 
    
124
 
  }
125
 
 
126
 
}