public DifferenceTest() { graphProducer = new AbstractGraphProducer<Difference>() { private Map<Graph, Graph[]> map = new HashMap<>(); @Override protected Difference createNewGraph() { Graph g1 = memGraph(); Graph g2 = memGraph(); Difference d = new Difference(g1, g2); map.put(d, new Graph[] { g1, g2 }); return d; } @Override public Graph[] getDependsOn(Graph d) { Graph[] dg = map.get(d); if (dg == null) { throw new IllegalStateException("graph not in map"); } return dg; } @Override public Graph[] getNotDependsOn(Graph g) { return new Graph[] { memGraph() }; } @Override protected void afterClose(Graph g) { map.remove(g); } }; }
@Override public ExtendedIterator<Triple> _graphBaseFind(Triple s) { return L.isEmpty() ? NullIterator.instance() : super._graphBaseFind(s); } }
@Override public ExtendedIterator<Triple> _graphBaseFind( Triple t ) { return L.find( t ). filterDrop ( ifIn( R ) ); } }
public void testAdd() { Graph l = graphWith( "x R y" ); Graph r = graphWith( "x R y; x R z" ); Difference diff = new Difference( l, r ); assertIsomorphic( graphWith( "" ), diff ); // case 1: add to the left operand diff.add( triple( "p S q" ) ); assertIsomorphic( graphWith( "p S q" ), diff ); assertIsomorphic( graphWith( "x R y; p S q" ), l ); assertIsomorphic( graphWith( "x R y; x R z" ), r ); // case 2: remove from the right, and add to the left operand diff.add( triple( "x R z" ) ); assertIsomorphic( graphWith( "x R z; p S q" ), diff ); assertIsomorphic( graphWith( "x R y; x R z; p S q" ), l ); assertIsomorphic( graphWith( "x R y" ), r ); // case 3: remove from the right operand diff.add( triple( "x R y" ) ); assertIsomorphic( graphWith( "x R y; x R z; p S q" ), diff ); assertIsomorphic( graphWith( "x R y; x R z; p S q" ), l ); assertIsomorphic( graphWith( "" ), r ); }
public void testDelete() { Graph l = graphWith( "x R y; x R z" ); Graph r = graphWith( "x R y" ); Difference diff = new Difference( l, r ); assertIsomorphic( graphWith( "x R z" ), diff ); // case 1: remove non-existent triple is a no-op diff.delete( triple( "p S q" ) ); assertIsomorphic( graphWith( "x R z" ), diff ); assertIsomorphic( graphWith( "x R y; x R z" ), l ); assertIsomorphic( graphWith( "x R y" ), r ); // case 2: remove triple that exists in both - removes from left diff.delete( triple( "x R y" ) ); assertIsomorphic( graphWith( "x R z" ), diff ); assertIsomorphic( graphWith( "x R z" ), l ); assertIsomorphic( graphWith( "x R y" ), r ); // case 3: remove triple that exists in left is removed diff.delete( triple( "x R z" ) ); assertIsomorphic( graphWith( "" ), diff ); assertIsomorphic( graphWith( "" ), l ); assertIsomorphic( graphWith( "x R y" ), r ); } }
public void testAdd() { Graph l = graphWith( "x R y" ); Graph r = graphWith( "x R y; x R z" ); Difference diff = new Difference( l, r ); assertIsomorphic( graphWith( "" ), diff ); // case 1: add to the left operand diff.add( triple( "p S q" ) ); assertIsomorphic( graphWith( "p S q" ), diff ); assertIsomorphic( graphWith( "x R y; p S q" ), l ); assertIsomorphic( graphWith( "x R y; x R z" ), r ); // case 2: remove from the right, and add to the left operand diff.add( triple( "x R z" ) ); assertIsomorphic( graphWith( "x R z; p S q" ), diff ); assertIsomorphic( graphWith( "x R y; x R z; p S q" ), l ); assertIsomorphic( graphWith( "x R y" ), r ); // case 3: remove from the right operand diff.add( triple( "x R y" ) ); assertIsomorphic( graphWith( "x R y; x R z; p S q" ), diff ); assertIsomorphic( graphWith( "x R y; x R z; p S q" ), l ); assertIsomorphic( graphWith( "" ), r ); }
public void testDelete() { Graph l = graphWith( "x R y; x R z" ); Graph r = graphWith( "x R y" ); Difference diff = new Difference( l, r ); assertIsomorphic( graphWith( "x R z" ), diff ); // case 1: remove non-existent triple is a no-op diff.delete( triple( "p S q" ) ); assertIsomorphic( graphWith( "x R z" ), diff ); assertIsomorphic( graphWith( "x R y; x R z" ), l ); assertIsomorphic( graphWith( "x R y" ), r ); // case 2: remove triple that exists in both - removes from left diff.delete( triple( "x R y" ) ); assertIsomorphic( graphWith( "x R z" ), diff ); assertIsomorphic( graphWith( "x R z" ), l ); assertIsomorphic( graphWith( "x R y" ), r ); // case 3: remove triple that exists in left is removed diff.delete( triple( "x R z" ) ); assertIsomorphic( graphWith( "" ), diff ); assertIsomorphic( graphWith( "" ), l ); assertIsomorphic( graphWith( "x R y" ), r ); } }
public DifferenceTest() { graphProducer = new AbstractGraphProducer<Difference>() { private Map<Graph, Graph[]> map = new HashMap<>(); @Override protected Difference createNewGraph() { Graph g1 = memGraph(); Graph g2 = memGraph(); Difference d = new Difference(g1, g2); map.put(d, new Graph[] { g1, g2 }); return d; } @Override public Graph[] getDependsOn(Graph d) { Graph[] dg = map.get(d); if (dg == null) { throw new IllegalStateException("graph not in map"); } return dg; } @Override public Graph[] getNotDependsOn(Graph g) { return new Graph[] { memGraph() }; } @Override protected void afterClose(Graph g) { map.remove(g); } }; }
@Override public ExtendedIterator<Triple> _graphBaseFind( Triple t ) { return L.find( t ). filterDrop ( ifIn( R ) ); } }
@Override protected Difference createNewGraph() { Graph g1 = memGraph(); Graph g2 = memGraph(); Difference d = new Difference(g1, g2); map.put(d, new Graph[] { g1, g2 }); return d; }
@Override protected Difference createNewGraph() { Graph g1 = memGraph(); Graph g2 = memGraph(); Difference d = new Difference(g1, g2); map.put(d, new Graph[] { g1, g2 }); return d; }
@Override Graph getGraph() { return new Difference(Factory.createGraphMem(), Factory.createGraphMem()); }};
@Override Graph getGraph() { return new Difference(Factory.createGraphMem(), Factory.createGraphMem()); }};
@Override public Graph getGraph() { Graph gBase = graphWith( "" ), g1 = graphWith( "" ); return new Difference( gBase, g1 ); }
public Difference differenceOf(String s1, String s2) { return new Difference( graphWith( s1 ), graphWith( s2 ) ); }
@Override public Graph getGraph() { Graph gBase = graphWith( "" ), g1 = graphWith( "" ); return new Difference( gBase, g1 ); }
public Difference differenceOf(String s1, String s2) { return new Difference( graphWith( s1 ), graphWith( s2 ) ); }
@ContractTest public void testDifference() { Graph g1 = graphWith("x R y; p R q"); Graph g2 = graphWith("r Foo s; x R y"); Graph d = new Difference(g1, g2); assertOmits("Difference", d, "x R y"); assertContains("Difference", "p R q", d); assertOmits("Difference", d, "r Foo s"); if (d.size() != 1) fail("oops: size of difference is not 1"); d.add(triple("cats eat cheese")); assertContains("Difference.L", "cats eat cheese", g1); assertOmits("Difference.R", g2, "cats eat cheese"); }
@ContractTest public void testDifference() { Graph g1 = graphWith("x R y; p R q"); Graph g2 = graphWith("r Foo s; x R y"); Graph d = new Difference(g1, g2); assertOmits("Difference", d, "x R y"); assertContains("Difference", "p R q", d); assertOmits("Difference", d, "r Foo s"); if (d.size() != 1) fail("oops: size of difference is not 1"); d.add(triple("cats eat cheese")); assertContains("Difference.L", "cats eat cheese", g1); assertOmits("Difference.R", g2, "cats eat cheese"); }
public void testDifferenceReflectsChangesToOperands() { Graph l = graphWith( "x R y" ); Graph r = graphWith( "x R y" ); Difference diff = new Difference( l, r ); assertIsomorphic(graphWith( "" ), diff); r.delete( triple( "x R y" ) ); assertIsomorphic( graphWith( "x R y" ), diff ); l.add( triple( "x R z" ) ); assertIsomorphic( graphWith( "x R y; x R z" ), diff ); r.add( triple( "x R z" ) ); assertIsomorphic( graphWith( "x R y" ), diff ); }