001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.commons.lang.math;
020:
021: import junit.framework.Test;
022: import junit.framework.TestSuite;
023:
024: /**
025: * Test cases for the {@link LongRange} class.
026: *
027: * @author Stephen Colebourne
028: * @version $Id: LongRangeTest.java 437554 2006-08-28 06:21:41Z bayard $
029: */
030: public final class LongRangeTest extends AbstractRangeTest {
031:
032: public LongRangeTest(String name) {
033: super (name);
034: }
035:
036: public static Test suite() {
037: TestSuite suite = new TestSuite(LongRangeTest.class);
038: suite.setName("LongRange Tests");
039: return suite;
040: }
041:
042: public void setUp() {
043: super .setUp();
044: tenToTwenty = new LongRange(long10, long20);
045: otherRange = new NumberRange(ten, twenty);
046: }
047:
048: protected Range createRange(Integer integer1, Integer integer2) {
049: return new LongRange(integer1, integer2);
050: }
051:
052: protected Range createRange(Integer integer) {
053: return new NumberRange(integer);
054: }
055:
056: //--------------------------------------------------------------------------
057:
058: public void testConstructor1a() {
059: LongRange nr = new LongRange(8L);
060: assertEquals(long8, nr.getMinimumNumber());
061: assertEquals(long8, nr.getMaximumNumber());
062: }
063:
064: public void testConstructor1b() {
065: LongRange nr = new LongRange(long8);
066: assertSame(long8, nr.getMinimumNumber());
067: assertSame(long8, nr.getMaximumNumber());
068:
069: Range r = new LongRange(nonComparableNumber);
070:
071: try {
072: new LongRange(null);
073: fail();
074: } catch (IllegalArgumentException ex) {
075: }
076: }
077:
078: public void testConstructor2a() {
079: LongRange nr = new LongRange(8L, 10L);
080: assertEquals(long8, nr.getMinimumNumber());
081: assertEquals(long10, nr.getMaximumNumber());
082:
083: nr = new LongRange(10L, 8L);
084: assertEquals(long8, nr.getMinimumNumber());
085: assertEquals(long10, nr.getMaximumNumber());
086: }
087:
088: public void testConstructor2b() {
089: LongRange nr = new LongRange(long8, long10);
090: assertSame(long8, nr.getMinimumNumber());
091: assertSame(long10, nr.getMaximumNumber());
092:
093: nr = new LongRange(long10, long8);
094: assertSame(long8, nr.getMinimumNumber());
095: assertSame(long10, nr.getMaximumNumber());
096:
097: nr = new LongRange(long8, long10);
098: assertSame(long8, nr.getMinimumNumber());
099: assertEquals(long10, nr.getMaximumNumber());
100:
101: // not null
102: try {
103: new LongRange(long8, null);
104: fail();
105: } catch (IllegalArgumentException ex) {
106: }
107: try {
108: new LongRange(null, long8);
109: fail();
110: } catch (IllegalArgumentException ex) {
111: }
112: try {
113: new LongRange(null, null);
114: fail();
115: } catch (IllegalArgumentException ex) {
116: }
117: }
118:
119: //--------------------------------------------------------------------------
120:
121: public void testContainsNumber() {
122: assertEquals(false, tenToTwenty.containsNumber(null));
123: assertEquals(true, tenToTwenty
124: .containsNumber(nonComparableNumber));
125:
126: assertEquals(false, tenToTwenty.containsNumber(five));
127: assertEquals(true, tenToTwenty.containsNumber(ten));
128: assertEquals(true, tenToTwenty.containsNumber(fifteen));
129: assertEquals(true, tenToTwenty.containsNumber(twenty));
130: assertEquals(false, tenToTwenty.containsNumber(twentyFive));
131:
132: assertEquals(false, tenToTwenty.containsNumber(long8));
133: assertEquals(true, tenToTwenty.containsNumber(long10));
134: assertEquals(true, tenToTwenty.containsNumber(long12));
135: assertEquals(true, tenToTwenty.containsNumber(long20));
136: assertEquals(false, tenToTwenty.containsNumber(long21));
137:
138: assertEquals(false, tenToTwenty.containsNumber(double8));
139: assertEquals(true, tenToTwenty.containsNumber(double10));
140: assertEquals(true, tenToTwenty.containsNumber(double12));
141: assertEquals(true, tenToTwenty.containsNumber(double20));
142: assertEquals(false, tenToTwenty.containsNumber(double21));
143:
144: assertEquals(false, tenToTwenty.containsNumber(float8));
145: assertEquals(true, tenToTwenty.containsNumber(float10));
146: assertEquals(true, tenToTwenty.containsNumber(float12));
147: assertEquals(true, tenToTwenty.containsNumber(float20));
148: assertEquals(false, tenToTwenty.containsNumber(float21));
149: }
150:
151: public void testContainsLongBig() {
152: LongRange big = new LongRange(Long.MAX_VALUE,
153: Long.MAX_VALUE - 2);
154: assertEquals(true, big.containsLong(Long.MAX_VALUE - 1));
155: assertEquals(false, big.containsLong(Long.MAX_VALUE - 3));
156: }
157:
158: //--------------------------------------------------------------------------
159:
160: }
|