Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
24   81   10   6
12   45   0.42   4
4     2.5  
1    
 
  TestNumberTools       Line # 21 24 10 100% 1.0
 
  (3)
 
1    package org.apache.lucene.document;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import junit.framework.TestCase;
20   
 
21    public class TestNumberTools extends TestCase {
 
22  1 toggle public void testNearZero() {
23  202 for (int i = -100; i <= 100; i++) {
24  40602 for (int j = -100; j <= 100; j++) {
25  40401 subtestTwoLongs(i, j);
26    }
27    }
28    }
29   
 
30  1 toggle public void testMax() {
31    // make sure the constants convert to their equivelents
32  1 assertEquals(Long.MAX_VALUE, NumberTools
33    .stringToLong(NumberTools.MAX_STRING_VALUE));
34  1 assertEquals(NumberTools.MAX_STRING_VALUE, NumberTools
35    .longToString(Long.MAX_VALUE));
36   
37    // test near MAX, too
38  10001 for (long l = Long.MAX_VALUE; l > Long.MAX_VALUE - 10000; l--) {
39  10000 subtestTwoLongs(l, l - 1);
40    }
41    }
42   
 
43  1 toggle public void testMin() {
44    // make sure the constants convert to their equivelents
45  1 assertEquals(Long.MIN_VALUE, NumberTools
46    .stringToLong(NumberTools.MIN_STRING_VALUE));
47  1 assertEquals(NumberTools.MIN_STRING_VALUE, NumberTools
48    .longToString(Long.MIN_VALUE));
49   
50    // test near MIN, too
51  10001 for (long l = Long.MIN_VALUE; l < Long.MIN_VALUE + 10000; l++) {
52  10000 subtestTwoLongs(l, l + 1);
53    }
54    }
55   
 
56  60401 toggle private static void subtestTwoLongs(long i, long j) {
57    // convert to strings
58  60401 String a = NumberTools.longToString(i);
59  60401 String b = NumberTools.longToString(j);
60   
61    // are they the right length?
62  60401 assertEquals(NumberTools.STR_SIZE, a.length());
63  60401 assertEquals(NumberTools.STR_SIZE, b.length());
64   
65    // are they the right order?
66  60401 if (i < j) {
67  30100 assertTrue(a.compareTo(b) < 0);
68  30301 } else if (i > j) {
69  30100 assertTrue(a.compareTo(b) > 0);
70    } else {
71  201 assertEquals(a, b);
72    }
73   
74    // can we convert them back to longs?
75  60401 long i2 = NumberTools.stringToLong(a);
76  60401 long j2 = NumberTools.stringToLong(b);
77   
78  60401 assertEquals(i, i2);
79  60401 assertEquals(j, j2);
80    }
81    }