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

« back to all changes in this revision

Viewing changes to lucene/backwards/src/test/org/apache/lucene/search/function/TestDocValues.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.search.function;
2
 
 
3
 
/**
4
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
5
 
 * contributor license agreements.  See the NOTICE file distributed with
6
 
 * this work for additional information regarding copyright ownership.
7
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
8
 
 * (the "License"); you may not use this file except in compliance with
9
 
 * the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
import org.apache.lucene.util.LuceneTestCase;
21
 
import org.junit.Test;
22
 
 
23
 
/**
24
 
 * DocValues TestCase  
25
 
 */
26
 
public class TestDocValues extends LuceneTestCase {
27
 
 
28
 
  @Test
29
 
  public void testGetMinValue() {
30
 
    float[] innerArray = new float[] { 1.0f, 2.0f, -1.0f, 100.0f };
31
 
    DocValuesTestImpl docValues = new DocValuesTestImpl(innerArray);
32
 
    assertEquals("-1.0f is the min value in the source array", -1.0f, docValues
33
 
        .getMinValue(), 0);
34
 
 
35
 
    // test with without values - NaN
36
 
    innerArray = new float[] {};
37
 
    docValues = new DocValuesTestImpl(innerArray);
38
 
    assertTrue("max is NaN - no values in inner array", Float.isNaN(docValues
39
 
        .getMinValue()));
40
 
  }
41
 
  @Test
42
 
  public void testGetMaxValue() {
43
 
    float[] innerArray = new float[] { 1.0f, 2.0f, -1.0f, 10.0f };
44
 
    DocValuesTestImpl docValues = new DocValuesTestImpl(innerArray);
45
 
    assertEquals("10.0f is the max value in the source array", 10.0f, docValues
46
 
        .getMaxValue(), 0);
47
 
 
48
 
    innerArray = new float[] { -3.0f, -1.0f, -100.0f };
49
 
    docValues = new DocValuesTestImpl(innerArray);
50
 
    assertEquals("-1.0f is the max value in the source array", -1.0f, docValues
51
 
        .getMaxValue(), 0);
52
 
 
53
 
    innerArray = new float[] { -3.0f, -1.0f, 100.0f, Float.MAX_VALUE,
54
 
        Float.MAX_VALUE - 1 };
55
 
    docValues = new DocValuesTestImpl(innerArray);
56
 
    assertEquals(Float.MAX_VALUE + " is the max value in the source array",
57
 
        Float.MAX_VALUE, docValues.getMaxValue(), 0);
58
 
 
59
 
    // test with without values - NaN
60
 
    innerArray = new float[] {};
61
 
    docValues = new DocValuesTestImpl(innerArray);
62
 
    assertTrue("max is NaN - no values in inner array", Float.isNaN(docValues
63
 
        .getMaxValue()));
64
 
  }
65
 
 
66
 
  @Test
67
 
  public void testGetAverageValue() {
68
 
    float[] innerArray = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
69
 
    DocValuesTestImpl docValues = new DocValuesTestImpl(innerArray);
70
 
    assertEquals("the average is 1.0f", 1.0f, docValues.getAverageValue(), 0);
71
 
 
72
 
    innerArray = new float[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f };
73
 
    docValues = new DocValuesTestImpl(innerArray);
74
 
    assertEquals("the average is 3.5f", 3.5f, docValues.getAverageValue(), 0);
75
 
 
76
 
    // test with negative values
77
 
    innerArray = new float[] { -1.0f, 2.0f };
78
 
    docValues = new DocValuesTestImpl(innerArray);
79
 
    assertEquals("the average is 0.5f", 0.5f, docValues.getAverageValue(), 0);
80
 
 
81
 
    // test with without values - NaN
82
 
    innerArray = new float[] {};
83
 
    docValues = new DocValuesTestImpl(innerArray);
84
 
    assertTrue("the average is NaN - no values in inner array", Float
85
 
        .isNaN(docValues.getAverageValue()));
86
 
  }
87
 
 
88
 
  static class DocValuesTestImpl extends DocValues {
89
 
    float[] innerArray;
90
 
 
91
 
    DocValuesTestImpl(float[] innerArray) {
92
 
      this.innerArray = innerArray;
93
 
    }
94
 
 
95
 
    /**
96
 
     * @see org.apache.lucene.search.function.DocValues#floatVal(int)
97
 
     */
98
 
    @Override
99
 
    public float floatVal(int doc) {
100
 
      return innerArray[doc];
101
 
    }
102
 
 
103
 
    /**
104
 
     * @see org.apache.lucene.search.function.DocValues#toString(int)
105
 
     */
106
 
    @Override
107
 
    public String toString(int doc) {
108
 
      return Integer.toString(doc);
109
 
    }
110
 
 
111
 
  }
112
 
 
113
 
}