use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.
the class AnswerSetQueryTest method matchPredicate.
@Test
public void matchPredicate() {
AnswerSetBuilder bld = new AnswerSetBuilder();
// @formatter:off
bld.predicate("p").symbolicInstance("a").symbolicInstance("b").predicate("q").symbolicInstance("x");
// @formatter:on
AnswerSet as = bld.build();
List<Atom> queryResult = as.query(AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)));
assertEquals(2, queryResult.size());
for (Atom a : queryResult) {
assertTrue(a.getPredicate().equals(Predicates.getPredicate("p", 1)));
}
}
use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.
the class AnswerSetQueryTest method matchString.
@Test
public void matchString() {
AnswerSetBuilder bld = new AnswerSetBuilder();
bld.predicate("p").symbolicInstance("a").instance("a");
AnswerSet as = bld.build();
AnswerSetQueryImpl stringQuery = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withStringEquals(0, "a");
List<Atom> queryResult = as.query(stringQuery);
assertEquals(1, queryResult.size());
}
use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.
the class AnswerSetQueryTest method matchSymbolicConstant.
@Test
public void matchSymbolicConstant() {
AnswerSetBuilder bld = new AnswerSetBuilder();
bld.predicate("p").symbolicInstance("a").instance("a");
AnswerSet as = bld.build();
AnswerSetQueryImpl constantQuery = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withConstantEquals(0, "a");
List<Atom> queryResult = as.query(constantQuery);
assertEquals(1, queryResult.size());
}
use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.
the class AnswerSetQueryTest method matchTerm.
@Test
public void matchTerm() {
AnswerSetBuilder bld = new AnswerSetBuilder();
bld.predicate("p").instance(1).instance(2).instance(3).instance(4).instance(5).instance("bla").symbolicInstance("blubb");
AnswerSet as = bld.build();
AnswerSetQueryImpl equalTerm = AnswerSetQueryImpl.forPredicate(Predicates.getPredicate("p", 1)).withTermEquals(0, Terms.newConstant(1));
List<Atom> queryResult = as.query(equalTerm);
assertEquals(1, queryResult.size());
Atom retrievedAtom = queryResult.get(0);
assertTrue(retrievedAtom.getTerms().get(0).equals(Terms.newConstant(1)));
}
use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.
the class AnswerSetToXlsxWriterTest method writeAnswerSetFilesTest.
@Test
public void writeAnswerSetFilesTest() throws IOException {
AnswerSet as = new AnswerSetBuilder().predicate("bla").instance("blubb", "blubb").instance("foo", "bar").predicate("foo").instance("bar").instance("baz").predicate("complex").instance(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)).build();
Path tmpDir = Files.createTempDirectory("alpha-test-xlsx-output");
AnswerSetToXlsxWriter writer = new AnswerSetToXlsxWriter(tmpDir.toString() + "/alphaAnswerSet");
writer.accept(0, as);
File tmpDirFile = tmpDir.toFile();
File[] generatedFiles = tmpDirFile.listFiles();
assertEquals(1, generatedFiles.length);
File answerSetFile = generatedFiles[0];
assertEquals("alphaAnswerSet.0.xlsx", answerSetFile.getName());
try (Workbook wb = WorkbookFactory.create(answerSetFile)) {
AnswerSetToWorkbookMapperTest.assertWorkbookMatchesAnswerSet(wb, as);
}
// clean up
answerSetFile.delete();
tmpDirFile.delete();
}
Aggregations