use of org.dkpro.lab.task.Constraint in project dkpro-lab by dkpro.
the class ParameterSpaceTest method testWithConstraint.
@Test
public void testWithConstraint() {
Dimension<String> letters = Dimension.create("letters", "a", "b", "c");
Dimension<Integer> numbers = Dimension.create("numbers", 1, 2);
Dimension<Character> symbols = Dimension.create("symbols", '!', '&');
int n = 0;
ParameterSpace pSpace = new ParameterSpace(letters, numbers, symbols);
pSpace.addConstraint(new Constraint() {
@Override
public boolean isValid(Map<String, Object> aConfiguration) {
// a implies 1
return !aConfiguration.get("letters").equals("a") || aConfiguration.get("symbols").equals('!');
}
});
for (Map<String, Object> config : pSpace) {
System.out.println(config);
if ("a".equals(config.get("letters")) && !config.get("symbols").equals('!')) {
fail();
}
n++;
}
assertEquals((3 * 2 * 2) - 2, n);
assertEquals((3 * 2 * 2), pSpace.getStepCount());
}
Aggregations