You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
7.0 KiB

  1. public class CheckSparseVector {
  2. public static void main(String[] args) {
  3. //(ausgelagert)
  4. // erstellen des this.Vektors = control Vector
  5. SparseVector controlVector = new SparseVector(10);
  6. controlVector.setElement(0, 10.0);
  7. controlVector.setElement(5, 123.213);
  8. controlVector.setElement(8, 65.01);
  9. controlVector.setElement(9, 112.79);
  10. System.out.println("\n");
  11. // erstellen der testVektoren (the 5 "others")
  12. SparseVector otherVector1 = new SparseVector(10);
  13. otherVector1.setElement(0, 10.0);
  14. otherVector1.setElement(5, 123.213);
  15. otherVector1.setElement(8, 65.01);
  16. otherVector1.setElement(9, 112.79);
  17. System.out.println("\n");
  18. SparseVector otherVector2 = new SparseVector(5);
  19. otherVector2.setElement(0, 11.0);
  20. otherVector2.setElement(3, 22.2);
  21. System.out.println("\n");
  22. SparseVector otherVector3 = new SparseVector(20);
  23. otherVector3.setElement(0,123);
  24. otherVector3.setElement(5,11);
  25. otherVector3.setElement(11,2);
  26. otherVector3.setElement(14,3);
  27. otherVector3.setElement(18,4);
  28. System.out.println("\n");
  29. SparseVector otherVector4 = new SparseVector(10); // ein leerer other. Vektor mit Länge 10
  30. System.out.println("der Wert des otherVector4 an der Position 5 ist: "+ otherVector4.getElement(5)); // 0.0
  31. System.out.println("der Wert des otherVector4 an der Position 7 ist: "+ otherVector4.getElement(7));// 0.0
  32. System.out.println("der Wert des otherVector4 an der Position 9 ist: " + otherVector4.getElement(9));// 0.0
  33. System.out.println("die Länge des otherVector4 ist: " + otherVector4.getLength()); // 10
  34. System.out.println("\n");
  35. SparseVector otherVector5 = new SparseVector(20); // ein leerer other. Vektor mit Länge 10
  36. System.out.println("der Wert des otherVector5 an der Position 5 ist: "+ otherVector5.getElement(5)); // 0.0
  37. System.out.println("der Wert des otherVector5 an der Position 17 ist: "+ otherVector5.getElement(17));// 0.0
  38. System.out.println("der Wert des otherVector5 an der Position 19 ist: " + otherVector5.getElement(19));// 0.0
  39. System.out.println("die Länge des otherVector5 ist: " + otherVector5.getLength()); // 20
  40. System.out.println("\n");
  41. // Testen des this. Vektors --> testen Methoden wie getLength(), getElement(), setElement(), removeElement()
  42. System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10
  43. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 123.213
  44. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); //10.0
  45. System.out.println("der Wert des controlVector an der Position 1 ist: " + controlVector.getElement(1)); //0.0
  46. // testen equal(), wenn die beiden Vektoren identisch sind → should be true
  47. System.out.println(controlVector.equals(otherVector1));
  48. System.out.println("\n");
  49. controlVector.removeElement(5);
  50. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 0.0
  51. System.out.println("Die Länge nach remove ist: "+ controlVector.getLength()); // 10
  52. controlVector.removeElement(7);
  53. System.out.println("der Wert des controlVector an der Position 7 ist: "+ controlVector.getElement(7)); // 0.0
  54. controlVector.setElement(5, 100);
  55. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); //100.0
  56. System.out.println("\n");
  57. // testen equals(other) --> nicht identisch
  58. System.out.println(controlVector.equals(otherVector1)); // should be false, weil der Wert an Index 5 zu 100 gesetzt wurde
  59. System.out.println(controlVector.equals(otherVector2)); // should be false
  60. System.out.println(controlVector.equals(otherVector3)); // should be false
  61. System.out.println(controlVector.equals(otherVector4)); // should be false
  62. System.out.println("\n");
  63. otherVector1.setElement(5, 100);
  64. System.out.println("der Wert des otherVector1 an der Position 5 ist: "+ otherVector1.getElement(5)); //100.0
  65. System.out.println(otherVector1.equals(controlVector));// should be true, weil der Wert an Index 5 von this und other Vektor gleich 100
  66. System.out.println("\n");
  67. // testen add()
  68. controlVector.add(otherVector1);
  69. System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10
  70. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 10 + 10 = 20
  71. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 100 + 100 = 200
  72. System.out.println("der Wert des controlVector an der Position 6 ist: " + controlVector.getElement(6)); // 0.0
  73. System.out.println("der Wert des controlVector an der Position 8 ist: " + controlVector.getElement(8)); // 65.01 + 65.01 = 130.02
  74. System.out.println("der Wert des controlVector an der Position 9 ist: " + controlVector.getElement(9)); // 112.79 + 112.79 = 225.58
  75. System.out.println("\n");
  76. controlVector.add(otherVector2);
  77. controlVector.setElement(3,90.1);
  78. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 20
  79. System.out.println("der Wert des controlVector an der Position 3 ist: " + controlVector.getElement(3)); // 90.1
  80. System.out.println("\n");
  81. controlVector.add(otherVector3);
  82. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 20
  83. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 200
  84. System.out.println("der Wert des controlVector an der Position 9 ist: "+ controlVector.getElement(9)); // 225.58
  85. System.out.println("\n");
  86. controlVector.add(otherVector4);
  87. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0));
  88. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5));
  89. System.out.println("\n");
  90. controlVector.removeElement(0);
  91. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 0.0
  92. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 200
  93. System.out.println("\n");
  94. controlVector.add(otherVector5);
  95. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 0.0
  96. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 200
  97. System.out.println("\n");
  98. }
  99. }