|
|
@ -1,10 +1,8 @@ |
|
|
|
public class CheckSparseVector { |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
//(ausgelagert) |
|
|
|
|
|
|
|
// (ausgelagert) |
|
|
|
// erstellen des this.Vektors = control Vector |
|
|
|
SparseVector controlVector = new SparseVector(10); |
|
|
|
controlVector.setElement(0, 10.0); |
|
|
@ -33,138 +31,146 @@ public class CheckSparseVector { |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
SparseVector otherVector3 = new SparseVector(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); |
|
|
|
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"); |
|
|
|
|
|
|
|
SparseVector otherVector4 = new SparseVector(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 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{ |
|
|
|
try { |
|
|
|
System.out.println(otherVector4.getElement(99)); |
|
|
|
} catch(Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
try{ |
|
|
|
try { |
|
|
|
System.out.println(otherVector4.getElement(-1)); |
|
|
|
} catch(Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
SparseVector otherVector5 = new SparseVector(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 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{ |
|
|
|
try { |
|
|
|
System.out.println(otherVector5.getElement(20)); |
|
|
|
} catch(Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
try{ |
|
|
|
try { |
|
|
|
System.out.println(otherVector5.getElement(-1)); |
|
|
|
} catch(Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
|
|
|
|
// Testen des this. Vektors --> testen Methoden wie getLength(), getElement(), setElement(), removeElement() |
|
|
|
// 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("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){ |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
try{ |
|
|
|
try { |
|
|
|
System.out.println(controlVector.getElement(-1)); |
|
|
|
} catch(Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
// testen equal(), wenn die beiden Vektoren identisch sind → should be true, not anymore :) |
|
|
|
// testen equal(), wenn die beiden Vektoren identisch sind → should be true, not |
|
|
|
// anymore :) |
|
|
|
System.out.println(controlVector.equals(otherVector1)); |
|
|
|
System.out.println("\n"); |
|
|
|
|
|
|
|
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("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("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("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(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("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 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("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 |
|
|
|
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("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("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("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("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"); |
|
|
|
|
|
|
|
} |
|
|
|