Search in sources :

Example 1 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AlphaImplTest method withExternalViaAnnotation.

@Test
public void withExternalViaAnnotation() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig cfg = InputConfig.forString("a :- &isOne[1].");
    cfg.addPredicateMethods(Externals.scan(this.getClass()));
    ASPCore2Program prog = system.readProgram(cfg);
    Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
    assertEquals(expected, actual);
}
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) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AlphaImplTest method withExternalTypeConflict.

@Test
public void withExternalTypeConflict() {
    assertThrows(IllegalArgumentException.class, () -> {
        Alpha system = new AlphaImpl();
        InputConfig inputCfg = InputConfig.forString("a :- &isFoo[\"adsfnfdsf\"].");
        inputCfg.addPredicateMethod("isFoo", Externals.processPredicateMethod(this.getClass().getMethod("isFoo", Integer.class)));
        Set<AnswerSet> actual = system.solve(system.readProgram(inputCfg)).collect(Collectors.toSet());
        Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
        assertEquals(expected, actual);
    });
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AlphaImplTest method filterTest.

/**
 * Verifies that filters are handled correctly (regression test case introduced when fixing issue #189).
 */
@Test
public void filterTest() {
    String progstr = "a. b. c. d :- c. e(a, b) :- d.";
    Alpha system = new AlphaImpl();
    ASPCore2Program prog = system.readProgramString(progstr);
    Set<AnswerSet> actual = system.solve(prog, (p) -> p.equals(Predicates.getPredicate("a", 0)) || p.equals(Predicates.getPredicate("e", 2))).collect(Collectors.toSet());
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").predicate("e").symbolicInstance("a", "b").build()));
    assertEquals(expected, actual);
}
Also used : Arrays(java.util.Arrays) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) LoggerFactory(org.slf4j.LoggerFactory) Heads(at.ac.tuwien.kr.alpha.commons.rules.heads.Heads) Disabled(org.junit.jupiter.api.Disabled) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) Collections.singletonList(java.util.Collections.singletonList) Externals(at.ac.tuwien.kr.alpha.core.externals.Externals) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Literals(at.ac.tuwien.kr.alpha.commons.literals.Literals) Path(java.nio.file.Path) Collections.emptyList(java.util.Collections.emptyList) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Atoms(at.ac.tuwien.kr.alpha.commons.atoms.Atoms) Collectors(java.util.stream.Collectors) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Test(org.junit.jupiter.api.Test) List(java.util.List) AspStandardLibrary(at.ac.tuwien.kr.alpha.core.externals.AspStandardLibrary) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Optional(java.util.Optional) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) ArrayList(java.util.ArrayList) ConstantTerm(at.ac.tuwien.kr.alpha.api.terms.ConstantTerm) HashSet(java.util.HashSet) Terms(at.ac.tuwien.kr.alpha.commons.terms.Terms) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Files(java.nio.file.Files) MethodPredicateInterpretation(at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.MethodPredicateInterpretation) Heuristic(at.ac.tuwien.kr.alpha.api.config.Heuristic) InlineDirectivesImpl(at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl) IOException(java.io.IOException) Predicates(at.ac.tuwien.kr.alpha.commons.Predicates) Paths(java.nio.file.Paths) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) BasicRule(at.ac.tuwien.kr.alpha.core.rules.BasicRule) 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) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AlphaImplTest method withExternalInvocationCounted1.

@Test
@Disabled("External atom has state, which is not allowed. Caching of calls makes the number of invocations wrong.")
public void withExternalInvocationCounted1() throws Exception {
    Alpha system = new AlphaImpl();
    InputConfig cfg = InputConfig.forString("a :- &isOne[1], &isOne[1].");
    cfg.addPredicateMethod("isOne", Externals.processPredicateMethod(this.getClass().getMethod("isOne", int.class)));
    ASPCore2Program prog = system.readProgram(cfg);
    int before = invocations;
    Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
    int after = invocations;
    assertEquals(2, after - before);
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").build()));
    assertEquals(expected, actual);
}
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) InputConfig(at.ac.tuwien.kr.alpha.api.config.InputConfig) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with AnswerSetBuilder

use of at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder in project Alpha by alpha-asp.

the class AlphaImplTest method basicUsageWithString.

@Test
public void basicUsageWithString() throws Exception {
    Alpha system = new AlphaImpl();
    Set<AnswerSet> actual = system.solve(system.readProgram(InputConfig.forString("p(\"a\")."))).collect(Collectors.toSet());
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("p").instance("a").build()));
    assertEquals(expected, actual);
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)21 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)20 Test (org.junit.jupiter.api.Test)20 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)12 HashSet (java.util.HashSet)12 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)8 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)7 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)7 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)4 Disabled (org.junit.jupiter.api.Disabled)4 InlineDirectivesImpl (at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl)3 ConstantTerm (at.ac.tuwien.kr.alpha.api.terms.ConstantTerm)2 Predicates (at.ac.tuwien.kr.alpha.commons.Predicates)2 Atoms (at.ac.tuwien.kr.alpha.commons.atoms.Atoms)2 Terms (at.ac.tuwien.kr.alpha.commons.terms.Terms)2 MethodPredicateInterpretation (at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.MethodPredicateInterpretation)2 BasicRule (at.ac.tuwien.kr.alpha.core.rules.BasicRule)2 Path (java.nio.file.Path)2 List (java.util.List)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2