use of at.ac.tuwien.kr.alpha.api.Alpha 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.Alpha in project Alpha by alpha-asp.
the class AlphaImplTest method problematicRun_3col_1119718541727902_sorted_400.
/**
* Runs a test that formerly caused some sort of exception.
*/
@Test
public void problematicRun_3col_1119718541727902_sorted_400() throws IOException {
/*
* NOTE: This was constructed from the following commandline invocation:
* -DebugEnableInternalChecks -q -g naive -s default -sort -n 400 -i 3col-20-38.txt
*/
SystemConfig cfg = new SystemConfig();
cfg.setGrounderName("naive");
cfg.setSolverName("default");
cfg.setNogoodStoreName("alpharoaming");
cfg.setDebugInternalChecks(true);
cfg.setSeed(1119718541727902L);
final Alpha system = new AlphaImpl(cfg);
final Path path = Paths.get("src", "test", "resources", "PreviouslyProblematic").resolve("3col-20-38.txt");
InputConfig inputCfg = new InputConfig();
List<String> files = new ArrayList<>();
files.add(path.toString());
inputCfg.setFiles(files);
ASPCore2Program prog = system.readProgram(inputCfg);
assertFalse(system.solve(prog).sorted().limit(400).collect(Collectors.toList()).isEmpty());
}
use of at.ac.tuwien.kr.alpha.api.Alpha 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.Alpha 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.Alpha 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);
}
Aggregations