From 97e0e2fc727d002837864b5e0bd851df73e1c6bb Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Mon, 23 Nov 2015 01:03:01 +0100 Subject: [PATCH] unifyTest --- .../typeinference/unifynew/Unify.java | 13 +++--- test/unify/UnifyTest.java | 46 ++++++++++++++++++- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java b/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java index 480e9a5e7..33943e85a 100644 --- a/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java @@ -30,14 +30,13 @@ import de.dhbwstuttgart.typinference.unify.model.Type; */ public class Unify { - public Menge> unify(Menge eq, IFiniteClosure fc) { + public Menge> unify(Set eq, IFiniteClosure fc) { /* * Step 1: Repeated application of reduce, adapt, erase, swap */ Set eq0 = applyTypeUnificationRules(eq, fc); - /* * Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs */ @@ -52,7 +51,7 @@ public class Unify { // Sets that originate from pair pattern matching // Sets of the "second level" - List>> pairSets = calculatePairSets(eq2s, fc); + List>> pairSetsSet = calculatePairSets(eq2s, fc); // The sets of the "first level" Set> sets = new HashSet>(); @@ -70,15 +69,15 @@ public class Unify { // Calculate the inner cartesian products // Cartesian products of the second level - for(List> pairSet : pairSets) // Prüfen ob addAll stimmt oder ob hier eigentlich nur 1 set sein sollte - setOps.cartesianProduct(pairSet).forEach(x -> sets.add(new HashSet(x))); + for(List> pairSets : pairSetsSet) // Prüfen ob addAll stimmt oder ob hier eigentlich nur 1 set sein sollte + setOps.cartesianProduct(pairSets).forEach(x -> sets.add(new HashSet(x))); // Calculate the outer cartesian products // Cartesian products of the first level Set> eqsSet = setOps.cartesianProduct(new ArrayList<>(sets)); /* - * Step 5: Repeated substitution + * Step 5: Substitution */ @@ -122,7 +121,7 @@ public class Unify { * Apply rules until the queue is empty */ while(!eqQueue.isEmpty()) { - MPair pair = eqQueue.getFirst(); + MPair pair = eqQueue.pollFirst(); // ReduceUp, ReduceLow, ReduceUpLow Optional opt = rules.reduceUpLow(pair); diff --git a/test/unify/UnifyTest.java b/test/unify/UnifyTest.java index 747374b29..65f94d962 100644 --- a/test/unify/UnifyTest.java +++ b/test/unify/UnifyTest.java @@ -1,7 +1,51 @@ package unify; +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; + +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unifynew.Unify; +import de.dhbwstuttgart.typinference.unify.model.MPair; +import de.dhbwstuttgart.typinference.unify.model.MPair.PairOperator; public class UnifyTest extends Unify { - + + @Test + public void unifyTest() { + TypeFactory tf = new TypeFactory(); + FiniteClosureBuilder fcb = new FiniteClosureBuilder(); + Set eq = new HashSet(); + + fcb.add(tf.getSimpleType("Number"), tf.getSimpleType("Object")); + fcb.add(tf.getSimpleType("Integer"), tf.getSimpleType("Number")); + fcb.add(tf.getSimpleType("Double"), tf.getSimpleType("Number")); + + IFiniteClosure fc = fcb.getCollectionExample(); + + // Vector <. Vector + // A <. Number + // Double <. B + // B <. Object + eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT)); + eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("Number"), PairOperator.SMALLERDOT)); + eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT)); + eq.add(new MPair(tf.getSimpleType("Double"), tf.getPlaceholderType("B"), PairOperator.SMALLERDOT)); + eq.add(new MPair(tf.getPlaceholderType("B"), tf.getSimpleType("Object"), PairOperator.EQUALSDOT)); + + this.unify(eq, fc); + + } + + @Test + public void applyTypeUnificationRulesTest() { + + } + + @Test + public void calculatePairSetsTest() { + + } + }