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.

171 lines
8.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  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. controlVector.setElement(10, -212.79);
  11. System.out.println("\n");
  12. // erstellen der testVektoren (the 5 "others")
  13. SparseVector otherVector1 = new SparseVector(10);
  14. otherVector1.setElement(0, 10.0);
  15. otherVector1.setElement(5, 123.213);
  16. otherVector1.setElement(8, 65.01);
  17. otherVector1.setElement(9, 112.79);
  18. otherVector1.setElement(10, -212.79);
  19. otherVector1.setElement(12, 12);
  20. System.out.println("\n");
  21. SparseVector otherVector2 = new SparseVector(5);
  22. otherVector2.setElement(0, 0);
  23. otherVector2.setElement(1, 2);
  24. otherVector2.setElement(2, 5);
  25. otherVector2.setElement(3, 11.0);
  26. otherVector2.setElement(4, 22.2);
  27. System.out.println("\n");
  28. SparseVector otherVector3 = new SparseVector(20);
  29. otherVector3.setElement(0,123);
  30. otherVector3.setElement(5,11);
  31. otherVector3.setElement(6,20);
  32. otherVector3.setElement(7,7);
  33. otherVector3.setElement(11,2);
  34. otherVector3.setElement(14,3);
  35. otherVector3.setElement(18,4);
  36. System.out.println("\n");
  37. SparseVector otherVector4 = new SparseVector(10); // ein leerer other. Vektor mit Länge 10
  38. System.out.println("der Wert des otherVector4 an der Position 0 ist: "+ otherVector4.getElement(0)); // 0.0
  39. System.out.println("der Wert des otherVector4 an der Position 5 ist: "+ otherVector4.getElement(5)); // 0.0
  40. System.out.println("der Wert des otherVector4 an der Position 7 ist: "+ otherVector4.getElement(7));// 0.0
  41. System.out.println("der Wert des otherVector4 an der Position 9 ist: " + otherVector4.getElement(9));// 0.0
  42. System.out.println("die Länge des otherVector4 ist: " + otherVector4.getLength()); // 10
  43. try{
  44. System.out.println(otherVector4.getElement(99));
  45. } catch(Exception e){
  46. System.out.println(e);
  47. }
  48. try{
  49. System.out.println(otherVector4.getElement(-1));
  50. } catch(Exception e){
  51. System.out.println(e);
  52. }
  53. System.out.println("\n");
  54. SparseVector otherVector5 = new SparseVector(20); // ein leerer other. Vektor mit Länge 20
  55. System.out.println("der Wert des otherVector5 an der Position 0 ist: "+ otherVector5.getElement(0)); // 0.0
  56. System.out.println("der Wert des otherVector5 an der Position 5 ist: "+ otherVector5.getElement(5)); // 0.0
  57. System.out.println("der Wert des otherVector5 an der Position 17 ist: "+ otherVector5.getElement(17));// 0.0
  58. System.out.println("der Wert des otherVector5 an der Position 19 ist: " + otherVector5.getElement(19));// 0.0
  59. System.out.println("die Länge des otherVector5 ist: " + otherVector5.getLength()); // 20
  60. try{
  61. System.out.println(otherVector5.getElement(20));
  62. } catch(Exception e){
  63. System.out.println(e);
  64. }
  65. try{
  66. System.out.println(otherVector5.getElement(-1));
  67. } catch(Exception e){
  68. System.out.println(e);
  69. }
  70. System.out.println("\n");
  71. // Testen des this. Vektors --> testen Methoden wie getLength(), getElement(), setElement(), removeElement()
  72. System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10
  73. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 123.213
  74. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); //10.0
  75. System.out.println("der Wert des controlVector an der Position 1 ist: " + controlVector.getElement(1)); //0.0
  76. try{
  77. System.out.println(controlVector.getElement(99));
  78. } catch(Exception e){
  79. System.out.println(e);
  80. }
  81. try{
  82. System.out.println(controlVector.getElement(-1));
  83. } catch(Exception e){
  84. System.out.println(e);
  85. }
  86. System.out.println("\n");
  87. // testen equal(), wenn die beiden Vektoren identisch sind → should be true, not anymore :)
  88. System.out.println(controlVector.equals(otherVector1));
  89. System.out.println("\n");
  90. controlVector.removeElement(5);
  91. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 0.0
  92. System.out.println("Die Länge nach remove ist: "+ controlVector.getLength()); // 10
  93. System.out.println("\n");
  94. controlVector.removeElement(7);
  95. System.out.println("der Wert des controlVector an der Position 7 ist: "+ controlVector.getElement(7)); // 0.0
  96. System.out.println("\n");
  97. controlVector.setElement(5, 100);
  98. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); //100.0
  99. System.out.println("\n");
  100. // testen equals(other) --> nicht identisch
  101. System.out.println(controlVector.equals(otherVector1)); // should be false, weil der Wert an Index 5 zu 100 gesetzt wurde
  102. System.out.println(controlVector.equals(otherVector2)); // should be false
  103. System.out.println(controlVector.equals(otherVector3)); // should be false
  104. System.out.println(controlVector.equals(otherVector4)); // should be false
  105. System.out.println("\n");
  106. otherVector1.setElement(5, 100);
  107. System.out.println("der Wert des otherVector1 an der Position 5 ist: "+ otherVector1.getElement(5)); //100.0
  108. System.out.println(otherVector1.equals(controlVector));// should be true, weil der Wert an Index 5 von this und other Vektor gleich 100
  109. System.out.println("\n");
  110. // testen add()
  111. controlVector.add(otherVector1);
  112. System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10
  113. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 10 + 10 = 20
  114. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 100 + 100 = 200
  115. System.out.println("der Wert des controlVector an der Position 6 ist: " + controlVector.getElement(6)); // 0.0
  116. System.out.println("der Wert des controlVector an der Position 8 ist: " + controlVector.getElement(8)); // 65.01 + 65.01 = 130.02
  117. System.out.println("der Wert des controlVector an der Position 9 ist: " + controlVector.getElement(9)); // 112.79 + 112.79 = 225.58
  118. System.out.println("\n");
  119. controlVector.add(otherVector2);
  120. controlVector.setElement(3,90.1);
  121. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 20
  122. System.out.println("der Wert des controlVector an der Position 3 ist: " + controlVector.getElement(3)); // 90.1
  123. System.out.println("\n");
  124. controlVector.add(otherVector3);
  125. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 20
  126. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 200
  127. System.out.println("der Wert des controlVector an der Position 9 ist: "+ controlVector.getElement(9)); // 225.58
  128. System.out.println("\n");
  129. controlVector.add(otherVector4);
  130. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0));
  131. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5));
  132. System.out.println("\n");
  133. controlVector.removeElement(0);
  134. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 0.0
  135. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 200
  136. System.out.println("\n");
  137. controlVector.add(otherVector5);
  138. System.out.println("der Wert des controlVector an der Position 0 ist: "+ controlVector.getElement(0)); // 0.0
  139. System.out.println("der Wert des controlVector an der Position 5 ist: "+ controlVector.getElement(5)); // 200
  140. System.out.println("\n");
  141. }
  142. }