forked from JavaTX/JavaCompilerCore
ConstraintsSet überarbeitet
This commit is contained in:
parent
e6606d08ee
commit
6bb01f012f
@ -21,7 +21,7 @@ public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConst
|
||||
public void add(OderConstraint constraint){
|
||||
constraintsSet.add(constraint);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
String ret ="";
|
||||
|
@ -11,19 +11,6 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
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 Menge<? extends KomplexeMenge<A>> getSet();
|
||||
|
@ -31,6 +31,13 @@ public class SingleConstraint extends UndConstraint{
|
||||
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) {
|
||||
this.addConstraint(toAdd);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -4,17 +4,54 @@ import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.EinzelElement;
|
||||
import de.dhbwstuttgart.typeinference.KomplexeMenge;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.OderMenge;
|
||||
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 {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
OderMenge<String> oM1 = new OderMenge<>();
|
||||
OderMenge<String> oM2 = new OderMenge<>();
|
||||
UndMenge<String> oM3 = new UndMenge<>();
|
||||
TestOderMenge oM1 = new TestOderMenge();
|
||||
TestOderMenge oM2 = new TestOderMenge();
|
||||
TestUndMenge oM3 = new TestUndMenge();
|
||||
oM1.addItem("Menge 1, Item 1");
|
||||
oM1.addItem("Menge 1, Item 2");
|
||||
oM2.addItem("Menge 2, Item 1");
|
||||
@ -27,9 +64,9 @@ public class KarthesischesProduktTest {
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
UndMenge<String> oM1 = new UndMenge<>();
|
||||
UndMenge<String> oM2 = new UndMenge<>();
|
||||
UndMenge<String> oM3 = new UndMenge<>();
|
||||
TestUndMenge oM1 = new TestUndMenge();
|
||||
TestUndMenge oM2 = new TestUndMenge();
|
||||
TestUndMenge oM3 = new TestUndMenge();
|
||||
oM1.addItem("Menge 1, Item 1");
|
||||
oM1.addItem("Menge 1, Item 2");
|
||||
oM2.addItem("Menge 2, Item 1");
|
||||
@ -42,9 +79,9 @@ public class KarthesischesProduktTest {
|
||||
|
||||
@Test
|
||||
public void test3(){
|
||||
OderMenge<String> oM1 = new OderMenge<>();
|
||||
UndMenge<String> oM2 = new UndMenge<>();
|
||||
UndMenge<String> oM3 = new UndMenge<>();
|
||||
TestOderMenge oM1 = new TestOderMenge();
|
||||
TestUndMenge oM2 = new TestUndMenge();
|
||||
TestUndMenge oM3 = new TestUndMenge();
|
||||
oM1.addItem("Menge 1, Item 1");
|
||||
oM1.addItem("Menge 1, Item 2");
|
||||
oM2.addItem("Menge 2, Item 1");
|
||||
@ -57,9 +94,9 @@ public class KarthesischesProduktTest {
|
||||
|
||||
@Test
|
||||
public void test4(){
|
||||
OderMenge<String> oM1 = new OderMenge<>();
|
||||
UndMenge<String> oM2 = new UndMenge<>();
|
||||
UndMenge<String> oM3 = new UndMenge<>();
|
||||
TestOderMenge oM1 = new TestOderMenge();
|
||||
TestUndMenge oM2 = new TestUndMenge();
|
||||
TestUndMenge oM3 = new TestUndMenge();
|
||||
oM2.addItem("Menge 2, Item 1");
|
||||
oM2.addItem("Menge 2, Item 2");
|
||||
oM3.addItems(oM1);
|
||||
@ -70,9 +107,9 @@ public class KarthesischesProduktTest {
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
OderMenge<String> oM1 = new OderMenge<>();
|
||||
UndMenge<String> oM2 = new UndMenge<>();
|
||||
UndMenge<String> oM3 = new UndMenge<>();
|
||||
TestOderMenge oM1 = new TestOderMenge();
|
||||
TestUndMenge oM2 = new TestUndMenge();
|
||||
TestUndMenge oM3 = new TestUndMenge();
|
||||
oM3.addItems(oM1);
|
||||
oM3.addItems(oM2);
|
||||
//System.out.println("undMenge:"+oM3.cartesianProduct());
|
||||
@ -81,9 +118,9 @@ public class KarthesischesProduktTest {
|
||||
|
||||
@Test
|
||||
public void test6(){
|
||||
OderMenge<String> oM1 = new OderMenge<>();
|
||||
OderMenge<String> oM2 = new OderMenge<>();
|
||||
UndMenge<String> oM3 = new UndMenge<>();
|
||||
TestOderMenge oM1 = new TestOderMenge();
|
||||
TestOderMenge oM2 = new TestOderMenge();
|
||||
TestUndMenge oM3 = new TestUndMenge();
|
||||
oM3.addItems(oM1);
|
||||
oM3.addItems(oM2);
|
||||
//System.out.println("undMenge:"+oM3.cartesianProduct());
|
||||
|
Loading…
Reference in New Issue
Block a user