001: package test.org.mandarax.reference;
002:
003: /*
004: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: import org.mandarax.kernel.InferenceEngine;
022: import org.mandarax.kernel.InferenceException;
023: import org.mandarax.kernel.KnowledgeBase;
024: import org.mandarax.kernel.Query;
025: import org.mandarax.kernel.ResultSet;
026:
027: /**
028: * Tests functions with a fully instanciated query. The query fails.
029: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
030: * @version 3.4 <7 March 05>
031: * @since 1.9.2
032: */
033: public class TestInferenceEngine15 extends TestInferenceEngineUseMath {
034:
035: /**
036: * Constructor.
037: * @param aKnowledgeBase a new, uninitialized knowledge base that will be used
038: * @param anInferenceEngine the inference engine that will be tested
039: */
040: public TestInferenceEngine15(KnowledgeBase aKnowledgeBase,
041: InferenceEngine anInferenceEngine) {
042: super (aKnowledgeBase, anInferenceEngine);
043: }
044:
045: /**
046: * Add facts and rules to the knowledge base.
047: * @param knowledge org.mandarax.kernel.KnowledgeBase
048: */
049: public void feedKnowledgeBase(KnowledgeBase knowledge) {
050: knowledge.removeAll();
051:
052: knowledge.add(lfs.fact(P1, new Integer(3)));
053: knowledge.add(lfs.rule(lfs.fact(P1, "x"), lfs.fact(P2,
054: new Integer("43"))));
055: }
056:
057: /**
058: * Get the expected number.
059: * @return the name of the person
060: */
061: int getExpectedNumber() {
062: return 43;
063: }
064:
065: /**
066: * Get a description of this test case.
067: * This is used by the <code>org.mandarax.demo</code>
068: * package to display the test cases.
069: * @return a brief description of the test case
070: */
071: public String getDescription() {
072: return "Testing fully instanciated queries (query fails)";
073: }
074:
075: /**
076: * Get the query.
077: * @return a query
078: */
079: public Query getQuery() {
080: return lfs.query(lfs.fact(P2, new Integer(42)), "a query");
081: }
082:
083: /**
084: * Run the test.
085: */
086: public void testInferenceEngine() {
087: LOG_TEST.info("Start Testcase " + getClass().getName()
088: + " , test method: " + "testInferenceEngine()");
089: try {
090: ResultSet rs = ie.query(getQuery(), kb,
091: getCardinalityConstraint(),
092: InferenceEngine.BUBBLE_EXCEPTIONS);
093: assertTrue(!rs.next());
094: } catch (InferenceException x) {
095: assertTrue(false);
096: }
097: LOG_TEST.info("Finish Testcase " + getClass().getName()
098: + " , test method: " + "testInferenceEngine()");
099: }
100:
101: }
|