Search in sources :

Example 16 with AnswerSetBuilder

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

the class AnswerSetToWorkbookMapperTest method smokeTest.

@Test
public void smokeTest() throws IOException {
    AnswerSet as = new AnswerSetBuilder().predicate("bla").instance("blubb", "blubb").instance("foo", "bar").predicate("foo").instance("bar").instance("baz").predicate("complex").instance(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)).build();
    try (Workbook wb = this.mapper.mapFromAnswerSet(as)) {
        assertNotNull(wb.getSheet("Flags"));
        assertNotNull(wb.getSheet("bla_2"));
        assertNotNull(wb.getSheet("foo_1"));
        assertNotNull(wb.getSheet("complex_3"));
    }
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.jupiter.api.Test)

Example 17 with AnswerSetBuilder

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

the class SimpleAnswerSetFormatterTest method basicFormatterWithSeparator.

@Test
public void basicFormatterWithSeparator() {
    AnswerSetFormatter<String> fmt = new SimpleAnswerSetFormatter(" bla ");
    AnswerSet as = new AnswerSetBuilder().predicate("p").instance("a").predicate("q").instance("b").build();
    String formatted = fmt.format(as);
    assertEquals("{ p(\"a\") bla q(\"b\") }", formatted);
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) SimpleAnswerSetFormatter(at.ac.tuwien.kr.alpha.commons.util.SimpleAnswerSetFormatter) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Test(org.junit.jupiter.api.Test)

Example 18 with AnswerSetBuilder

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

the class AlphaImplTest method basicUsage.

@Test
public void basicUsage() 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").symbolicInstance("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)

Example 19 with AnswerSetBuilder

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

the class AlphaImplTest method withExternal.

@Test
public void withExternal() throws Exception {
    Alpha alpha = new AlphaImpl();
    InputConfig inputCfg = InputConfig.forString("a :- &isOne[1].");
    inputCfg.addPredicateMethod("isOne", Externals.processPredicateMethod(this.getClass().getMethod("isOne", int.class)));
    ASPCore2Program program = alpha.readProgram(inputCfg);
    Set<AnswerSet> actual = alpha.solve(program).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 20 with AnswerSetBuilder

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

the class AlphaImplTest method addsFacts.

@Test
public void addsFacts() {
    Alpha system = new AlphaImpl();
    Thingy a = new Thingy();
    Thingy b = new Thingy();
    List<Thingy> things = asList(a, b);
    InputProgram program = InputProgram.builder().addFacts(Externals.asFacts(Thingy.class, things)).build();
    Set<AnswerSet> actual = system.solve(program).collect(Collectors.toSet());
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("thingy").instance(a).instance(b).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) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) 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