use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class AtomsTest method testAreBasicAtomsEqual.
@Test
public void testAreBasicAtomsEqual() {
ASPCore2Program p1 = parser.parse("bla(blubb, foo(bar)). bla(blubb, foo(bar)).");
Atom a1 = p1.getFacts().get(0);
Atom a2 = p1.getFacts().get(1);
assertEquals(a1, a2);
ASPCore2Program p2 = parser.parse("foo(1, 2, 3, \"bar\"). foo(1, 2, 3, \"bar\").");
Atom a3 = p2.getFacts().get(0);
Atom a4 = p2.getFacts().get(1);
assertEquals(a3, a4);
ASPCore2Program p3 = parser.parse("foo(BAR). foo(BAR).");
Atom a5 = p3.getFacts().get(0);
Atom a6 = p3.getFacts().get(1);
assertEquals(a5, a6);
ASPCore2Program p4 = parser.parse("foo(b, a, r(\"bla\", BLUBB)). foo(b, a, r(\"bla\", BLUBB)).");
Atom a7 = p4.getFacts().get(0);
Atom a8 = p4.getFacts().get(1);
assertEquals(a7, a8);
assertFalse(a1.equals(a3));
assertFalse(a3.equals(a1));
assertFalse(a1.equals(a5));
assertFalse(a5.equals(a1));
assertFalse(a1.equals(a7));
assertFalse(a7.equals(a1));
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class AtomsTest method testAreExternalAtomsEqual.
@Test
@SuppressWarnings("unlikely-arg-type")
public void testAreExternalAtomsEqual() {
ASPCore2Program p1 = parser.parse("a :- &isFoo[1].", externals);
Atom ext1 = p1.getRules().get(0).getBody().stream().findFirst().get().getAtom();
ASPCore2Program p2 = parser.parse("a :- &isFoo[1].", externals);
Atom ext2 = p2.getRules().get(0).getBody().stream().findFirst().get().getAtom();
assertEquals(ext1, ext2);
assertEquals(ext2, ext1);
assertFalse(ext1.equals(null));
assertFalse(ext1.equals("bla"));
assertTrue(ext1.hashCode() == ext2.hashCode());
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class AlphaImplTest method withNegatedExternal.
@Test
@SuppressWarnings("unchecked")
public void withNegatedExternal() throws IOException {
Alpha alpha = new AlphaImpl();
ASPCore2Program prog = alpha.readProgram(InputConfig.forString(NEGATED_EXTERNAL_ASP));
Set<AnswerSet> answerSets = alpha.solve(prog).collect(Collectors.toSet());
assertEquals(31, answerSets.size());
// 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();
LOGGER.debug("ResultString is {}", resultstring);
assertEquals(6, resultstring.length());
assertTrue(resultstring.contains("foo"));
}
}
}
Aggregations