public void testScopedVariables() {
// setup the data...
final RuleModel model = new RuleModel();
model.lhs = new IPattern[3];
final FactPattern x = new FactPattern("Car");
model.lhs[0] = x;
x.boundName = "x";
final FactPattern y = new FactPattern("Car");
model.lhs[1] = y;
y.boundName = "y";
final SingleFieldConstraint[] cons = new SingleFieldConstraint[2];
y.constraintList = new CompositeFieldConstraint();
y.constraintList.constraints = cons;
cons[0] = new SingleFieldConstraint("age");
cons[1] = new SingleFieldConstraint("make");
cons[0].fieldBinding = "qbc";
cons[0].connectives = new ConnectiveConstraint[1];
cons[0].connectives[0] = new ConnectiveConstraint("&", "x");
cons[0].connectives[0].constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
final FactPattern other = new FactPattern("House");
model.lhs[2] = other;
other.boundName = "q";
final SingleFieldConstraint[] cons2 = new SingleFieldConstraint[1];
cons2[0] = new SingleFieldConstraint();
other.constraintList = new CompositeFieldConstraint();
other.constraintList.constraints = cons2;
// check the results for correct scope
List vars = model.getBoundVariablesInScope(cons[0]);
assertEquals(1, vars.size());
assertEquals("x", vars.get(0));
vars = model.getBoundVariablesInScope(cons[0].connectives[0]);
assertEquals(1, vars.size());
assertEquals("x", vars.get(0));
vars = model.getBoundVariablesInScope(cons[1]);
assertEquals(2, vars.size());
assertEquals("x", vars.get(0));
assertEquals("qbc", vars.get(1));
vars = model.getBoundVariablesInScope(cons[0]);
assertEquals(1, vars.size());
assertEquals("x", vars.get(0));
vars = model.getBoundVariablesInScope(cons2[0]);
assertEquals(3, vars.size());
assertEquals("x", vars.get(0));
assertEquals("qbc", vars.get(1));
assertEquals("y", vars.get(2));
}