KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > math > LongRangeTest


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.lang.math;
17
18 import junit.framework.Test;
19 import junit.framework.TestSuite;
20
21 /**
22  * Test cases for the {@link LongRange} class.
23  *
24  * @author Stephen Colebourne
25  * @version $Id: LongRangeTest.java 155423 2005-02-26 13:08:30Z dirkv $
26  */

27 public final class LongRangeTest extends AbstractRangeTest {
28
29     public LongRangeTest(String JavaDoc name) {
30         super(name);
31     }
32
33     public static Test suite() {
34         TestSuite suite = new TestSuite(LongRangeTest.class);
35         suite.setName("LongRange Tests");
36         return suite;
37     }
38     
39     public void setUp() {
40         super.setUp();
41         tenToTwenty = new LongRange(long10, long20);
42         otherRange = new NumberRange(ten, twenty);
43     }
44
45     protected Range createRange(Integer JavaDoc integer1, Integer JavaDoc integer2) {
46         return new LongRange(integer1, integer2);
47     }
48     protected Range createRange(Integer JavaDoc integer) {
49         return new NumberRange(integer);
50     }
51     
52     //--------------------------------------------------------------------------
53

54     public void testConstructor1a() {
55         LongRange nr = new LongRange(8L);
56         assertEquals(long8, nr.getMinimumNumber());
57         assertEquals(long8, nr.getMaximumNumber());
58     }
59     
60     public void testConstructor1b() {
61         LongRange nr = new LongRange(long8);
62         assertSame(long8, nr.getMinimumNumber());
63         assertSame(long8, nr.getMaximumNumber());
64         
65         Range r = new LongRange(nonComparable);
66         
67         try {
68             new LongRange(null);
69             fail();
70         } catch (IllegalArgumentException JavaDoc ex) {}
71     }
72     
73     public void testConstructor2a() {
74         LongRange nr = new LongRange(8L, 10L);
75         assertEquals(long8, nr.getMinimumNumber());
76         assertEquals(long10, nr.getMaximumNumber());
77         
78         nr = new LongRange(10L, 8L);
79         assertEquals(long8, nr.getMinimumNumber());
80         assertEquals(long10, nr.getMaximumNumber());
81     }
82
83     public void testConstructor2b() {
84         LongRange nr = new LongRange(long8, long10);
85         assertSame(long8, nr.getMinimumNumber());
86         assertSame(long10, nr.getMaximumNumber());
87         
88         nr = new LongRange(long10, long8);
89         assertSame(long8, nr.getMinimumNumber());
90         assertSame(long10, nr.getMaximumNumber());
91         
92         nr = new LongRange(long8, long10);
93         assertSame(long8, nr.getMinimumNumber());
94         assertEquals(long10, nr.getMaximumNumber());
95         
96         // not null
97
try {
98             new LongRange(long8, null);
99             fail();
100         } catch (IllegalArgumentException JavaDoc ex) {}
101         try {
102             new LongRange(null, long8);
103             fail();
104         } catch (IllegalArgumentException JavaDoc ex) {}
105         try {
106             new LongRange(null, null);
107             fail();
108         } catch (IllegalArgumentException JavaDoc ex) {}
109     }
110
111     //--------------------------------------------------------------------------
112

113     public void testContainsNumber() {
114         assertEquals(false, tenToTwenty.containsNumber(null));
115         assertEquals(true, tenToTwenty.containsNumber(nonComparable));
116         
117         assertEquals(false, tenToTwenty.containsNumber(five));
118         assertEquals(true, tenToTwenty.containsNumber(ten));
119         assertEquals(true, tenToTwenty.containsNumber(fifteen));
120         assertEquals(true, tenToTwenty.containsNumber(twenty));
121         assertEquals(false, tenToTwenty.containsNumber(twentyFive));
122         
123         assertEquals(false, tenToTwenty.containsNumber(long8));
124         assertEquals(true, tenToTwenty.containsNumber(long10));
125         assertEquals(true, tenToTwenty.containsNumber(long12));
126         assertEquals(true, tenToTwenty.containsNumber(long20));
127         assertEquals(false, tenToTwenty.containsNumber(long21));
128         
129         assertEquals(false, tenToTwenty.containsNumber(double8));
130         assertEquals(true, tenToTwenty.containsNumber(double10));
131         assertEquals(true, tenToTwenty.containsNumber(double12));
132         assertEquals(true, tenToTwenty.containsNumber(double20));
133         assertEquals(false, tenToTwenty.containsNumber(double21));
134         
135         assertEquals(false, tenToTwenty.containsNumber(float8));
136         assertEquals(true, tenToTwenty.containsNumber(float10));
137         assertEquals(true, tenToTwenty.containsNumber(float12));
138         assertEquals(true, tenToTwenty.containsNumber(float20));
139         assertEquals(false, tenToTwenty.containsNumber(float21));
140     }
141
142     public void testContainsLongBig() {
143         LongRange big = new LongRange(Long.MAX_VALUE, Long.MAX_VALUE- 2);
144         assertEquals(true, big.containsLong(Long.MAX_VALUE - 1));
145         assertEquals(false, big.containsLong(Long.MAX_VALUE - 3));
146     }
147
148     //--------------------------------------------------------------------------
149

150 }
151
Popular Tags