/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn_junit.util; import xbn.util.XBNTestCase; import xbn.AssertException; import xbn.util.RangeConfig; import junit.framework.Test; import junit.framework.TestSuite; import junit.textui.TestRunner; public class JUTRangeConfig extends XBNTestCase { public JUTRangeConfig(String s_name) { super(s_name); } public void test_constructors() { RangeConfig rc = new RangeConfig(); c_assert(-1, false, -1, false, false, rc); rc = new RangeConfig(-5, 5); c_assert(-5, true, 5, true, true, rc); rc = new RangeConfig(-5, true, 5, true); c_assert(-5, true, 5, true, true, rc); //Illegal bounds. try { rc = new RangeConfig(5, true, -5, true); xfail("new RangeConfig(5, true, -5, true) should throw an ax"); } catch(AssertException ax) { xassertTrue(); } //Cloning constructor. rc = new RangeConfig(-5, true, 5, true); rc = new RangeConfig(rc); c_assert(-5, true, 5, true, true, rc); //Cloning constructor, null parameter. try { rc = new RangeConfig(null); xfail("new RangeConfig(null) should throw an ax"); } catch(AssertException ax) { xassertTrue(); } } public void c_assert(int i_min, boolean b_nfrcMin, int i_max, boolean b_nfrcMax, boolean b_restricted, RangeConfig range_config) { xassertTrue(i_min == range_config.getMin()); xassertTrue(i_max == range_config.getMax()); xassertTrue(b_nfrcMin == range_config.isMinEnforced()); xassertTrue(b_nfrcMax == range_config.isMaxEnforced()); xassertTrue(b_restricted == range_config.isRestricted()); } public void test_isValid() { //Anything is valid RangeConfig rc = new RangeConfig(); xassertTrue(rc.isValid(8123740)); rc = new RangeConfig(-5, 5); xassertFalse(rc.isValid(-6)); xassertTrue(rc.isValid(-5)); xassertTrue(rc.isValid(-4)); xassertTrue(rc.isValid(0)); xassertTrue(rc.isValid(4)); xassertTrue(rc.isValid(5)); xassertFalse(rc.isValid(6)); rc = new RangeConfig(-5, true, 5, true); xassertFalse(rc.isValid(-6)); xassertTrue(rc.isValid(-5)); xassertTrue(rc.isValid(-4)); xassertTrue(rc.isValid(0)); xassertTrue(rc.isValid(4)); xassertTrue(rc.isValid(5)); xassertFalse(rc.isValid(6)); rc = new RangeConfig(-5, true, -1, false); xassertFalse(rc.isValid(-6)); xassertTrue(rc.isValid(-5)); xassertTrue(rc.isValid(-4)); xassertTrue(rc.isValid(0)); xassertTrue(rc.isValid(6)); xassertTrue(rc.isValid(6018274)); } public void setUp() throws Exception { super.setUp(); } public void tearDown() throws Exception { super.tearDown(); } public static Test suite() { TestSuite ts = new TestSuite(JUTRangeConfig.class); return ts; } public static void main(String[] as_cmdLineParams) { TestRunner.run(suite()); printSummary(); } }