use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.
the class AlphaImplTest method withExternalViaAnnotation.
@Test
public void withExternalViaAnnotation() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("a :- &isOne[1].");
cfg.addPredicateMethods(Externals.scan(this.getClass()));
ASPCore2Program prog = system.readProgram(cfg);
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder 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.commons.AnswerSetBuilder 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.commons.AnswerSetBuilder in project Alpha by alpha-asp.
the class AlphaImplTest method withExternalInvocationCounted1.
@Test
@Disabled("External atom has state, which is not allowed. Caching of calls makes the number of invocations wrong.")
public void withExternalInvocationCounted1() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("a :- &isOne[1], &isOne[1].");
cfg.addPredicateMethod("isOne", Externals.processPredicateMethod(this.getClass().getMethod("isOne", int.class)));
ASPCore2Program prog = system.readProgram(cfg);
int before = invocations;
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
int after = invocations;
assertEquals(2, after - before);
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.
the class AlphaImplTest method basicUsageWithString.
@Test
public void basicUsageWithString() throws Exception {
Alpha system = new AlphaImpl();
Set<AnswerSet> actual = system.solve(system.readProgram(InputConfig.forString("p(\"a\")."))).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("p").instance("a").build()));
assertEquals(expected, actual);
}
Aggregations