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.Iterator;
22: import java.util.List;
23:
24: import org.mandarax.kernel.Clause;
25: import org.mandarax.kernel.ClauseSetException;
26: import org.mandarax.util.ClauseIterator;
27:
28: /**
29: * Test removing a clause. (Test whether clauses retain their order if last clause is removed).
30: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
31: * @version 3.4 <7 March 05>
32: * @since 1.7.2
33: */
34: public class TestKnowledgeBaseRemoveClause5 extends TestKnowledgeBase {
35:
36: /**
37: * Constructor.
38: * @param aKnowledgeBase a knowledge base
39: */
40: public TestKnowledgeBaseRemoveClause5(
41: org.mandarax.kernel.KnowledgeBase aKnowledgeBase) {
42: super (aKnowledgeBase);
43: }
44:
45: /**
46: * Run the test.
47: */
48: public void testKnowledgeBase() {
49: kb.removeAll();
50:
51: // input knowledge
52: ArrayList input = new ArrayList();
53:
54: Clause c1 = Person.getFact("isFatherOf", "Jens", "Max");
55: Clause c2 = Person.getRule("isGrandFatherOf", "x", "z",
56: "isFatherOf", "y", "z", "isFatherOf", "x", "y");
57: Clause c3 = Person.getFact("isFatherOf", "Klaus", "Jens");
58: Clause c4 = Person.getFact("isBrotherOf", "Lutz", "Klaus");
59:
60: input.add(c1);
61: input.add(c2);
62: input.add(c3);
63: input.add(c4);
64:
65: // add the input to the knowledge base
66: for (Iterator it = input.iterator(); it.hasNext();) {
67: kb.add((Clause) it.next());
68: }
69:
70: // now remove a fact
71: Clause removed = c4;
72: kb.remove(c4);
73:
74: // collect output in a set (use set since we do not check
75: // the order
76: List output = new ArrayList();
77:
78: try {
79: for (ClauseIterator it = kb.clauses(); it.hasMoreClauses();) {
80: output.add(it.nextClause());
81: }
82: // compare the two sets
83: assertTrue(output.size() == 3 && !output.contains(removed));
84: }
85:
86: catch (ClauseSetException x) {
87: assertTrue(false);
88: }
89:
90: }
91: }
|