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.ArrayList;
21: import java.util.HashSet;
22: import java.util.Iterator;
23: import java.util.List;
24:
25: import org.mandarax.kernel.Clause;
26: import org.mandarax.kernel.ClauseSetException;
27: import org.mandarax.util.ClauseIterator;
28:
29: /**
30: * Test removing a clause. (Remove a clause set from the middle).
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 TestKnowledgeBaseRemoveClause1 extends TestKnowledgeBase {
36:
37: /**
38: * Constructor.
39: * @param aKnowledgeBase a knowledge base
40: */
41: public TestKnowledgeBaseRemoveClause1(
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: // now remove a fact
67: Clause removed = Person.getFact("isFatherOf", "Klaus", "Jens");
68:
69: kb.remove(removed);
70:
71: // collect output in a set (use set since we do not check
72: // the order
73: List output = new ArrayList();
74:
75: try {
76: for (ClauseIterator it = kb.clauses(); it.hasMoreClauses();) {
77: output.add(it.nextClause());
78: }
79: // compare the two sets
80: assertTrue(output.size() == 3 && !output.contains(removed));
81: }
82:
83: catch (ClauseSetException x) {
84: assertTrue(false);
85: }
86:
87: }
88: }
|