001: /*
002: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package test.org.mandarax.reference;
019:
020: import java.util.List;
021: import java.util.Vector;
022:
023: import org.mandarax.reference.DefaultLoopCheckingAlgorithm;
024:
025: /**
026: * An abstract test case class to test the simple loop checker.
027: * Note that we do not check sequences of clauses but sequences of objects (strings).
028: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
029: * @version 3.4 <7 March 05>
030: * @since 1.3
031: */
032: public abstract class TestSimpleLoopChecker extends MandaraxTestCase {
033:
034: /**
035: * Constructor.
036: */
037: public TestSimpleLoopChecker() {
038: super ("testLoopChecker");
039: }
040:
041: /**
042: * Get a description of this test case.
043: * @return a descriptive string
044: */
045: public String getDescription() {
046: return "test case " + getClass().getName();
047: }
048:
049: /**
050: * Get the max pattern length.
051: * @return a value
052: */
053: public abstract int getMaxPatternLength();
054:
055: /**
056: * Get the min recurrence number.
057: * @return a value
058: */
059: public abstract int getMinRecurrenceNumber();
060:
061: /**
062: * Get the number of steps without checks.
063: * @return a value
064: */
065: public abstract int getNumberOfStepsWithoutCheck();
066:
067: /**
068: * Get a sequence of objects to be tested.
069: * @return a list
070: */
071: public abstract List getSequence();
072:
073: /**
074: * merge a list n times with itself
075: * @return a new list
076: * @param list a list
077: * @param times indicates how often the list should be merged with itself
078: */
079: protected List merge(List list, int times) {
080: List newList = new Vector(list.size() * times);
081:
082: for (int i = 0; i < times; i++) {
083: newList.addAll(list);
084: }
085:
086: return newList;
087: }
088:
089: /**
090: * Indicates whether the loop checker should detect an infinite loop.
091: * @return a boolean
092: */
093: public abstract boolean shouldDetectLoop();
094:
095: /**
096: * Run the test.
097: */
098: public void testLoopChecker() {
099: LOG_TEST.info("Start Testcase " + getClass().getName()
100: + " , test method: " + "testLoopChecker()");
101:
102: DefaultLoopCheckingAlgorithm lc = new DefaultLoopCheckingAlgorithm(
103: getMaxPatternLength(), getMinRecurrenceNumber(),
104: getNumberOfStepsWithoutCheck());
105:
106: assertTrue(shouldDetectLoop() == lc
107: .isInfiniteLoop(getSequence()));
108: LOG_TEST.info("Finish Testcase " + getClass().getName()
109: + " , test method: " + "testLoopChecker()");
110: }
111: }
|