public void testAdd() {
Graph g0 = graphWith( "x p y" );
Graph g1 = graphWith( "x p z; z p zz" ); // disjoint with g0
Graph g2 = graphWith( "x p y; z p a" ); // intersects with g1
MultiUnion m = new MultiUnion( new Graph[] {g0, g1} );
int s0 = g0.size();
int s1 = g1.size();
int s2 = g2.size();
int m0 = m.size();
// add a triple to the union
m.add( triple( "a q b" ) );
assertEquals( "m.size should have increased by one", m0 + 1, m.size() );
assertEquals( "g0.size should have increased by one", s0 + 1, g0.size() );
assertEquals( "g1 size should be constant", s1, g1.size() );
// change the designated receiver and try again
m.setBaseGraph( g1 );
s0 = g0.size();
s1 = g1.size();
s2 = g2.size();
m0 = m.size();
m.add( triple( "a1 q b1" ));
assertEquals( "m.size should have increased by one", m0 + 1, m.size() );
assertEquals( "g0 size should be constant", s0, g0.size() );
assertEquals( "g1.size should have increased by one", s1 + 1, g1.size() );
// check that we can't make g2 the designated updater
boolean expected = false;
try {
m.setBaseGraph( g2 );
}
catch (IllegalArgumentException e) {
expected = true;
}
assertTrue( "Should not have been able to make g2 the updater", expected );