1
package org.apache.lucene.document;
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
11
* http://www.apache.org/licenses/LICENSE-2.0
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.
20
import org.apache.lucene.util.LuceneTestCase;
22
public class TestNumberTools extends LuceneTestCase {
23
public void testNearZero() {
24
for (int i = -100; i <= 100; i++) {
25
for (int j = -100; j <= 100; j++) {
26
subtestTwoLongs(i, j);
31
public void testMax() {
32
// make sure the constants convert to their equivalents
33
assertEquals(Long.MAX_VALUE, NumberTools
34
.stringToLong(NumberTools.MAX_STRING_VALUE));
35
assertEquals(NumberTools.MAX_STRING_VALUE, NumberTools
36
.longToString(Long.MAX_VALUE));
39
for (long l = Long.MAX_VALUE; l > Long.MAX_VALUE - 10000; l--) {
40
subtestTwoLongs(l, l - 1);
44
public void testMin() {
45
// make sure the constants convert to their equivelents
46
assertEquals(Long.MIN_VALUE, NumberTools
47
.stringToLong(NumberTools.MIN_STRING_VALUE));
48
assertEquals(NumberTools.MIN_STRING_VALUE, NumberTools
49
.longToString(Long.MIN_VALUE));
52
for (long l = Long.MIN_VALUE; l < Long.MIN_VALUE + 10000; l++) {
53
subtestTwoLongs(l, l + 1);
57
private static void subtestTwoLongs(long i, long j) {
59
String a = NumberTools.longToString(i);
60
String b = NumberTools.longToString(j);
62
// are they the right length?
63
assertEquals(NumberTools.STR_SIZE, a.length());
64
assertEquals(NumberTools.STR_SIZE, b.length());
66
// are they the right order?
68
assertTrue(a.compareTo(b) < 0);
70
assertTrue(a.compareTo(b) > 0);
75
// can we convert them back to longs?
76
long i2 = NumberTools.stringToLong(a);
77
long j2 = NumberTools.stringToLong(b);
b'\\ No newline at end of file'