1 10 package com.hp.hpl.jena.reasoner.rulesys.impl.oldCode; 11 12 import com.hp.hpl.jena.graph.*; 13 import com.hp.hpl.jena.reasoner.*; 14 import com.hp.hpl.jena.reasoner.rulesys.*; 15 16 import junit.framework.TestCase; 17 import junit.framework.TestSuite; 18 19 25 public class TestTrail extends TestCase { 26 27 Node a = Node.createURI("a"); 28 Node b = Node.createURI("b"); 29 Node c = Node.createURI("c"); 30 Node p = Node.createURI("p"); 31 Node q = Node.createURI("q"); 32 33 36 public TestTrail( String name ) { 37 super( name ); 38 } 39 40 44 public static TestSuite suite() { 45 return new TestSuite( TestTrail.class ); 46 } 47 48 51 public void testUnify() { 52 Node_RuleVariable X = new Node_RuleVariable("x", 0); 53 Node_RuleVariable Y = new Node_RuleVariable("y", 1); 54 Node_RuleVariable Z = new Node_RuleVariable("z", 2); 55 56 Trail trail = new Trail(); 57 assertTrue(trail.unify(new TriplePattern(X, p, Y), new TriplePattern(a, p, b))); 58 assertEquals(X.deref(), a); 59 assertEquals(Y.deref(), b); 60 assertTrue(Z.isUnbound()); 61 trail.unwindAndClear(); 62 assertTrue(X.isUnbound()); 63 assertTrue(Y.isUnbound()); 64 65 assertTrue(trail.unify(new TriplePattern(X, p, X), new TriplePattern(Z, p, a))); 66 assertEquals(X.deref(), a); 67 assertEquals(Z.deref(), a); 68 trail.unwindAndClear(); 69 70 TriplePattern gf = new TriplePattern(X, p, 71 Functor.makeFunctorNode("f", new Node[]{X, b})); 72 TriplePattern hf1 = new TriplePattern(Y, p, 73 Functor.makeFunctorNode("f", new Node[]{Z, b})); 74 TriplePattern hf2 = new TriplePattern(Y, p, 75 Functor.makeFunctorNode("f", new Node[]{a, Y})); 76 TriplePattern hf3 = new TriplePattern(Y, p, 77 Functor.makeFunctorNode("f", new Node[]{b, Y})); 78 assertTrue(trail.unify(gf, hf1)); 79 assertEquals(X.deref(), Y.deref()); 80 assertEquals(X.deref(), Z.deref()); 81 trail.unwindAndClear(); 82 83 assertTrue(! trail.unify(gf, hf2)); 84 assertTrue(X.isUnbound()); 85 assertTrue(Y.isUnbound()); 86 assertTrue(Z.isUnbound()); 87 trail.unwindAndClear(); 88 89 assertTrue(trail.unify(gf, hf3)); 90 assertEquals(X.deref(), b); 91 assertEquals(Y.deref(), b); 92 trail.unwindAndClear(); 93 94 } 95 96 100 public void testMatching() { 101 Node_RuleVariable X = new Node_RuleVariable("x", 0); 102 Node_RuleVariable Y = new Node_RuleVariable("y", 1); 103 Node_RuleVariable Z = new Node_RuleVariable("z", 2); 104 Node_RuleVariable X1 = new Node_RuleVariable("x1", 0); 105 Node_RuleVariable Y1 = new Node_RuleVariable("y1", 1); 106 Node_RuleVariable Z1 = new Node_RuleVariable("z1", 2); 107 108 assertTrue(X.sameValueAs(Y)); 109 TriplePattern f1 = new TriplePattern(X, p, 110 Functor.makeFunctorNode("f", new Node[]{X, b})); 111 TriplePattern f2 = new TriplePattern(Y, p, 112 Functor.makeFunctorNode("f", new Node[]{Z, b})); 113 TriplePattern f3 = new TriplePattern(Y1, p, 114 Functor.makeFunctorNode("f", new Node[]{Y1, b})); 115 TriplePattern f4 = new TriplePattern(X1, p, 116 Functor.makeFunctorNode("f", new Node[]{Z1, b})); 117 assertEquals(f1, f2); 118 assertEquals(f1.hashCode(), f2.hashCode()); 119 assertTrue(f1.variantOf(f3)); 120 assertTrue(f2.variantOf(f4)); 121 assertTrue( ! f1.variantOf(f2)); 122 assertTrue( ! f3.variantOf(f4)); 123 } 124 125 } 126 127 | Popular Tags |