Skip to content

Commit

Permalink
Fix tests after merging master
Browse files Browse the repository at this point in the history
  • Loading branch information
madmike200590 committed Jul 22, 2024
1 parent 133553f commit 173f664
Show file tree
Hide file tree
Showing 26 changed files with 337 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void main(String[] args) {
Main.exitWithMessage(commandLineParser.getUsageMessage(), 1);
}

Alpha alpha = new AlphaFactory().newAlpha(cfg.getSystemConfig());
Alpha alpha = AlphaFactory.newAlpha(cfg.getSystemConfig());

InputProgram program = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void smokeTest() {
"n1 -> n5 [xlabel=\"-\" labeldistance=0.1]" + LS +
"n2 -> n5 [xlabel=\"+\" labeldistance=0.1]" + LS +
"}" + LS;
Alpha alpha = new AlphaFactory().newAlpha();
Alpha alpha = AlphaFactory.newAlpha();
DebugSolvingContext dbgResult = alpha.prepareDebugSolve(alpha.readProgramString(asp));
ComponentGraph compgraph = dbgResult.getComponentGraph();
ComponentGraphWriter writer = new ComponentGraphWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void smokeTest() {
"n6 -> n4 [xlabel=\"+\" labeldistance=0.1]" + LS +
"n6 -> n5 [xlabel=\"+\" labeldistance=0.1]" + LS +
"}" + LS;
Alpha alpha = new AlphaFactory().newAlpha();
Alpha alpha = AlphaFactory.newAlpha();
DebugSolvingContext dbgResult = alpha.prepareDebugSolve(alpha.readProgramString(asp));
DependencyGraph depgraph = dbgResult.getDependencyGraph();
DependencyGraphWriter writer = new DependencyGraphWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void solveAndWriteWorkbookTest() {
+ "p(N) :- p(I), N = I + 1, N <= MX, maxP(MX)."
+ "q(A, B) :- p(A), p(B).";
//@formatter:on
Alpha alpha = new AlphaFactory().newAlpha();
Alpha alpha = AlphaFactory.newAlpha();
List<AnswerSet> answerSets = alpha.solve(alpha.readProgramString(progstr)).collect(Collectors.toList());
assertEquals(1, answerSets.size());
AnswerSet as = answerSets.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import at.ac.tuwien.kr.alpha.core.antlr.ASPCore2Parser;

/**
* A parser that, in contrast to {@link ProgramParser}, does not parse full programs but only program parts like
* A parser that, in contrast to {@link at.ac.tuwien.kr.alpha.api.programs.ProgramParser}, does not parse full programs but only program parts like
* atoms, terms and such.
*/
// TODO adapt this and create evolog version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import at.ac.tuwien.kr.alpha.api.AnswerSet;
import at.ac.tuwien.kr.alpha.api.impl.AnswerSetsParser;
import at.ac.tuwien.kr.alpha.api.programs.Program;
import at.ac.tuwien.kr.alpha.api.programs.atoms.Atom;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.ac.tuwien.kr.alpha.api.impl;
package at.ac.tuwien.kr.alpha.test;

import java.util.Collections;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected ActionImplementationProvider newActionImplementationProvider() {
return new DefaultActionImplementationProvider();
}

public Alpha newAlpha(SystemConfig cfg) {
protected Alpha buildInstance(SystemConfig cfg) {
ActionImplementationProvider actionImplementationProvider = newActionImplementationProvider();
ProgramParser parser = new ProgramParserImpl(actionImplementationProvider, Collections.emptyMap());
ProgramTransformation<InputProgram, NormalProgram> programNormalizer = new NormalizeProgramTransformation(cfg.getAggregateRewritingConfig());
Expand All @@ -87,8 +87,13 @@ public Alpha newAlpha(SystemConfig cfg) {
}

// Create Alpha instance with default config.
public Alpha newAlpha() {
return newAlpha(new SystemConfig());
public static Alpha newAlpha() {
return AlphaFactory.newAlpha(new SystemConfig());
}

public static Alpha newAlpha(SystemConfig cfg) {
AlphaFactory factory = new AlphaFactory();
return factory.buildInstance(cfg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import at.ac.tuwien.kr.alpha.api.Alpha;
import at.ac.tuwien.kr.alpha.api.AnswerSet;
import at.ac.tuwien.kr.alpha.api.config.SystemConfig;
import at.ac.tuwien.kr.alpha.api.impl.AlphaFactory;
import at.ac.tuwien.kr.alpha.api.programs.InputProgram;
import at.ac.tuwien.kr.alpha.api.programs.terms.ConstantTerm;
import at.ac.tuwien.kr.alpha.api.programs.terms.FunctionTerm;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class ActionsTest {
@Test
public void helloWorld() {
MockedActionsAlphaFactory alphaFactory = new MockedActionsAlphaFactory();
Alpha alpha = alphaFactory.newAlpha(new SystemConfig());
Alpha alpha = AlphaFactory.newAlpha();
InputProgram program = alpha.readProgramString(HELLO_WORLD);
alpha.solve(program);
assertEquals("Hello World!", alphaFactory.getActionImplementationMock().getStdoutContent());
Expand All @@ -61,7 +62,7 @@ public void writeToFile() {
MockedActionsAlphaFactory alphaFactory = new MockedActionsAlphaFactory();
alphaFactory.getActionImplementationMock().setMockedFileOutputs(mockedFileOutputs);
ActionImplementationProvider actionProvider = alphaFactory.getActionImplementationMock();
Alpha alpha = alphaFactory.newAlpha(new SystemConfig());
Alpha alpha = AlphaFactory.newAlpha();
InputProgram program = alpha.readProgramString(WRITE_TO_FILE);
Set<AnswerSet> answerSets = alpha.solve(program).collect(Collectors.toSet());
LOGGER.debug("Got answer sets: {}", answerSets);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package at.ac.tuwien.kr.alpha.core.programs.transformation.aggregates;
package at.ac.tuwien.kr.alpha;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

import at.ac.tuwien.kr.alpha.api.Alpha;
import at.ac.tuwien.kr.alpha.api.impl.AlphaFactory;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand All @@ -31,18 +34,6 @@

public class AggregateRewritingTest {

private static final ProgramParser PARSER = new ProgramParserImpl();
private static final Function<String, List<AnswerSet>> NORMALIZE_AND_SOLVE = (str) -> {
SystemConfig cfg = new SystemConfig();
InputProgram prog = PARSER.parse(str);
NormalProgram normalized = new NormalizeProgramTransformation(cfg.getAggregateRewritingConfig()).apply(prog);
CompiledProgram compiled = InternalProgram.fromNormalProgram(normalized);
AtomStore atomStore = new AtomStoreImpl();
Grounder grounder = GrounderFactory.getInstance("naive", compiled, atomStore, cfg.isDebugInternalChecks());
Solver solver = SolverFactory.getInstance(cfg, atomStore, grounder);
return solver.collectList();
};

//@formatter:off
// Smoke-test case for "X <= #count{...}" aggregate
private static final String CNT_LE1_ASP =
Expand Down Expand Up @@ -99,9 +90,16 @@ public class AggregateRewritingTest {
+ " Y = #count { X : p( X ) }, 1 <= #count { X : p( X ) }, Z = #max { W : p( W ) }.";
//@formatter:on

// Use an alpha instance with default config for all test cases
private final Alpha alpha = AlphaFactory.newAlpha();
private final Function<String, List<AnswerSet>> solve = (asp) -> {
InputProgram prog = alpha.readProgramString(asp);
return alpha.solve(prog).collect(Collectors.toList());
};

@Test
public void countLeSortingGridSimple() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(CNT_LE1_ASP);
List<AnswerSet> answerSets = solve.apply(CNT_LE1_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate thing = Predicates.getPredicate("thing", 1);
Expand All @@ -123,7 +121,7 @@ public void countLeSortingGridSimple() {

@Test
public void countEqSimple() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(CNT_EQ1_ASP);
List<AnswerSet> answerSets = solve.apply(CNT_EQ1_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate thing = Predicates.getPredicate("thing", 1);
Expand All @@ -141,7 +139,7 @@ public void countEqSimple() {

@Test
public void countLeCountingGridSimple() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(CNT_LE1_ASP);
List<AnswerSet> answerSets = solve.apply(CNT_LE1_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate thing = Predicates.getPredicate("thing", 1);
Expand All @@ -163,7 +161,7 @@ public void countLeCountingGridSimple() {

@Test
public void countEqGlobalVars() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(VERTEX_DEGREE_ASP);
List<AnswerSet> answerSets = solve.apply(VERTEX_DEGREE_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate vertexDegree = Predicates.getPredicate("graph_vertex_degree", 3);
Expand All @@ -182,7 +180,7 @@ public void countEqGlobalVars() {
@Test
// Test "count eq" and "max eq" together with global vars
public void graphVerticesOfMaxDegree() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(NUM_MAX_DEGREE_VERTICES_ASP);
List<AnswerSet> answerSets = solve.apply(NUM_MAX_DEGREE_VERTICES_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate maxDegreeVertices = Predicates.getPredicate("graph_max_degree_vertices", 3);
Expand All @@ -196,7 +194,7 @@ public void graphVerticesOfMaxDegree() {

@Test
public void greaterMin() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(MIN_GT1_ASP);
List<AnswerSet> answerSets = solve.apply(MIN_GT1_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate greaterMin = Predicates.getPredicate("greater_min_acceptable", 1);
Expand All @@ -210,7 +208,7 @@ public void greaterMin() {

@Test
public void sumEquals1() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(SUM_EQ1_ASP);
List<AnswerSet> answerSets = solve.apply(SUM_EQ1_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate sumThings = Predicates.getPredicate("sum_things", 1);
Expand All @@ -224,7 +222,7 @@ public void sumEquals1() {

@Test
public void sumLessOrEqual1() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(SUM_LE1_ASP);
List<AnswerSet> answerSets = solve.apply(SUM_LE1_ASP);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate boundLe = Predicates.getPredicate("bound_le_sum", 1);
Expand All @@ -238,7 +236,7 @@ public void sumLessOrEqual1() {
@Test
@Disabled("Open issue, as dependency analysis includes cyclic output-dependency, which it should not.")
public void setComplexEqualityWithGlobals() {
List<AnswerSet> answerSets = NORMALIZE_AND_SOLVE.apply(COMPLEX_EQUALITY_WITH_GLOBALS);
List<AnswerSet> answerSets = solve.apply(COMPLEX_EQUALITY_WITH_GLOBALS);
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.get(0);
Predicate q = Predicates.getPredicate("q", 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.ac.tuwien.kr.alpha.core.programs.transformation;
package at.ac.tuwien.kr.alpha;

import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.Set;

import at.ac.tuwien.kr.alpha.core.programs.transformation.ArithmeticTermsRewriting;
import org.junit.jupiter.api.Test;

import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation;
Expand All @@ -23,7 +24,7 @@
import at.ac.tuwien.kr.alpha.api.programs.terms.VariableTerm;
import at.ac.tuwien.kr.alpha.commons.programs.Programs;
import at.ac.tuwien.kr.alpha.commons.programs.terms.Terms;
import at.ac.tuwien.kr.alpha.core.externals.Externals;
import at.ac.tuwien.kr.alpha.commons.externals.Externals;
import at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.ac.tuwien.kr.alpha.api.impl;
package at.ac.tuwien.kr.alpha;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -12,6 +12,7 @@
import java.util.Optional;
import java.util.Set;

import at.ac.tuwien.kr.alpha.api.impl.AlphaFactory;
import org.junit.jupiter.api.Test;

import at.ac.tuwien.kr.alpha.api.Alpha;
Expand All @@ -23,8 +24,8 @@
import at.ac.tuwien.kr.alpha.commons.Predicates;
import at.ac.tuwien.kr.alpha.commons.programs.atoms.Atoms;
import at.ac.tuwien.kr.alpha.commons.programs.terms.Terms;
import at.ac.tuwien.kr.alpha.core.externals.AspStandardLibrary;
import at.ac.tuwien.kr.alpha.core.externals.Externals;
import at.ac.tuwien.kr.alpha.commons.externals.Externals;
import at.ac.tuwien.kr.alpha.commons.externals.AspStandardLibrary;

public class FixedInterpretationLiteralsTest {

Expand Down Expand Up @@ -79,7 +80,7 @@ public static Set<List<ConstantTerm<String>>> connection(String dummy) {
private Map<String, PredicateInterpretation> externals;

public FixedInterpretationLiteralsTest() {
this.alpha = new AlphaImpl();
this.alpha = AlphaFactory.newAlpha();
this.externals = new HashMap<>();
this.externals.putAll(Externals.scan(AspStandardLibrary.class));
this.externals.putAll(Externals.scan(FixedInterpretationLiteralsTest.class));
Expand Down
Loading

0 comments on commit 173f664

Please sign in to comment.