forked from JavaTX/JavaCompilerCore
108 lines
2.5 KiB
Java
108 lines
2.5 KiB
Java
package KomplexeMenge;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import java.util.Set;
|
|
import java.util.Vector;
|
|
|
|
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 TestKlasse {
|
|
static int identifier = 0;
|
|
public String name;
|
|
int id;
|
|
|
|
TestKlasse(String name){
|
|
this.name = name;
|
|
id = 0;
|
|
}
|
|
|
|
public String toString(){
|
|
return name+" #"+id;
|
|
}
|
|
}
|
|
|
|
class TestKlasseOderMenge extends OderMenge<TestKlasse>{
|
|
Menge<TestKlasseUndMenge> set = new Menge<>();
|
|
|
|
@Override
|
|
public Menge<? extends KomplexeMenge<TestKlasse>> getSet() {
|
|
return set;
|
|
}
|
|
|
|
public void addItem(TestKlasse string) {
|
|
TestKlasseUndMenge toAdd = new TestKlasseUndMenge();
|
|
toAdd.addItem(string);
|
|
set.add(toAdd);
|
|
}
|
|
public void addItems(TestKlasseUndMenge undMenge) {
|
|
set.add(undMenge);
|
|
}
|
|
}
|
|
|
|
class TestKlasseUndMenge extends UndMenge<TestKlasse>{
|
|
Menge<KomplexeMenge<TestKlasse>> set = new Menge<>();
|
|
|
|
@Override
|
|
public Menge<? extends KomplexeMenge<TestKlasse>> getSet() {
|
|
return set;
|
|
}
|
|
public void addItem(TestKlasse string) {
|
|
set.add(new EinzelElement<TestKlasse>(string));
|
|
}
|
|
|
|
public void addItems(KomplexeMenge<TestKlasse> oderMenge) {
|
|
set.add(oderMenge);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Depreciated
|
|
* Tests möglicherweise obsolet
|
|
*/
|
|
public class KeineDoppeltenVerweise {
|
|
|
|
@Test
|
|
public void test() {
|
|
TestKlasseOderMenge oM1 = new TestKlasseOderMenge();
|
|
TestKlasseOderMenge oM2 = new TestKlasseOderMenge();
|
|
TestKlasseUndMenge oM3 = new TestKlasseUndMenge();
|
|
oM1.addItem(new TestKlasse("Menge 1, Item 1"));
|
|
oM1.addItem(new TestKlasse("Menge 1, Item 2"));
|
|
oM2.addItem(new TestKlasse("Menge 2, Item 1"));
|
|
oM2.addItem(new TestKlasse("Menge 2, Item 2"));
|
|
oM3.addItems(oM1);
|
|
oM3.addItems(oM2);
|
|
Set<Set<TestKlasse>> cP = oM3.cartesianProduct();
|
|
System.out.println(cP);
|
|
cP.iterator().next().iterator().next().name="neu";
|
|
System.out.println(cP);
|
|
//check(cP); //TODO Muss neu implementiert werden
|
|
}
|
|
|
|
private <A> void check(Menge<Menge<A>> cP){
|
|
Menge<A> allElements = new Menge<>();
|
|
for(Vector<A> v : cP)for(A i : v){
|
|
Object o = containsRef(allElements, i);
|
|
if(o!=null){
|
|
fail("Ein Verweis ist im Karthesischen Produkt doppelt vorhanden: "+o+" == "+i);
|
|
}else{
|
|
allElements.add(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
private Object containsRef(Menge v, Object i){
|
|
for(Object o : v){
|
|
if(i == o)return o;
|
|
}
|
|
return null;
|
|
}
|
|
}
|