001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.lang.math;
019:
020: import junit.framework.Test;
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: /**
025: * <p>
026: * Tests the base methods in the {@link org.apache.commons.lang.math.Range} class.
027: * </p>
028: *
029: * @author Nathan Beyer
030: * @version $Id: RangeTest.java 437554 2006-08-28 06:21:41Z bayard $
031: */
032: public class RangeTest extends TestCase {
033:
034: private static class RangeTestFixture extends Range {
035: private byte max;
036:
037: private byte min;
038:
039: RangeTestFixture(byte min, byte max) {
040: super ();
041: this .min = min;
042: this .max = max;
043: }
044:
045: public boolean containsNumber(Number number) {
046: if (number.byteValue() >= min && number.byteValue() <= max) {
047: return true;
048: }
049: return false;
050: }
051:
052: public Number getMaximumNumber() {
053: return new Byte(max);
054: }
055:
056: public Number getMinimumNumber() {
057: return new Byte(min);
058: }
059: }
060:
061: public static Test suite() {
062: TestSuite suite = new TestSuite(RangeTest.class);
063: suite.setName("Range Tests");
064: return suite;
065: }
066:
067: public RangeTest(String name) {
068: super (name);
069: }
070:
071: protected void setUp() throws Exception {
072: super .setUp();
073: }
074:
075: protected void tearDown() throws Exception {
076: super .tearDown();
077: }
078:
079: /**
080: * Test method for 'org.apache.commons.lang.math.Range.equals(Object)'
081: */
082: public void testEqualsObject() {
083: RangeTestFixture r1 = new RangeTestFixture((byte) 0, (byte) 5);
084: RangeTestFixture r2 = new RangeTestFixture((byte) 0, (byte) 5);
085: RangeTestFixture r3 = new RangeTestFixture((byte) 0, (byte) 10);
086:
087: assertEquals(r1, r1);
088: assertEquals(r1, r2);
089: assertEquals(r2, r2);
090: assertTrue(r1.equals(r1));
091: assertTrue(r2.equals(r2));
092: assertTrue(r3.equals(r3));
093: assertFalse(r2.equals(r3));
094: assertFalse(r2.equals(null));
095: assertFalse(r2.equals("Ni!"));
096: }
097:
098: /**
099: * Test method for 'org.apache.commons.lang.math.Range.hashCode()'
100: */
101: public void testHashCode() {
102: RangeTestFixture r1 = new RangeTestFixture((byte) 0, (byte) 5);
103: RangeTestFixture r2 = new RangeTestFixture((byte) 0, (byte) 5);
104: RangeTestFixture r3 = new RangeTestFixture((byte) 0, (byte) 10);
105:
106: assertEquals(r1.hashCode(), r2.hashCode());
107: assertFalse(r1.hashCode() == r3.hashCode());
108: }
109:
110: /**
111: * Test method for 'org.apache.commons.lang.math.Range.toString()'
112: */
113: public void testToString() {
114: RangeTestFixture r1 = new RangeTestFixture((byte) 0, (byte) 5);
115: assertNotNull(r1.toString());
116: assertNotNull(r1.toString());
117: RangeTestFixture r2 = new RangeTestFixture((byte) 0, (byte) 5);
118: assertNotNull(r2.toString());
119: assertNotNull(r2.toString());
120: RangeTestFixture r3 = new RangeTestFixture((byte) 0, (byte) 10);
121: assertNotNull(r3.toString());
122: assertNotNull(r3.toString());
123: }
124:
125: }
|