JavaCompilerCore/test/asp/ClingoTest.java

51 lines
2.0 KiB
Java
Raw Normal View History

package asp;
import de.dhbwstuttgart.parser.NullToken;
2018-07-17 17:56:01 +00:00
import de.dhbwstuttgart.sat.asp.ASPUnify;
2018-02-27 18:10:16 +00:00
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
2018-03-07 21:41:00 +00:00
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
2018-02-27 18:10:16 +00:00
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
2018-02-27 18:10:16 +00:00
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import org.junit.Test;
import java.io.*;
import java.util.*;
public class ClingoTest {
public static final String tempDirectory = "/tmp/";
2018-02-27 18:10:16 +00:00
private final TypePlaceholder testType = TypePlaceholder.fresh(new NullToken());
@Test
2018-02-19 10:33:08 +00:00
public void test() throws IOException, InterruptedException, ClassNotFoundException {
String content = "";
2018-03-07 21:41:00 +00:00
content = ASPFactory.generateASP(this.getPairs(), this.getFC());
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
writer.println(content);
writer.close();
2018-07-17 17:56:01 +00:00
ASPUnify clingo = new ASPUnify(Arrays.asList(new File(tempDirectory + "test.lp")));
2018-02-27 18:10:16 +00:00
String result = clingo.runClingo();
System.out.println(result);
ResultSet resultSet = ASPParser.parse(result, Arrays.asList(testType));
RefTypeOrTPHOrWildcardOrGeneric resolvedType = resultSet.resolveType(testType).resolvedType;
assert resolvedType.toString().equals(ASTFactory.createObjectType().toString());
}
public Collection<ClassOrInterface> getFC() {
Set<ClassOrInterface> ret = new HashSet<>();
return ret;
}
public ConstraintSet<Pair> getPairs() {
ConstraintSet<Pair> ret = new ConstraintSet<>();
2018-02-27 18:10:16 +00:00
ret.addUndConstraint(new Pair(testType, ASTFactory.createObjectType(), PairOperator.EQUALSDOT));
return ret;
}
}