use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class AlphaImplTest method smallGraphWithWrongType.
@Test
public void smallGraphWithWrongType() {
assertThrows(IllegalArgumentException.class, () -> {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("a :- &connected[\"hello\",2].");
cfg.addPredicateMethod("connected", Externals.processPredicate((Integer a, Integer b) -> (a == 1 && b == 2) || (b == 2 || b == 3)));
ASPCore2Program prog = system.readProgram(cfg);
system.solve(prog).collect(Collectors.toSet());
});
}
use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class AlphaImplTest method withExternal.
@Test
public void withExternal() throws Exception {
Alpha alpha = new AlphaImpl();
InputConfig inputCfg = InputConfig.forString("a :- &isOne[1].");
inputCfg.addPredicateMethod("isOne", Externals.processPredicateMethod(this.getClass().getMethod("isOne", int.class)));
ASPCore2Program program = alpha.readProgram(inputCfg);
Set<AnswerSet> actual = alpha.solve(program).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class RuleParser method parse.
public static Rule<Head> parse(String str) {
ProgramParser parser = new ProgramParserImpl();
ASPCore2Program prog = parser.parse(str);
if (!prog.getFacts().isEmpty()) {
throw new IllegalArgumentException("Expected exactly one rule and no facts!");
}
if (prog.getRules().size() != 1) {
throw new IllegalArgumentException("Expected exactly one rule");
}
return prog.getRules().get(0);
}
use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class AlphaImplTest method disableStratifiedEvalTest.
/**
* Verifies that no stratified evaluation is performed up-front when disabled in config.
*/
@Test
public void disableStratifiedEvalTest() {
// Note: This might be cleaner if the test used the debugSolve method from the interface
String progstr = "p(a). q(X) :- p(X).";
SystemConfig cfg = new SystemConfig();
cfg.setEvaluateStratifiedPart(false);
AlphaImpl system = new AlphaImpl(cfg);
ASPCore2Program input = system.readProgramString(progstr);
NormalProgram normal = system.normalizeProgram(input);
CompiledProgram preprocessed = system.performProgramPreprocessing(normal);
assertFalse(preprocessed.getFacts().contains(Atoms.newBasicAtom(Predicates.getPredicate("q", 1), Terms.newSymbolicConstant("a"))), "Preprocessed program contains fact derived from stratifiable rule, but should not!");
}
use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class AlphaImplTest method enableStratifiedEvalTest.
/**
* Verifies that stratified evaluation is performed up-front if not otherwise configured.
*/
@Test
public void enableStratifiedEvalTest() {
// Note: This might be cleaner if the test used the debugSolve method from the interface
String progstr = "p(a). q(X) :- p(X).";
SystemConfig cfg = new SystemConfig();
AlphaImpl system = new AlphaImpl(cfg);
ASPCore2Program input = system.readProgramString(progstr);
NormalProgram normal = system.normalizeProgram(input);
CompiledProgram preprocessed = system.performProgramPreprocessing(normal);
assertTrue(preprocessed.getFacts().contains(Atoms.newBasicAtom(Predicates.getPredicate("q", 1), Terms.newSymbolicConstant("a"))), "Preprocessed program does not contain fact derived from stratifiable rule, but should!");
}
Aggregations