use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AlphaImplTest method withExternalTypeConflict.
@Test
public void withExternalTypeConflict() {
assertThrows(IllegalArgumentException.class, () -> {
Alpha system = new AlphaImpl();
InputConfig inputCfg = InputConfig.forString("a :- &isFoo[\"adsfnfdsf\"].");
inputCfg.addPredicateMethod("isFoo", Externals.processPredicateMethod(this.getClass().getMethod("isFoo", Integer.class)));
Set<AnswerSet> actual = system.solve(system.readProgram(inputCfg)).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.AnswerSet in project Alpha by alpha-asp.
the class AlphaImplTest method smallGraphSingleNeighborNoTerm.
@Test
@Disabled("Test program is not safe (external lacking output variables). This should throw some exception.")
public void smallGraphSingleNeighborNoTerm() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("success :- &neighbors[1], not &neighbors[2].");
cfg.addPredicateMethod("neighbors", Externals.processPredicateMethod(this.getClass().getMethod("neighbors", int.class)));
ASPCore2Program prog = system.readProgram(cfg);
Set<AnswerSet> expected = AnswerSetsParser.parse("{ success }");
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AlphaImplTest method filterTest.
/**
* Verifies that filters are handled correctly (regression test case introduced when fixing issue #189).
*/
@Test
public void filterTest() {
String progstr = "a. b. c. d :- c. e(a, b) :- d.";
Alpha system = new AlphaImpl();
ASPCore2Program prog = system.readProgramString(progstr);
Set<AnswerSet> actual = system.solve(prog, (p) -> p.equals(Predicates.getPredicate("a", 0)) || p.equals(Predicates.getPredicate("e", 2))).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").predicate("e").symbolicInstance("a", "b").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AlphaImplTest method supplier.
@Test
public void supplier() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("node(1). a :- &bestNode(X), node(X).");
cfg.addPredicateMethod("bestNode", Externals.processPredicate(() -> singleton(singletonList(Terms.newConstant(1)))));
ASPCore2Program prog = system.readProgram(cfg);
Set<AnswerSet> expected = AnswerSetsParser.parse("{ node(1), a }");
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class ThreeColouringTestWithRandom method testThreeColouring.
private void testThreeColouring(int n, boolean shuffle, int seed, RegressionTestConfig cfg) {
ASPCore2Program tmpPrg = new ProgramParserImpl().parse("col(V,C) :- v(V), c(C), not ncol(V,C)." + "ncol(V,C) :- col(V,D), c(C), C != D." + ":- e(V,U), col(V,C), col(U,C).");
InputProgram.Builder prgBuilder = InputProgram.builder().accumulate(tmpPrg);
prgBuilder.addFacts(createColors("1", "2", "3"));
prgBuilder.addFacts(createVertices(n));
prgBuilder.addFacts(createEdges(n, shuffle, seed));
InputProgram program = prgBuilder.build();
Solver solver = buildSolverForRegressionTest(program, cfg);
@SuppressWarnings("unused") Optional<AnswerSet> answerSet = solver.stream().findAny();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
Aggregations