Search in sources :

Example 1 with Difference

use of org.apache.jena.graph.compose.Difference in project jena by apache.

the class DifferenceTest method testDifference.

@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");
}
Also used : Graph(org.apache.jena.graph.Graph) Difference(org.apache.jena.graph.compose.Difference) ContractTest(org.xenei.junit.contract.ContractTest)

Example 2 with Difference

use of org.apache.jena.graph.compose.Difference in project jena by apache.

the class TestDifference method testAdd.

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);
}
Also used : Graph(org.apache.jena.graph.Graph) Difference(org.apache.jena.graph.compose.Difference)

Example 3 with Difference

use of org.apache.jena.graph.compose.Difference in project jena by apache.

the class TestDifference method testDelete.

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);
}
Also used : Graph(org.apache.jena.graph.Graph) Difference(org.apache.jena.graph.compose.Difference)

Example 4 with Difference

use of org.apache.jena.graph.compose.Difference in project jena by apache.

the class TestDifference method testDifferenceReflectsChangesToOperands.

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);
}
Also used : Graph(org.apache.jena.graph.Graph) Difference(org.apache.jena.graph.compose.Difference)

Aggregations

Graph (org.apache.jena.graph.Graph)4 Difference (org.apache.jena.graph.compose.Difference)4 ContractTest (org.xenei.junit.contract.ContractTest)1