ConstraintsSet überarbeitet

This commit is contained in:
JanUlrich 2015-06-03 14:10:12 +02:00
parent e6606d08ee
commit 6bb01f012f
5 changed files with 63 additions and 62 deletions

View File

@ -21,7 +21,7 @@ public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConst
public void add(OderConstraint constraint){ public void add(OderConstraint constraint){
constraintsSet.add(constraint); constraintsSet.add(constraint);
} }
@Override @Override
public String toString(){ public String toString(){
String ret =""; String ret ="";

View File

@ -11,19 +11,6 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier; import de.dhbwstuttgart.typeinference.unify.Unifier;
/*
* KomplexeMenge
* OderMenge
* Menge
* Item
*/
interface KomplexeMenge<A>{
Menge<? extends KomplexeMenge<A>> getSet();
Menge<Menge<A>> cartesianProduct();
}
public abstract class OderMenge<A> implements KomplexeMenge<A>{ public abstract class OderMenge<A> implements KomplexeMenge<A>{
public abstract Menge<? extends KomplexeMenge<A>> getSet(); public abstract Menge<? extends KomplexeMenge<A>> getSet();

View File

@ -31,6 +31,13 @@ public class SingleConstraint extends UndConstraint{
this.addConstraint(constraintPair); this.addConstraint(constraintPair);
} }
@Override
public Menge<? extends KomplexeMenge<Pair>> getSet() {
Menge<EinzelElement<Pair>> ret = new Menge<>();
ret.add(new EinzelElement<>(constraintPair));
return ret;
}
public SingleConstraint(ConstraintPair toAdd) { public SingleConstraint(ConstraintPair toAdd) {
this.addConstraint(toAdd); this.addConstraint(toAdd);
} }

View File

@ -40,33 +40,3 @@ public abstract class UndMenge<A> implements KomplexeMenge<A>{
} }
} }
class EinzelElement<A> implements KomplexeMenge<A>{
private A item;
public EinzelElement(A element){
item = element;
}
public Menge<KomplexeMenge<A>> getSet(){
Menge<KomplexeMenge<A>> ret = new Menge<>();
ret.add(this);
return ret;
}
@Override
public Menge<Menge<A>> cartesianProduct() {
Cloner cloner = new Cloner();
Menge<Menge<A>> ret = new Menge<>();
Menge<A> i = new Menge<A>();
i.add(cloner.deepClone(item));
ret.add(i);
return ret;
}
@Override
public String toString(){
return item.toString();
}
}

View File

