01: /*
02: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package test.org.mandarax.reference;
19:
20: import java.util.HashSet;
21: import java.util.Iterator;
22:
23: import org.mandarax.kernel.Clause;
24: import org.mandarax.kernel.ClauseSetException;
25: import org.mandarax.util.ClauseIterator;
26:
27: /**
28: * Test adding a fact to a knowledge base. Here we add a set of clauses
29: * and check whether the set of clauses returned by <code>clauses()</code>
30: * is the same (we compare instances of <code>HashSet</code>).
31: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
32: * @version 3.4 <7 March 05>
33: * @since 1.1
34: */
35: public class TestKnowledgeBaseAddClause1 extends TestKnowledgeBase {
36:
37: /**
38: * Constructor.
39: * @param aKnowledgeBase a knowledge base
40: */
41: public TestKnowledgeBaseAddClause1(
42: org.mandarax.kernel.KnowledgeBase aKnowledgeBase) {
43: super (aKnowledgeBase);
44: }
45:
46: /**
47: * Run the test.
48: */
49: public void testKnowledgeBase() {
50: kb.removeAll();
51:
52: // input knowledge
53: HashSet input = new HashSet();
54:
55: input.add(Person.getFact("isFatherOf", "Jens", "Max"));
56: input.add(Person.getRule("isGrandFatherOf", "x", "z",
57: "isFatherOf", "y", "z", "isFatherOf", "x", "y"));
58: input.add(Person.getFact("isFatherOf", "Klaus", "Jens"));
59: input.add(Person.getFact("isBrotherOf", "Lutz", "Klaus"));
60:
61: // add the input to the knowledge base
62: for (Iterator it = input.iterator(); it.hasNext();) {
63: kb.add((Clause) it.next());
64: }
65:
66: // collect output in a set (use set since we do not check
67: // the order
68: HashSet output = new HashSet();
69:
70: try {
71: for (ClauseIterator it = kb.clauses(); it.hasMoreClauses();) {
72: output.add(it.nextClause());
73: }
74:
75: // compare the two sets
76: assertTrue(input.equals(output));
77: } catch (ClauseSetException x) {
78: assertTrue(false);
79: }
80: }
81: }
|