use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.
the class HanoiTowerTest method testHanoiTower.
private void testHanoiTower(String instance, RegressionTestConfig cfg) throws IOException {
ASPCore2Program prog = new ProgramParserImpl().parse(Paths.get("src", "test", "resources", "HanoiTower_Alpha.asp"), Paths.get("src", "test", "resources", "HanoiTower_instances", instance + ".asp"));
Solver solver = TestUtils.buildSolverForRegressionTest(prog, cfg);
Optional<AnswerSet> answerSet = solver.stream().findFirst();
assertTrue(answerSet.isPresent());
checkGoal(prog, answerSet.get());
}
use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.
the class ThreeColouringRandomGraphTest method testThreeColouring.
private void testThreeColouring(int nVertices, int nEdges, RegressionTestConfig cfg) {
ASPCore2Program tmpPrg = new ProgramParserImpl().parse("blue(N) :- v(N), not red(N), not green(N)." + "red(N) :- v(N), not blue(N), not green(N)." + "green(N) :- v(N), not red(N), not blue(N)." + ":- e(N1,N2), blue(N1), blue(N2)." + ":- e(N1,N2), red(N1), red(N2)." + ":- e(N1,N2), green(N1), green(N2).");
InputProgram.Builder prgBuilder = InputProgram.builder(tmpPrg);
prgBuilder.addFacts(createVertices(nVertices));
prgBuilder.addFacts(createEdges(nVertices, nEdges));
InputProgram program = prgBuilder.build();
maybeShuffle(program);
@SuppressWarnings("unused") Optional<AnswerSet> answerSet = buildSolverForRegressionTest(program, cfg).stream().findAny();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl in project Alpha by alpha-asp.
the class ProgramTest method testToString.
@Test
public void testToString() {
ASPCore2Program parsedProgram = new ProgramParserImpl().parse("p(a)." + System.lineSeparator() + "q(X) :- p(X)." + System.lineSeparator() + "p(b).");
assertEquals("p(a)." + System.lineSeparator() + "p(b)." + System.lineSeparator() + "q(X) :- p(X)." + System.lineSeparator(), parsedProgram.toString());
}
use of at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl 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);
}
Aggregations