use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class AtomsTest method testIsBasicAtomGround.
@Test
public void testIsBasicAtomGround() {
ASPCore2Program p = parser.parse("bla(blubb, foo(bar)).");
Atom a = p.getFacts().get(0);
assertBasicAtomGround(a, true);
ASPCore2Program p1 = parser.parse("foo(1, 2, 3, \"bar\").");
Atom a1 = p1.getFacts().get(0);
assertBasicAtomGround(a1, true);
ASPCore2Program p2 = parser.parse("foo(BAR).");
Atom a2 = p2.getFacts().get(0);
assertBasicAtomGround(a2, false);
ASPCore2Program p3 = parser.parse("foo(b, a, r(\"bla\", BLUBB)).");
Atom a3 = p3.getFacts().get(0);
assertBasicAtomGround(a3, false);
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class AlphaImplTest method programWithExternalStringStuff.
@Test
@SuppressWarnings("unchecked")
public void programWithExternalStringStuff() throws IOException {
Alpha alpha = new AlphaImpl();
ASPCore2Program prog = alpha.readProgram(InputConfig.forString(STRINGSTUFF_ASP));
Set<AnswerSet> answerSets = alpha.solve(prog).collect(Collectors.toSet());
// Verify every result string has length 6 and contains "foo"
for (AnswerSet as : answerSets) {
for (Atom atom : as.getPredicateInstances(Predicates.getPredicate("resultstring", 1))) {
String resultstring = ((ConstantTerm<String>) atom.getTerms().get(0)).getObject();
assertEquals(6, resultstring.length());
assertTrue(resultstring.contains("foo"));
}
}
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class AtomsTest method testExternalHasOutput.
@Test
public void testExternalHasOutput() {
ASPCore2Program p = parser.parse("a:- &extWithOutput[1](OUT).", externals);
Atom ext = p.getRules().get(0).getBody().stream().findFirst().get().getAtom();
assertExternalAtomGround(ext, false);
assertTrue(((ExternalAtom) ext).hasOutput());
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class ThreeColouringTestWithRandom method createEdges.
/**
* @param n
* @param shuffle if true, the vertex indices are shuffled with the given seed
* @param seed
* @return
*/
private List<Atom> createEdges(int n, boolean shuffle, int seed) {
List<Atom> facts = new ArrayList<>(n);
List<Integer> indices = new ArrayList<>();
for (int i = 1; i <= n; i++) {
indices.add(i);
}
if (shuffle) {
Collections.shuffle(indices, new Random(seed));
}
for (int i = 1; i < n; i++) {
facts.add(fact("e", indices.get(0), indices.get(i)));
}
for (int i = 1; i < n - 1; i++) {
facts.add(fact("e", indices.get(i), indices.get(i + 1)));
}
facts.add(fact("e", indices.get(1), indices.get(n - 1)));
return facts;
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class FixedInterpretationLiteralsTest method positiveExternalBindingOutput.
@Test
public void positiveExternalBindingOutput() {
Optional<AnswerSet> answer = this.alpha.solve(this.alpha.readProgramString(TEST_PROG, this.externals)).findFirst();
assertTrue(answer.isPresent());
AnswerSet answerSet = answer.get();
Predicate pred = Predicates.getPredicate("positive_external_binding_output", 2);
assertTrue(answerSet.getPredicates().contains(pred));
Set<Atom> instances = answerSet.getPredicateInstances(pred);
assertEquals(3, instances.size());
assertTrue(instances.contains(Atoms.newBasicAtom(pred, Terms.newConstant("Klagenfurt"), Terms.newConstant("Villach"))));
assertTrue(instances.contains(Atoms.newBasicAtom(pred, Terms.newConstant("Klagenfurt"), Terms.newConstant("Graz"))));
assertTrue(instances.contains(Atoms.newBasicAtom(pred, Terms.newConstant("Villach"), Terms.newConstant("Salzburg"))));
}
Aggregations