@ -4,17 +4,54 @@ import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import de.dhbwstuttgart.typeinference.EinzelElement;
import de.dhbwstuttgart.typeinference.KomplexeMenge;
import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.OderMenge; import de.dhbwstuttgart.typeinference.OderMenge;
import de.dhbwstuttgart.typeinference.UndMenge; import de.dhbwstuttgart.typeinference.UndMenge;
class TestOderMenge extends OderMenge<String>{
Menge<TestUndMenge> set = new Menge<>();
@Override
public Menge<? extends KomplexeMenge<String>> getSet() {
return set;
}
public void addItem(String string) {
TestUndMenge toAdd = new TestUndMenge();
toAdd.addItem(string);
set.add(toAdd);
}
public void addItems(TestUndMenge undMenge) {
set.add(undMenge);
}
}
class TestUndMenge extends UndMenge<String>{
Menge<KomplexeMenge<String>> set = new Menge<>();
@Override
public Menge<? extends KomplexeMenge<String>> getSet() {
return set;
}
public void addItem(String string) {
set.add(new EinzelElement<String>(string));
}
public void addItems(KomplexeMenge<String> oderMenge) {
set.add(oderMenge);
}
}
public class KarthesischesProduktTest { public class KarthesischesProduktTest {
@Test @Test
public void test() { public void test() {
OderMenge<String> oM1 = new OderMenge<>(); TestOderMenge oM1 = new TestOderMenge();
OderMenge<String> oM2 = new OderMenge<>(); TestOderMenge oM2 = new TestOderMenge();
UndMenge<String> oM3 = new UndMenge<>(); TestUndMenge oM3 = new TestUndMenge();
oM1.addItem("Menge 1, Item 1"); oM1.addItem("Menge 1, Item 1");
oM1.addItem("Menge 1, Item 2"); oM1.addItem("Menge 1, Item 2");
oM2.addItem("Menge 2, Item 1"); oM2.addItem("Menge 2, Item 1");
@ -27,9 +64,9 @@ public class KarthesischesProduktTest {
@Test @Test
public void test2(){ public void test2(){
UndMenge<String> oM1 = new UndMenge<>(); TestUndMenge oM1 = new TestUndMenge();
UndMenge<String> oM2 = new UndMenge<>(); TestUndMenge oM2 = new TestUndMenge();
UndMenge<String> oM3 = new UndMenge<>(); TestUndMenge oM3 = new TestUndMenge();
oM1.addItem("Menge 1, Item 1"); oM1.addItem("Menge 1, Item 1");
oM1.addItem("Menge 1, Item 2"); oM1.addItem("Menge 1, Item 2");
oM2.addItem("Menge 2, Item 1"); oM2.addItem("Menge 2, Item 1");
@ -42,9 +79,9 @@ public class KarthesischesProduktTest {
@Test @Test
public void test3(){ public void test3(){
OderMenge<String> oM1 = new OderMenge<>(); TestOderMenge oM1 = new TestOderMenge();
UndMenge<String> oM2 = new UndMenge<>(); TestUndMenge oM2 = new TestUndMenge();
UndMenge<String> oM3 = new UndMenge<>(); TestUndMenge oM3 = new TestUndMenge();
oM1.addItem("Menge 1, Item 1"); oM1.addItem("Menge 1, Item 1");
oM1.addItem("Menge 1, Item 2"); oM1.addItem("Menge 1, Item 2");
oM2.addItem("Menge 2, Item 1"); oM2.addItem("Menge 2, Item 1");
@ -57,9 +94,9 @@ public class KarthesischesProduktTest {
@Test @Test
public void test4(){ public void test4(){
OderMenge<String> oM1 = new OderMenge<>(); TestOderMenge oM1 = new TestOderMenge();
UndMenge<String> oM2 = new UndMenge<>(); TestUndMenge oM2 = new TestUndMenge();
UndMenge<String> oM3 = new UndMenge<>(); TestUndMenge oM3 = new TestUndMenge();
oM2.addItem("Menge 2, Item 1"); oM2.addItem("Menge 2, Item 1");
oM2.addItem("Menge 2, Item 2"); oM2.addItem("Menge 2, Item 2");
oM3.addItems(oM1); oM3.addItems(oM1);
@ -70,9 +107,9 @@ public class KarthesischesProduktTest {
@Test @Test
public void test5(){ public void test5(){
OderMenge<String> oM1 = new OderMenge<>(); TestOderMenge oM1 = new TestOderMenge();
UndMenge<String> oM2 = new UndMenge<>(); TestUndMenge oM2 = new TestUndMenge();
UndMenge<String> oM3 = new UndMenge<>(); TestUndMenge oM3 = new TestUndMenge();
oM3.addItems(oM1); oM3.addItems(oM1);
oM3.addItems(oM2); oM3.addItems(oM2);
//System.out.println("undMenge:"+oM3.cartesianProduct()); //System.out.println("undMenge:"+oM3.cartesianProduct());
@ -81,9 +118,9 @@ public class KarthesischesProduktTest {
@Test @Test
public void test6(){ public void test6(){
OderMenge<String> oM1 = new OderMenge<>(); TestOderMenge oM1 = new TestOderMenge();
OderMenge<String> oM2 = new OderMenge<>(); TestOderMenge oM2 = new TestOderMenge();
UndMenge<String> oM3 = new UndMenge<>(); TestUndMenge oM3 = new TestUndMenge();
oM3.addItems(oM1); oM3.addItems(oM1);
oM3.addItems(oM2); oM3.addItems(oM2);
//System.out.println("undMenge:"+oM3.cartesianProduct()); //System.out.println("undMenge:"+oM3.cartesianProduct());