From 6bb01f012f89b4ea5de56642846a2d41d1c4cc2d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 3 Jun 2015 14:10:12 +0200 Subject: [PATCH] =?UTF-8?q?ConstraintsSet=20=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../typeinference/ConstraintsSet.java | 2 +- .../typeinference/OderMenge.java | 13 ---- .../typeinference/SingleConstraint.java | 7 ++ .../dhbwstuttgart/typeinference/UndMenge.java | 30 -------- .../KarthesischesProduktTest.java | 73 ++++++++++++++----- 5 files changed, 63 insertions(+), 62 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index 48d4c4dc..032b8f56 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -21,7 +21,7 @@ public class ConstraintsSet extends UndMenge implements Iterable{ - Menge> getSet(); - Menge> cartesianProduct(); -} - public abstract class OderMenge implements KomplexeMenge{ public abstract Menge> getSet(); diff --git a/src/de/dhbwstuttgart/typeinference/SingleConstraint.java b/src/de/dhbwstuttgart/typeinference/SingleConstraint.java index 6ac5b4f6..f405b9ee 100755 --- a/src/de/dhbwstuttgart/typeinference/SingleConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/SingleConstraint.java @@ -31,6 +31,13 @@ public class SingleConstraint extends UndConstraint{ this.addConstraint(constraintPair); } + @Override + public Menge> getSet() { + Menge> ret = new Menge<>(); + ret.add(new EinzelElement<>(constraintPair)); + return ret; + } + public SingleConstraint(ConstraintPair toAdd) { this.addConstraint(toAdd); } diff --git a/src/de/dhbwstuttgart/typeinference/UndMenge.java b/src/de/dhbwstuttgart/typeinference/UndMenge.java index 98168c1c..0dd2c06c 100644 --- a/src/de/dhbwstuttgart/typeinference/UndMenge.java +++ b/src/de/dhbwstuttgart/typeinference/UndMenge.java @@ -40,33 +40,3 @@ public abstract class UndMenge implements KomplexeMenge{ } } - -class EinzelElement implements KomplexeMenge{ - private A item; - - public EinzelElement(A element){ - item = element; - } - - public Menge> getSet(){ - Menge> ret = new Menge<>(); - ret.add(this); - return ret; - } - - @Override - public Menge> cartesianProduct() { - Cloner cloner = new Cloner(); - Menge> ret = new Menge<>(); - Menge i = new Menge(); - i.add(cloner.deepClone(item)); - ret.add(i); - return ret; - } - - @Override - public String toString(){ - return item.toString(); - } - -} \ No newline at end of file diff --git a/test/KomplexeMenge/KarthesischesProduktTest.java b/test/KomplexeMenge/KarthesischesProduktTest.java index 6d48b918..89979df8 100644 --- a/test/KomplexeMenge/KarthesischesProduktTest.java +++ b/test/KomplexeMenge/KarthesischesProduktTest.java @@ -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{ + Menge set = new Menge<>(); + + @Override + public Menge> 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{ + Menge> set = new Menge<>(); + + @Override + public Menge> getSet() { + return set; + } + public void addItem(String string) { + set.add(new EinzelElement(string)); + } + + public void addItems(KomplexeMenge oderMenge) { + set.add(oderMenge); + } +} + public class KarthesischesProduktTest { + @Test public void test() { - OderMenge oM1 = new OderMenge<>(); - OderMenge oM2 = new OderMenge<>(); - UndMenge 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 oM1 = new UndMenge<>(); - UndMenge oM2 = new UndMenge<>(); - UndMenge 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 oM1 = new OderMenge<>(); - UndMenge oM2 = new UndMenge<>(); - UndMenge 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 oM1 = new OderMenge<>(); - UndMenge oM2 = new UndMenge<>(); - UndMenge 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 oM1 = new OderMenge<>(); - UndMenge oM2 = new UndMenge<>(); - UndMenge 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 oM1 = new OderMenge<>(); - OderMenge oM2 = new OderMenge<>(); - UndMenge 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());