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.

177 lines
8.8 KiB

7 months ago
7 months 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(),
  72. // setElement(), removeElement()
  73. System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10
  74. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 123.213
  75. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 10.0
  76. System.out.println("der Wert des controlVector an der Position 1 ist: " + controlVector.getElement(1)); // 0.0
  77. try {
  78. System.out.println(controlVector.getElement(99));
  79. } catch (Exception e) {
  80. System.out.println(e);
  81. }
  82. try {
  83. System.out.println(controlVector.getElement(-1));
  84. } catch (Exception e) {
  85. System.out.println(e);
  86. }
  87. System.out.println("\n");
  88. // testen equal(), wenn die beiden Vektoren identisch sind → should be true, not
  89. // anymore :)
  90. System.out.println(controlVector.equals(otherVector1));
  91. System.out.println("\n");
  92. controlVector.removeElement(5);
  93. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 0.0
  94. System.out.println("Die Länge nach remove ist: " + controlVector.getLength()); // 10
  95. System.out.println("\n");
  96. controlVector.removeElement(7);
  97. System.out.println("der Wert des controlVector an der Position 7 ist: " + controlVector.getElement(7)); // 0.0
  98. System.out.println("\n");
  99. controlVector.setElement(5, 100);
  100. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 100.0
  101. System.out.println("\n");
  102. // testen equals(other) --> nicht identisch
  103. System.out.println(controlVector.equals(otherVector1)); // should be false, weil der Wert an Index 5 zu 100 gesetzt
  104. // wurde
  105. System.out.println(controlVector.equals(otherVector2)); // should be false
  106. System.out.println(controlVector.equals(otherVector3)); // should be false
  107. System.out.println(controlVector.equals(otherVector4)); // should be false
  108. System.out.println("\n");
  109. otherVector1.setElement(5, 100);
  110. System.out.println("der Wert des otherVector1 an der Position 5 ist: " + otherVector1.getElement(5)); // 100.0
  111. System.out.println(otherVector1.equals(controlVector));// should be true, weil der Wert an Index 5 von this und
  112. // other Vektor gleich 100
  113. System.out.println("\n");
  114. // testen add()
  115. controlVector.add(otherVector1);
  116. System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10
  117. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 10 + 10 =
  118. // 20
  119. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 100 + 100
  120. // = 200
  121. System.out.println("der Wert des controlVector an der Position 6 ist: " + controlVector.getElement(6)); // 0.0
  122. System.out.println("der Wert des controlVector an der Position 8 ist: " + controlVector.getElement(8)); // 65.01 +
  123. // 65.01 =
  124. // 130.02
  125. System.out.println("der Wert des controlVector an der Position 9 ist: " + controlVector.getElement(9)); // 112.79 +
  126. // 112.79 =
  127. // 225.58
  128. System.out.println("\n");
  129. controlVector.add(otherVector2);
  130. controlVector.setElement(3, 90.1);
  131. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 20
  132. System.out.println("der Wert des controlVector an der Position 3 ist: " + controlVector.getElement(3)); // 90.1
  133. System.out.println("\n");
  134. controlVector.add(otherVector3);
  135. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 20
  136. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200
  137. System.out.println("der Wert des controlVector an der Position 9 ist: " + controlVector.getElement(9)); // 225.58
  138. System.out.println("\n");
  139. controlVector.add(otherVector4);
  140. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0));
  141. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5));
  142. System.out.println("\n");
  143. controlVector.removeElement(0);
  144. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 0.0
  145. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200
  146. System.out.println("\n");
  147. controlVector.add(otherVector5);
  148. System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 0.0
  149. System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200
  150. System.out.println("\n");
  151. }
  152. }