|
|
@ -0,0 +1,169 @@ |
|
|
|
public class Main { |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
// (ausgelagert) |
|
|
|
// erstellen des this.Vektors = control Vector |
|
|
|
RBTree controlVector = new RBTree(10); |
|
|
|
controlVector.setElement(0, 10.0); |
|
|
|
controlVector.setElement(5, 123.213); |
|
|
|
controlVector.setElement(8, 65.01); |
|
|
|
controlVector.setElement(9, 112.79); |
|
|
|
controlVector.setElement(10, -212.79); |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
// erstellen der testVektoren (the 5 "others") |
|
|
|
RBTree otherVector1 = new RBTree(10); |
|
|
|
otherVector1.setElement(0, 10.0); |
|
|
|
otherVector1.setElement(5, 123.213); |
|
|
|
otherVector1.setElement(8, 65.01); |
|
|
|
otherVector1.setElement(9, 112.79); |
|
|
|
otherVector1.setElement(10, -212.79); |
|
|
|
otherVector1.setElement(12, 12); |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
RBTree otherVector2 = new RBTree(5); |
|
|
|
otherVector2.setElement(0, 0); |
|
|
|
otherVector2.setElement(1, 2); |
|
|
|
otherVector2.setElement(2, 5); |
|
|
|
otherVector2.setElement(3, 11.0); |
|
|
|
otherVector2.setElement(4, 22.2); |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
RBTree otherVector3 = new RBTree(20); |
|
|
|
otherVector3.setElement(0, 123); |
|
|
|
otherVector3.setElement(5, 11); |
|
|
|
otherVector3.setElement(6, 20); |
|
|
|
otherVector3.setElement(7, 7); |
|
|
|
otherVector3.setElement(11, 2); |
|
|
|
otherVector3.setElement(14, 3); |
|
|
|
otherVector3.setElement(18, 4); |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
RBTree otherVector4 = new RBTree(10); // ein leerer other. Vektor mit Länge 10 |
|
|
|
System.out.println("der Wert des otherVector4 an der Position 0 ist: " + otherVector4.getElement(0)); // 0.0 |
|
|
|
System.out.println("der Wert des otherVector4 an der Position 5 ist: " + otherVector4.getElement(5)); // 0.0 |
|
|
|
System.out.println("der Wert des otherVector4 an der Position 7 ist: " + otherVector4.getElement(7));// 0.0 |
|
|
|
System.out.println("der Wert des otherVector4 an der Position 9 ist: " + otherVector4.getElement(9));// 0.0 |
|
|
|
System.out.println("die Länge des otherVector4 ist: " + otherVector4.getLength()); // 10 |
|
|
|
try { |
|
|
|
System.out.println(otherVector4.getElement(99)); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
try { |
|
|
|
System.out.println(otherVector4.getElement(-1)); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
RBTree otherVector5 = new RBTree(20); // ein leerer other. Vektor mit Länge 20 |
|
|
|
System.out.println("der Wert des otherVector5 an der Position 0 ist: " + otherVector5.getElement(0)); // 0.0 |
|
|
|
System.out.println("der Wert des otherVector5 an der Position 5 ist: " + otherVector5.getElement(5)); // 0.0 |
|
|
|
System.out.println("der Wert des otherVector5 an der Position 17 ist: " + otherVector5.getElement(17));// 0.0 |
|
|
|
System.out.println("der Wert des otherVector5 an der Position 19 ist: " + otherVector5.getElement(19));// 0.0 |
|
|
|
System.out.println("die Länge des otherVector5 ist: " + otherVector5.getLength()); // 20 |
|
|
|
try { |
|
|
|
System.out.println(otherVector5.getElement(20)); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
try { |
|
|
|
System.out.println(otherVector5.getElement(-1)); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
// Testen des this. Vektors --> testen Methoden wie getLength(), getElement(), |
|
|
|
// setElement(), removeElement() |
|
|
|
System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10 |
|
|
|
System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 123.213 |
|
|
|
System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 10.0 |
|
|
|
System.out.println("der Wert des controlVector an der Position 1 ist: " + controlVector.getElement(1)); // 0.0 |
|
|
|
try { |
|
|
|
System.out.println(controlVector.getElement(99)); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
try { |
|
|
|
System.out.println(controlVector.getElement(-1)); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
// testen equal(), wenn die beiden Vektoren identisch sind → should be true, not anymore :) |
|
|
|
System.out.println(controlVector.equals(otherVector1)); |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
// Testen: Remove Element |
|
|
|
controlVector.removeElement(5); |
|
|
|
System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 0.0 |
|
|
|
System.out.println("Die Länge nach remove ist: " + controlVector.getLength()); // 10 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
controlVector.removeElement(7); |
|
|
|
System.out.println("der Wert des controlVector an der Position 7 ist: " + controlVector.getElement(7)); // 0.0 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
controlVector.setElement(5, 100); |
|
|
|
System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 100.0 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
// testen equals(other) --> nicht identisch |
|
|
|
System.out.println(controlVector.equals(otherVector1)); // should be false, weil der Wert an Index 5 zu 100 gesetzt wurde |
|
|
|
System.out.println(controlVector.equals(otherVector2)); // should be false |
|
|
|
System.out.println(controlVector.equals(otherVector3)); // should be false |
|
|
|
System.out.println(controlVector.equals(otherVector4)); // should be false |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
otherVector1.setElement(5, 100); |
|
|
|
System.out.println("der Wert des otherVector1 an der Position 5 ist: " + otherVector1.getElement(5)); // 100.0 |
|
|
|
System.out.println(otherVector1.equals(controlVector));// should be true, weil der Wert an Index 5 von this und other Vektor gleich 100 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
// testen add() |
|
|
|
controlVector.add(otherVector1); |
|
|
|
|
|
|
|
System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10 |
|
|
|
System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 10 + 10 = 20 |
|
|
|
System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 100 + 100 = 200 |
|
|
|
System.out.println("der Wert des controlVector an der Position 6 ist: " + controlVector.getElement(6)); // 0.0 |
|
|
|
System.out.println("der Wert des controlVector an der Position 8 ist: " + controlVector.getElement(8)); // 65.01 + 65.01 = 130.02 |
|
|
|
System.out.println("der Wert des controlVector an der Position 9 ist: " + controlVector.getElement(9)); // 112.79 + 112.79 = 225.58 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
controlVector.add(otherVector2); |
|
|
|
|
|
|
|
controlVector.setElement(3, 90.1); |
|
|
|
System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 20 |
|
|
|
System.out.println("der Wert des controlVector an der Position 3 ist: " + controlVector.getElement(3)); // 90.1 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
controlVector.add(otherVector3); |
|
|
|
System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 20 |
|
|
|
System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200 |
|
|
|
System.out.println("der Wert des controlVector an der Position 9 ist: " + controlVector.getElement(9)); // 225.58 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
controlVector.add(otherVector4); |
|
|
|
|
|
|
|
System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); |
|
|
|
System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
controlVector.removeElement(0); |
|
|
|
|
|
|
|
System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 0.0 |
|
|
|
System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
controlVector.add(otherVector5); |
|
|
|
System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 0.0 |
|
|
|
System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200 |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
} |
|
|
|
} |