forked from JavaTX/JavaCompilerCore
130 lines
3.3 KiB
Java
130 lines
3.3 KiB
Java
package KomplexeMenge;
|
|
|
|
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() {
|
|
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");
|
|
oM2.addItem("Menge 2, Item 2");
|
|
oM3.addItems(oM1);
|
|
oM3.addItems(oM2);
|
|
System.out.println(oM3.cartesianProduct());
|
|
assertTrue(oM3.cartesianProduct().size()==4);
|
|
}
|
|
|
|
@Test
|
|
public void test2(){
|
|
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");
|
|
oM2.addItem("Menge 2, Item 2");
|
|
oM3.addItems(oM1);
|
|
oM3.addItems(oM2);
|
|
System.out.println("undMenge:"+oM3.cartesianProduct());
|
|
assertTrue(oM3.cartesianProduct().size()==1);
|
|
}
|
|
|
|
@Test
|
|
public void test3(){
|
|
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");
|
|
oM2.addItem("Menge 2, Item 2");
|
|
oM3.addItems(oM1);
|
|
oM3.addItems(oM2);
|
|
//System.out.println("undMenge:"+oM3.cartesianProduct());
|
|
assertTrue(oM3.cartesianProduct().size()==2);
|
|
}
|
|
|
|
@Test
|
|
public void test4(){
|
|
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);
|
|
oM3.addItems(oM2);
|
|
//System.out.println("undMenge:"+oM3.cartesianProduct());
|
|
assertTrue(oM3.cartesianProduct().size()==0);
|
|
}
|
|
|
|
@Test
|
|
public void test5(){
|
|
TestOderMenge oM1 = new TestOderMenge();
|
|
TestUndMenge oM2 = new TestUndMenge();
|
|
TestUndMenge oM3 = new TestUndMenge();
|
|
oM3.addItems(oM1);
|
|
oM3.addItems(oM2);
|
|
//System.out.println("undMenge:"+oM3.cartesianProduct());
|
|
assertTrue(oM3.cartesianProduct().size()==0);
|
|
}
|
|
|
|
@Test
|
|
public void test6(){
|
|
TestOderMenge oM1 = new TestOderMenge();
|
|
TestOderMenge oM2 = new TestOderMenge();
|
|
TestUndMenge oM3 = new TestUndMenge();
|
|
oM3.addItems(oM1);
|
|
oM3.addItems(oM2);
|
|
//System.out.println("undMenge:"+oM3.cartesianProduct());
|
|
assertTrue(oM3.cartesianProduct().size()==0);
|
|
}
|
|
}
|