001: /*
002: * MCS Media Computer Software
003: * Copyright (c) 2005 by MCS
004: * --------------------------------------
005: * Created on 23.04.2005 by w.klaas
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019: package de.mcs.jmeasurement.test;
020:
021: import junit.framework.TestCase;
022:
023: /**
024: * This is an extension for the JUnit framework. It can be used for a check
025: * values between a range.
026: * @author w.klaas
027: */
028: public class MCSTestCase extends TestCase {
029:
030: /**
031: * Checks if a value is between a range, including both edges.
032: * @param min minimal value
033: * @param max maximal value
034: * @param value the value to check
035: */
036: public static void assertBetween(final long min, final long max,
037: final long value) {
038: if (!((value >= min) && (value <= max))) {
039: fail("value is not in range. min:" + Long.toString(min)
040: + " max:" + Long.toString(max) + " value:"
041: + Long.toString(value));
042: }
043: }
044:
045: /**
046: * Checks if a value is between a range, including both edges.
047: * @param min minimal value
048: * @param max maximal value
049: * @param value the value to check
050: * @return <code>true</code> if the value is between the min and max, or
051: * <code>false</code> if not.
052: */
053: public static boolean assertBetween(final int min, final int max,
054: final int value) {
055: return ((value >= min) && (value <= max));
056: }
057:
058: /**
059: * Checks if a value is between a range, including both edges.
060: * @param min minimal value
061: * @param max maximal value
062: * @param value the value to check
063: * @return <code>true</code> if the value is between the min and max, or
064: * <code>false</code> if not.
065: */
066: public static boolean assertBetween(final short min,
067: final short max, final short value) {
068: return ((value >= min) && (value <= max));
069: }
070:
071: /**
072: * Checks if a value is between a range, including both edges.
073: * @param min minimal value
074: * @param max maximal value
075: * @param value the value to check
076: * @return <code>true</code> if the value is between the min and max, or
077: * <code>false</code> if not.
078: */
079: public static boolean assertBetween(final byte min, final byte max,
080: final byte value) {
081: return ((value >= min) && (value <= max));
082: }
083:
084: /**
085: * Checks if a value is between a range, including both edges.
086: * @param min minimal value
087: * @param max maximal value
088: * @param value the value to check
089: * @return <code>true</code> if the value is between the min and max, or
090: * <code>false</code> if not.
091: */
092: public static boolean assertBetween(final float min,
093: final float max, final float value) {
094: return ((value >= min) && (value <= max));
095: }
096:
097: /**
098: * Checks if a value is between a range, including both edges.
099: * @param min minimal value
100: * @param max maximal value
101: * @param value the value to check
102: * @return <code>true</code> if the value is between the min and max, or
103: * <code>false</code> if not.
104: */
105: public static boolean assertBetween(final double min,
106: final double max, final double value) {
107: return ((value >= min) && (value <= max));
108: }
109:
110: }
|