Search in sources :

Example 76 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveComparisonLiteral_EQ_RightAssigning.

@Test
public void testPositiveComparisonLiteral_EQ_RightAssigning() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), 5 = Y.").getRules().get(0);
    Literal literal = rule.getBody().stream().filter((lit) -> lit.getPredicate() == ComparisonOperators.EQ.toPredicate()).findFirst().get();
    assertEquals(false, literal.isNegated());
    expectVariables(literal.getBindingVariables(), "Y");
    expectVariables(literal.getNonBindingVariables());
}
Also used : Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test)

Example 77 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveComparisonLiteral_NEQ_LeftAssigning.

@Test
public void testPositiveComparisonLiteral_NEQ_LeftAssigning() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), Y != 5.").getRules().get(0);
    Literal literal = rule.getBody().stream().filter((lit) -> lit.getPredicate() == ComparisonOperators.NE.toPredicate()).findFirst().get();
    assertEquals(false, literal.isNegated());
    expectVariables(literal.getBindingVariables());
    expectVariables(literal.getNonBindingVariables(), "Y");
}
Also used : Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test)

Example 78 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testPositiveComparisonLiteral_EQ_LeftAssigning.

@Test
public void testPositiveComparisonLiteral_EQ_LeftAssigning() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), Y = 5.").getRules().get(0);
    Literal literal = rule.getBody().stream().filter((lit) -> lit.getPredicate() == ComparisonOperators.EQ.toPredicate()).findFirst().get();
    assertEquals(false, literal.isNegated());
    expectVariables(literal.getBindingVariables(), "Y");
    expectVariables(literal.getNonBindingVariables());
}
Also used : Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test)

Example 79 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testNegativeComparisonLiteral_EQ_LeftAssigning.

@Test
public void testNegativeComparisonLiteral_EQ_LeftAssigning() {
    Rule<Head> rule = parser.parse("p(X) :- q(X,Y), not Y = 5.").getRules().get(0);
    Literal literal = rule.getNegativeBody().stream().findFirst().get();
    assertEquals(true, literal.isNegated());
    expectVariables(literal.getBindingVariables());
    expectVariables(literal.getNonBindingVariables(), "Y");
}
Also used : Head(at.ac.tuwien.kr.alpha.api.rules.heads.Head) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test)

Example 80 with Literal

use of at.ac.tuwien.kr.alpha.api.programs.literals.Literal in project Alpha by alpha-asp.

the class LiteralBindingNonBindingVariablesTest method testNegativeComparisonLiteral_NEQ_Bidirectional.

@Test
@Disabled("Literals of this kind are compiled away by VariableEqualityRemoval")
public void testNegativeComparisonLiteral_NEQ_Bidirectional() {
    Literal literal = parser.parse("p(X) :- q(X,Y), not X != Y.").getRules().get(0).getNegativeBody().stream().findFirst().get();
    assertEquals(true, literal.isNegated());
    expectVariables(literal.getBindingVariables(), "X", "Y");
    expectVariables(literal.getNonBindingVariables());
}
Also used : Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)82 Test (org.junit.jupiter.api.Test)42 VariableTerm (at.ac.tuwien.kr.alpha.api.terms.VariableTerm)20 ArrayList (java.util.ArrayList)20 AggregateLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral)17 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)16 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)14 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)14 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)14 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)13 Map (java.util.Map)12 Head (at.ac.tuwien.kr.alpha.api.rules.heads.Head)11 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)11 CompiledRule (at.ac.tuwien.kr.alpha.core.rules.CompiledRule)10 HashSet (java.util.HashSet)10 ComparisonLiteral (at.ac.tuwien.kr.alpha.api.programs.literals.ComparisonLiteral)9 Instance (at.ac.tuwien.kr.alpha.commons.substitutions.Instance)9 LinkedHashSet (java.util.LinkedHashSet)8 List (java.util.List)8 Term (at.ac.tuwien.kr.alpha.api.terms.Term)7