001: package test.org.mandarax.reference;
002:
003: /*
004: * Copyright (C) 1999-2004 <a href="mailto:Hans-Henning.Wiesner@bauer-partner.com">Hans-Henning Wiesner</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: import org.mandarax.lib.math.IntArithmetic;
027:
028: /**
029: * Tests unifying of complex terms.
030: * @author <A HREF="mailto:Hans-Henning.Wiesner@bauer-partner.com">Hans-Henning Wiesner</A>
031: * @version 3.4 <7 March 05>
032: * @since 2.2.1
033: */
034: public class TestInferenceEngine17 extends TestInferenceEngineUseMath {
035:
036: /**
037: * Constructor.
038: * @param aKnowledgeBase a new, uninitialized knowledge base that will be used
039: * @param anInferenceEngine the inference engine that will be tested
040: */
041: public TestInferenceEngine17(KnowledgeBase aKnowledgeBase,
042: InferenceEngine anInferenceEngine) {
043: super (aKnowledgeBase, anInferenceEngine);
044: }
045:
046: /**
047: * Add facts and rules to the knowledge base.
048: * @param knowledge org.mandarax.kernel.KnowledgeBase
049: */
050: public void feedKnowledgeBase(KnowledgeBase knowledge) {
051: knowledge.removeAll();
052:
053: knowledge.add(lfs.rule(lfs.prereq(P3, lfs.variable(
054: QUERY_VARIABLE, Integer.class)), lfs.prereq(P1, lfs
055: .cplx(IntArithmetic.PLUS, lfs.cons(new Integer(1),
056: Integer.class), lfs.variable(QUERY_VARIABLE,
057: Integer.class))), lfs.fact(P2, lfs.variable(
058: QUERY_VARIABLE, Integer.class))));
059: knowledge.add(lfs.fact(P3, lfs.cons(new Integer(0),
060: Integer.class)));
061: knowledge.add(lfs.fact(P1, lfs.cons(new Integer(1),
062: Integer.class)));
063: }
064:
065: /**
066: * Get the expected number.
067: * @return the name of the person
068: */
069: int getExpectedNumber() {
070: //RobinsonsUnificationAlgorithm
071: //because no unification of +([1],[0]) and [1] is done
072: //return -1;
073: //ExtendedRobinsonsUnificationAlgorithm
074: return 0;
075: }
076:
077: /**
078: * Get a description of this test case.
079: * This is used by the <code>org.mandarax.demo</code>
080: * package to display the test cases.
081: * @return a brief description of the test case
082: */
083: public String getDescription() {
084: return "Testing complex terms in result sets";
085: }
086:
087: /**
088: * Get the query.
089: * @return a query
090: */
091: public Query getQuery() {
092: return lfs.query(lfs.fact(P2, lfs.variable(QUERY_VARIABLE,
093: Integer.class)), "a query");
094: }
095:
096: /**
097: * Run the test.
098: */
099: public void testInferenceEngine() {
100: LOG_TEST.info("Start Testcase " + getClass().getName()
101: + " , test method: " + "testInferenceEngine()");
102: try {
103: ResultSet rs = ie.query(getQuery(), kb,
104: getCardinalityConstraint(),
105: InferenceEngine.BUBBLE_EXCEPTIONS);
106: int expected = getExpectedNumber();
107: boolean succ = rs.next();
108: if (expected == -1) {
109: assertTrue(!succ);
110: return;
111: }
112: int computed = ((Integer) rs.getResult(Integer.class,
113: QUERY_VARIABLE)).intValue();
114: assertTrue(expected == computed);
115: } catch (InferenceException x) {
116: assertTrue(false);
117: }
118: LOG_TEST.info("Finish Testcase " + getClass().getName()
119: + " , test method: " + "testInferenceEngine()");
120: }
121: }
|