use of at.ac.tuwien.kr.alpha.api.config.InputConfig 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.config.InputConfig 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.config.InputConfig 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.api.config.InputConfig in project Alpha by alpha-asp.
the class AlphaImplTest method errorDuplicateExternal.
/**
* Externals may only be scanned once per implementation.
* If at the time of a scan, the name of an external is already registered,
* an exception is thrown.
*/
@Test
public void errorDuplicateExternal() {
assertThrows(IllegalArgumentException.class, () -> {
InputConfig cfg = InputConfig.forString("someString.");
cfg.addPredicateMethods(Externals.scan(this.getClass()));
cfg.addPredicateMethods(Externals.scan(this.getClass()));
});
}
use of at.ac.tuwien.kr.alpha.api.config.InputConfig in project Alpha by alpha-asp.
the class AlphaImplTest method withExternalInvocationCounted3.
@Test
@Disabled("External atom has state, which is not allowed. Caching of calls makes the number of invocations wrong.")
public void withExternalInvocationCounted3() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("a :- &isOne[1], not &isOne[2].");
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(1, after - before);
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
assertEquals(expected, actual);
}
Aggregations