use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AlphaImplTest method addsFacts.
@Test
public void addsFacts() {
Alpha system = new AlphaImpl();
Thingy a = new Thingy();
Thingy b = new Thingy();
List<Thingy> things = asList(a, b);
InputProgram program = InputProgram.builder().addFacts(Externals.asFacts(Thingy.class, things)).build();
Set<AnswerSet> actual = system.solve(program).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("thingy").instance(a).instance(b).build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AlphaImplTest method withExternalSubtype.
@Test
public void withExternalSubtype() throws Exception {
SubThingy thingy = new SubThingy();
BasicRule rule = new BasicRule(Heads.newNormalHead(Atoms.newBasicAtom(Predicates.getPredicate("p", 1), Terms.newConstant("x"))), singletonList(Literals.fromAtom(Atoms.newExternalAtom(Predicates.getPredicate("thinger", 1), new MethodPredicateInterpretation(this.getClass().getMethod("thinger", Thingy.class)), singletonList(Terms.newConstant(thingy)), emptyList()), true)));
Alpha system = new AlphaImpl();
InputProgram prog = new InputProgram(singletonList(rule), emptyList(), new InlineDirectivesImpl());
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("p").instance("x").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AlphaImplTest method smallGraphCoolNode.
@Test
public void smallGraphCoolNode() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("node(1..2). in(X) :- node(X), &coolNode[X].");
cfg.addPredicateMethod("coolNode", Externals.processPredicateMethod(this.getClass().getMethod("coolNode", int.class)));
ASPCore2Program prog = system.readProgram(cfg);
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
Set<AnswerSet> expected = AnswerSetsParser.parse("{ in(1), node(1), node(2) }");
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AlphaImplTest method noInput.
@Test
public void noInput() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("node(1). a :- &bestNode(X), node(X).");
cfg.addPredicateMethod("bestNode", Externals.processPredicateMethod(this.getClass().getMethod("bestNode")));
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 AlphaImplTest method smallGraphNoNeighbors.
@Test
@Disabled("Test program is not safe (external lacking output variables). This should throw some exception.")
public void smallGraphNoNeighbors() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("noNeighbors(2) :- not &neighbors[2].");
cfg.addPredicateMethod("neighbors", Externals.processPredicateMethod(this.getClass().getMethod("neighbors", int.class)));
ASPCore2Program prog = system.readProgram(cfg);
Set<AnswerSet> expected = AnswerSetsParser.parse("{ noNeighbors(2) }");
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
assertEquals(expected, actual);
}
Aggregations