Search in sources :

Example 71 with Atom

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));
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) ExternalAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.ExternalAtom) Test(org.junit.jupiter.api.Test)

Example 72 with Atom

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());
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) BasicAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) ExternalAtom(at.ac.tuwien.kr.alpha.api.programs.atoms.ExternalAtom) Test(org.junit.jupiter.api.Test)

Example 73 with Atom

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"));
        }
    }
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) ConstantTerm(at.ac.tuwien.kr.alpha.api.terms.ConstantTerm) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) Test(org.junit.jupiter.api.Test)

Aggregations

Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)73 Test (org.junit.jupiter.api.Test)38 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)27 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)27 LinkedHashSet (java.util.LinkedHashSet)16 Unifier (at.ac.tuwien.kr.alpha.commons.substitutions.Unifier)15 ArrayList (java.util.ArrayList)14 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)13 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)12 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)11 Instance (at.ac.tuwien.kr.alpha.commons.substitutions.Instance)9 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)9 WorkingMemory (at.ac.tuwien.kr.alpha.core.grounder.WorkingMemory)9 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)9 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)8 RuleAtom (at.ac.tuwien.kr.alpha.core.atoms.RuleAtom)8 WritableAssignment (at.ac.tuwien.kr.alpha.core.solver.WritableAssignment)7 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)6 ExternalAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.ExternalAtom)6 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)6