Compare commits
No commits in common. "main" and "main" have entirely different histories.
|
|
@ -1,6 +1,6 @@
|
|||
# String in Großbuchstaben umwandeln
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
* Daten von der Kommandozeile lesen.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Labeled Break
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Ein labeled break verwenden.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Passwortbewertung
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Einfache String-Verarbeitung.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# printf mit Formatstring
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Formatierung mit Formatstrings.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Maximum in einem Array suchen
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Über Arrays iterieren.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Taschenrechner
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
`case` verwenden.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Java-Coding-Standard anwenden
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Java-Code korrekt entsprechend dem [Coding-Standard von Oracle](http://www.oracle.com/technetwork/java/codeconventions-150003.pdf) formatieren.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# JavaDoc schreiben
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Eine vorhandene Klasse mit korrekten JavaDoc-Kommentaren versehen.
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
# Klasse mit JUnit testen
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Einen JUnit-Test für eine gegebene Klasse schreiben.
|
||||
|
||||
## Aufgabe
|
||||
|
||||
Gehen Sie in das Paket [pr2.intro.junit_factorial](../sources/src/main/java/pr2/intro/junit_factorial/).
|
||||
Gehen Sie in das Paket [pr2.intro.junit_faculty](../sources/src/main/java/pr2/intro/junit_faculty/).
|
||||
|
||||
Schreiben Sie bitte einen JUnit-Test für folgende Klasse `Fakultaet`, der die Funktionalität der Methode `fact` testet. Denken Sie insbesondere daran, die Randfälle zu testen.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Lösung: Klasse mit JUnit testen
|
||||
|
||||
|
||||
Gehen Sie in das Paket [pr2.intro.junit_factorials](../../solutions/src/main/java/pr2/intro/junit_factorial/).
|
||||
Gehen Sie in das Paket [pr2.intro.junit_faculty](../../solutions/src/main/java/pr2/intro/junit_faculty/).
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
# Information-Hiding einer Klasse verbessern
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Bei einer vorhandenen Klasse Information Hiding verbessern und Seiteneffekte reduzieren.
|
||||
|
||||
## Aufgabe
|
||||
|
||||
Im Paket [pr2.strukturierung.information_hiding](../sources/src/main/java/pr2/strukturierung/information_hiding/) finden Sie eine Klasse namens `Rechner`, die eine sehr einfachen Taschenrechner repräsentiert. Außerdem finden Sie einen passenden JUnit-Test `RechnerTest`, der die Funktionsweise des Taschenrechners demonstriert -- [pr2.strukturierung.information_hiding.test](../sources/src/test/java/pr2/strukturierung/information_hiding/test/).
|
||||
Im Paket [pr2.strukturierung.information_hiding](../sources/src/main/java/pr2/strukturierung/information_hiding/) finden Sie eine Klasse namens `Rechner`, die eine sehr einfachen Taschenrechner repräsentiert. Außerdem finden Sie einen passenden JUnit-Test `RechnerTest`, der die Funktionsweise des Taschenrechners demonstriert.
|
||||
|
||||
Führen Sie den JUnit-Test aus und vergewissern Sie sich, dass der Taschenrechner korrekt funktioniert.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Vorhandene Bibliotheken als JAR einbinden
|
||||
## Lernziel
|
||||
[Musterlösung](solution/)
|
||||
|
||||
|
||||
|
||||
Eine vorhandene Bibliothek in einem Projekt verwenden und hierzu ein JAR einbinden.
|
||||
|
|
|
|||
222
readme.md
222
readme.md
|
|
@ -10,114 +10,114 @@ Hier finden Sie die **freiwilligen Übungen** zur Vorlesung Programmieren 2 (PR2
|
|||
|
||||
Hinweise zur nötigen Softwareausstattung finden Sie [hier](help/softwareausstattung.md).
|
||||
|
||||
| # | Kapitel | Thema | Musterlösung |
|
||||
|-----|-----------------------|---------------------------------------------------------------------------------------------------|----------------|
|
||||
| 1. | Auffrischung | [String in Großbuchstaben umwandeln](Auffrischung_001/readme.md) | [✅](Auffrischung_001/solution/) |
|
||||
| 2. | Auffrischung | [Labeled Break](Auffrischung_002/readme.md) | [✅](Auffrischung_002/solution/) |
|
||||
| 3. | Auffrischung | [Passwortbewertung](Auffrischung_003/readme.md) | [✅](Auffrischung_003/solution/) |
|
||||
| 4. | Auffrischung | [printf mit Formatstring](Auffrischung_004/readme.md) | [✅](Auffrischung_004/solution/) |
|
||||
| 5. | Auffrischung | [Maximum in einem Array suchen](Auffrischung_005/readme.md) | [✅](Auffrischung_005/solution/) |
|
||||
| 6. | Auffrischung | [Taschenrechner](Auffrischung_006/readme.md) | [✅](Auffrischung_006/solution/) |
|
||||
| 7. | Einführung | [Java-Coding-Standard anwenden](Einfuehrung_001/readme.md) | [✅](Einfuehrung_001/solution/) |
|
||||
| 8. | Einführung | [JavaDoc schreiben](Einfuehrung_002/readme.md) | [✅](Einfuehrung_002/solution/) |
|
||||
| 9. | Einführung | [Klasse mit JUnit testen](Einfuehrung_003/readme.md) | [✅](Einfuehrung_003/solution/) |
|
||||
| 10. | Strukturierung | [Information-Hiding einer Klasse verbessern](Strukturierung_001/readme.md) | [✅](Strukturierung_001/solution/) |
|
||||
| 11. | Strukturierung | [Vorhandene Bibliotheken als JAR einbinden](Strukturierung_002/readme.md) | [✅](Strukturierung_002/solution/) |
|
||||
| 12. | Vererbung | [Final anwenden](Vererbung_001/readme.md) | |
|
||||
| 13. | Vererbung | [Figur und Rechteck](Vererbung_002/readme.md) | |
|
||||
| 14. | Vererbung | [Figur erweitern](Vererbung_003/readme.md) | |
|
||||
| 15. | Vererbung | [Figur noch einmal erweitern](Vererbung_004/readme.md) | |
|
||||
| 16. | Vererbung | [Konstruktoren schreiben](Vererbung_005/readme.md) | |
|
||||
| 17. | Vererbung | [Polymorphie einsetzen](Vererbung_006/readme.md) | |
|
||||
| 18. | Vererbung | [Singleton](Vererbung_007/readme.md) | |
|
||||
| 19. | Vererbung | [Statische Methoden und Attribute](Vererbung_008/readme.md) | |
|
||||
| 20. | Vererbung | [Methode überladen](Vererbung_009/readme.md) | |
|
||||
| 21. | Vererbung | [Methoden überschreiben](Vererbung_010/readme.md) | |
|
||||
| 22. | Vererbung | [Varag-Methode schreiben](Vererbung_011/readme.md) | |
|
||||
| 23. | Vererbung | [Vererbung von Figuren](Vererbung_012/readme.md) | |
|
||||
| 24. | Abstrakte Klassen | [Abstrakte Klassen](Abstrakte_Klassen_001/readme.md) | |
|
||||
| 25. | Abstrakte Klassen | [Abstrakte Klasse](Abstrakte_Klassen_002/readme.md) | |
|
||||
| 26. | Interfaces | [Comparable implementieren](Interfaces_001/readme.md) | |
|
||||
| 27. | Interfaces | [Interface Stack entwerfen](Interfaces_002/readme.md) | |
|
||||
| 28. | Interfaces | [Interface: Uebersetzer](Interfaces_003/readme.md) | |
|
||||
| 29. | Interfaces | [Interfaces anwenden und entwerfen](Interfaces_004/readme.md) | |
|
||||
| 30. | Object und Wrapper | [Deep-Copy mit `clone()`](Object_und_Wrapper_001/readme.md) | |
|
||||
| 31. | Object und Wrapper | [Clone](Object_und_Wrapper_002/readme.md) | |
|
||||
| 32. | Object und Wrapper | [`equals()` und `hashCode()` implementieren und nutzen](Object_und_Wrapper_003/readme.md) | |
|
||||
| 33. | Object und Wrapper | [equals und hashCode](Object_und_Wrapper_004/readme.md) | |
|
||||
| 34. | Object und Wrapper | [`toString()`-Methode implementieren](Object_und_Wrapper_005/readme.md) | |
|
||||
| 35. | Object und Wrapper | [Optimierung bei Integer](Object_und_Wrapper_006/readme.md) | |
|
||||
| 36. | Object und Wrapper | [Methoden der Wrapper-Klassen](Object_und_Wrapper_007/readme.md) | |
|
||||
| 37. | Enumerationen | [Eigene Enumeration schreiben und verwenden](Enumerationen_001/readme.md) | |
|
||||
| 38. | Enumerationen | [Enumeration schreiben](Enumerationen_002/readme.md) | |
|
||||
| 39. | Enumerationen | [Singleton-Eigenschaft von Enumerationen](Enumerationen_003/readme.md) | |
|
||||
| 40. | Enumerationen | [Stein, Papier, Schere, Echse, Spock](Enumerationen_004/readme.md) | |
|
||||
| 41. | Ausnahmen | [Ausnahmen testen](Ausnahmen_001/readme.md) | |
|
||||
| 42. | Ausnahmen | [Eigene Ausnahmen schreiben und an entsprechender Stelle werfen](Ausnahmen_002/readme.md) | |
|
||||
| 43. | Ausnahmen | [Eigene Exception schreiben](Ausnahmen_003/readme.md) | |
|
||||
| 44. | Ausnahmen | [Handle-or-Declare-Regel anwenden](Ausnahmen_004/readme.md) | |
|
||||
| 45. | Ausnahmen | [Ausnahmen mit `try` und `catch` behandeln.](Ausnahmen_005/readme.md) | |
|
||||
| 46. | Input und Output | [`BufferedReader` zum zeilenweisen Lesen einsetzen](Input_und_Output_001/readme.md) | |
|
||||
| 47. | Input und Output | [DataOutputStream](Input_und_Output_002/readme.md) | |
|
||||
| 48. | Input und Output | [DataOutputStream durch Serialisierung ersetzen](Input_und_Output_003/readme.md) | |
|
||||
| 49. | Input und Output | [Daten mit `DataOutputStream` und `DataInputStream` verarbeiten](Input_und_Output_004/readme.md) | |
|
||||
| 50. | Input und Output | [Daten mit einem `InputStream` lesen](Input_und_Output_005/readme.md) | |
|
||||
| 51. | Input und Output | [Daten mit einem `OutputStream` schreiben](Input_und_Output_006/readme.md) | |
|
||||
| 52. | Input und Output | [Filesystem-Abstraktion mit `File`](Input_und_Output_007/readme.md) | |
|
||||
| 53. | Input und Output | [Fileattribute lesen](Input_und_Output_008/readme.md) | |
|
||||
| 54. | Input und Output | [`FilterReader`](Input_und_Output_009/readme.md) | |
|
||||
| 55. | Input und Output | [Konsolen Input/Output](Input_und_Output_010/readme.md) | |
|
||||
| 56. | Input und Output | [Zeilen einer Textdatei zählen](Input_und_Output_011/readme.md) | |
|
||||
| 57. | Input und Output | [`RandomAccessFile`](Input_und_Output_012/readme.md) | |
|
||||
| 58. | Input und Output | [`Reader` verwenden](Input_und_Output_013/readme.md) | |
|
||||
| 59. | Input und Output | [Rot13-Verschlüsselung](Input_und_Output_014/readme.md) | |
|
||||
| 60. | Input und Output | [Datei zerhacken](Input_und_Output_015/readme.md) | |
|
||||
| 61. | Input und Output | [Serialisierung](Input_und_Output_016/readme.md) | |
|
||||
| 62. | Generische Typen | [Einen generischen Typ schreiben](Generische_Typen_001/readme.md) | |
|
||||
| 63. | Generische Typen | [Generische Klasse Pair schreiben](Generische_Typen_002/readme.md) | |
|
||||
| 64. | Generische Typen | [Generische Klasse Pair erweitern: NumberPair](Generische_Typen_003/readme.md) | |
|
||||
| 65. | Generische Typen | [Generische Klasse Pair erweitern: SamePair](Generische_Typen_004/readme.md) | |
|
||||
| 66. | Generische Typen | [PairList](Generische_Typen_005/readme.md) | |
|
||||
| 67. | Generische Typen | [Wildcard benutzen](Generische_Typen_006/readme.md) | |
|
||||
| 68. | Generische Typen | [Generische Queue](Generische_Typen_007/readme.md) | |
|
||||
| 69. | Generische Typen | [`super` und `extends` einsetzen](Generische_Typen_008/readme.md) | |
|
||||
| 70. | Generische Typen | [Generische Typen zusammen mit Wildcards einsetzen](Generische_Typen_009/readme.md) | |
|
||||
| 71. | Geschachtelte Klassen | [Eigene compare-Methode schreiben](Geschachtelte_Klassen_001/readme.md) | |
|
||||
| 72. | Geschachtelte Klassen | [Innere Klasse Beobachter](Geschachtelte_Klassen_002/readme.md) | |
|
||||
| 73. | Geschachtelte Klassen | [Callback mit anonymer Klasse realisieren](Geschachtelte_Klassen_003/readme.md) | |
|
||||
| 74. | Lambdas | [Comparator als Lambda](Lambdas_001/readme.md) | |
|
||||
| 75. | Lambdas | [Callback mit Lambda realisieren](Lambdas_002/readme.md) | |
|
||||
| 76. | Geschachtelte Klassen | [MatrixSuche](Geschachtelte_Klassen_001/readme.md) | |
|
||||
| 77. | Lambdas | [StringTransmogrifier](Lambdas_001/readme.md) | |
|
||||
| 78. | Lambdas | [StringTransmogrifier erweitern](Lambdas_002/readme.md) | |
|
||||
| 79. | Collections | [Iterator schreiben](Collections_001/readme.md) | |
|
||||
| 80. | Collections | [Iterator programmieren](Collections_002/readme.md) | |
|
||||
| 81. | Collections | [`List<T>` und dessen Implementierungen](Collections_003/readme.md) | |
|
||||
| 82. | Collections | [`Map<T>` verwenden](Collections_004/readme.md) | |
|
||||
| 83. | Collections | [ReverserGeneric](Collections_005/readme.md) | |
|
||||
| 84. | Collections | [Strings umgekehrt sortieren: Reverser](Collections_006/readme.md) | |
|
||||
| 85. | Collections | [`Set<T>` und dessen Implementierungen](Collections_007/readme.md) | |
|
||||
| 86. | Collections | [CommandLineSorter](Collections_008/readme.md) | |
|
||||
| 87. | Collections | [CommandLineSorter -- Version 2](Collections_009/readme.md) | |
|
||||
| 88. | Collections | [`Comparator<T>` verwenden und Objekte sortieren](Collections_010/readme.md) | |
|
||||
| 89. | Collections | [Wörterbuchprogramm](Collections_011/readme.md) | |
|
||||
| 90. | Streams | [Kleinbuchstaben in einem String zählen](Streams_001/readme.md) | |
|
||||
| 91. | Streams | [Buchstaben in einer Liste von Strings zählen](Streams_002/readme.md) | |
|
||||
| 92. | Streams | [Kleinbuchstaben in einem String zählen](Streams_003/readme.md) | |
|
||||
| 93. | Streams | [Liste filtern](Streams_004/readme.md) | |
|
||||
| 94. | Streams | [Streams mit interner Iteration](Streams_005/readme.md) | |
|
||||
| 95. | Streams | [Map und Filter auf Streams](Streams_006/readme.md) | |
|
||||
| 96. | Streams | [Map und Reduce auf Streams](Streams_007/readme.md) | |
|
||||
| 97. | Streams | [Reduce](Streams_008/readme.md) | |
|
||||
| 98. | Streams | [Summe über reduce bestimmen](Streams_009/readme.md) | |
|
||||
| 99. | Streams | [Wörter zählen](Streams_010/readme.md) | |
|
||||
| 100. | Threads | [Fakultät parallel berechnen](Threads_001/readme.md) | |
|
||||
| 101. | Threads | [Thread per interrupt beenden](Threads_002/readme.md) | |
|
||||
| 102. | Threads | [wait und notify benutzen](Threads_003/readme.md) | |
|
||||
| 103. | Threads | [Parallele Ausgaben erzeugen](Threads_004/readme.md) | |
|
||||
| 104. | Threads | [Race-Condition finden und beheben](Threads_005/readme.md) | |
|
||||
| 105. | Threads | [Stack und Heap unterscheiden](Threads_006/readme.md) | |
|
||||
| 106. | Threads | [synchronized verwenden](Threads_007/readme.md) | |
|
||||
| 107. | Threads | [Timer und TimerTask verwenden](Threads_008/readme.md) | |
|
||||
| 108. | Reflection | [Klasse per Reflection analysieren](Reflection_001/readme.md) | |
|
||||
| 109. | Reflection | [Objekte per Reflection erzeugen](Reflection_002/readme.md) | |
|
||||
| # | Kapitel | Thema |
|
||||
|-----|-----------------------|---------------------------------------------------------------------------------------------------|
|
||||
| 1. | Auffrischung | [String in Großbuchstaben umwandeln](Auffrischung_001/readme.md) |
|
||||
| 2. | Auffrischung | [Labeled Break](Auffrischung_002/readme.md) |
|
||||
| 3. | Auffrischung | [Passwortbewertung](Auffrischung_003/readme.md) |
|
||||
| 4. | Auffrischung | [printf mit Formatstring](Auffrischung_004/readme.md) |
|
||||
| 5. | Auffrischung | [Maximum in einem Array suchen](Auffrischung_005/readme.md) |
|
||||
| 6. | Auffrischung | [Taschenrechner](Auffrischung_006/readme.md) |
|
||||
| 7. | Einführung | [Java-Coding-Standard anwenden](Einfuehrung_001/readme.md) |
|
||||
| 8. | Einführung | [JavaDoc schreiben](Einfuehrung_002/readme.md) |
|
||||
| 9. | Einführung | [Klasse mit JUnit testen](Einfuehrung_003/readme.md) |
|
||||
| 10. | Strukturierung | [Information-Hiding einer Klasse verbessern](Strukturierung_001/readme.md) |
|
||||
| 11. | Strukturierung | [Vorhandene Bibliotheken als JAR einbinden](Strukturierung_002/readme.md) |
|
||||
| 12. | Vererbung | [Final anwenden](Vererbung_001/readme.md) |
|
||||
| 13. | Vererbung | [Figur und Rechteck](Vererbung_002/readme.md) |
|
||||
| 14. | Vererbung | [Figur erweitern](Vererbung_003/readme.md) |
|
||||
| 15. | Vererbung | [Figur noch einmal erweitern](Vererbung_004/readme.md) |
|
||||
| 16. | Vererbung | [Konstruktoren schreiben](Vererbung_005/readme.md) |
|
||||
| 17. | Vererbung | [Polymorphie einsetzen](Vererbung_006/readme.md) |
|
||||
| 18. | Vererbung | [Singleton](Vererbung_007/readme.md) |
|
||||
| 19. | Vererbung | [Statische Methoden und Attribute](Vererbung_008/readme.md) |
|
||||
| 20. | Vererbung | [Methode überladen](Vererbung_009/readme.md) |
|
||||
| 21. | Vererbung | [Methoden überschreiben](Vererbung_010/readme.md) |
|
||||
| 22. | Vererbung | [Varag-Methode schreiben](Vererbung_011/readme.md) |
|
||||
| 23. | Vererbung | [Vererbung von Figuren](Vererbung_012/readme.md) |
|
||||
| 24. | Abstrakte Klassen | [Abstrakte Klassen](Abstrakte_Klassen_001/readme.md) |
|
||||
| 25. | Abstrakte Klassen | [Abstrakte Klasse](Abstrakte_Klassen_002/readme.md) |
|
||||
| 26. | Interfaces | [Comparable implementieren](Interfaces_001/readme.md) |
|
||||
| 27. | Interfaces | [Interface Stack entwerfen](Interfaces_002/readme.md) |
|
||||
| 28. | Interfaces | [Interface: Uebersetzer](Interfaces_003/readme.md) |
|
||||
| 29. | Interfaces | [Interfaces anwenden und entwerfen](Interfaces_004/readme.md) |
|
||||
| 30. | Object und Wrapper | [Deep-Copy mit `clone()`](Object_und_Wrapper_001/readme.md) |
|
||||
| 31. | Object und Wrapper | [Clone](Object_und_Wrapper_002/readme.md) |
|
||||
| 32. | Object und Wrapper | [`equals()` und `hashCode()` implementieren und nutzen](Object_und_Wrapper_003/readme.md) |
|
||||
| 33. | Object und Wrapper | [equals und hashCode](Object_und_Wrapper_004/readme.md) |
|
||||
| 34. | Object und Wrapper | [`toString()`-Methode implementieren](Object_und_Wrapper_005/readme.md) |
|
||||
| 35. | Object und Wrapper | [Optimierung bei Integer](Object_und_Wrapper_006/readme.md) |
|
||||
| 36. | Object und Wrapper | [Methoden der Wrapper-Klassen](Object_und_Wrapper_007/readme.md) |
|
||||
| 37. | Enumerationen | [Eigene Enumeration schreiben und verwenden](Enumerationen_001/readme.md) |
|
||||
| 38. | Enumerationen | [Enumeration schreiben](Enumerationen_002/readme.md) |
|
||||
| 39. | Enumerationen | [Singleton-Eigenschaft von Enumerationen](Enumerationen_003/readme.md) |
|
||||
| 40. | Enumerationen | [Stein, Papier, Schere, Echse, Spock](Enumerationen_004/readme.md) |
|
||||
| 41. | Ausnahmen | [Ausnahmen testen](Ausnahmen_001/readme.md) |
|
||||
| 42. | Ausnahmen | [Eigene Ausnahmen schreiben und an entsprechender Stelle werfen](Ausnahmen_002/readme.md) |
|
||||
| 43. | Ausnahmen | [Eigene Exception schreiben](Ausnahmen_003/readme.md) |
|
||||
| 44. | Ausnahmen | [Handle-or-Declare-Regel anwenden](Ausnahmen_004/readme.md) |
|
||||
| 45. | Ausnahmen | [Ausnahmen mit `try` und `catch` behandeln.](Ausnahmen_005/readme.md) |
|
||||
| 46. | Input und Output | [`BufferedReader` zum zeilenweisen Lesen einsetzen](Input_und_Output_001/readme.md) |
|
||||
| 47. | Input und Output | [DataOutputStream](Input_und_Output_002/readme.md) |
|
||||
| 48. | Input und Output | [DataOutputStream durch Serialisierung ersetzen](Input_und_Output_003/readme.md) |
|
||||
| 49. | Input und Output | [Daten mit `DataOutputStream` und `DataInputStream` verarbeiten](Input_und_Output_004/readme.md) |
|
||||
| 50. | Input und Output | [Daten mit einem `InputStream` lesen](Input_und_Output_005/readme.md) |
|
||||
| 51. | Input und Output | [Daten mit einem `OutputStream` schreiben](Input_und_Output_006/readme.md) |
|
||||
| 52. | Input und Output | [Filesystem-Abstraktion mit `File`](Input_und_Output_007/readme.md) |
|
||||
| 53. | Input und Output | [Fileattribute lesen](Input_und_Output_008/readme.md) |
|
||||
| 54. | Input und Output | [`FilterReader`](Input_und_Output_009/readme.md) |
|
||||
| 55. | Input und Output | [Konsolen Input/Output](Input_und_Output_010/readme.md) |
|
||||
| 56. | Input und Output | [Zeilen einer Textdatei zählen](Input_und_Output_011/readme.md) |
|
||||
| 57. | Input und Output | [`RandomAccessFile`](Input_und_Output_012/readme.md) |
|
||||
| 58. | Input und Output | [`Reader` verwenden](Input_und_Output_013/readme.md) |
|
||||
| 59. | Input und Output | [Rot13-Verschlüsselung](Input_und_Output_014/readme.md) |
|
||||
| 60. | Input und Output | [Datei zerhacken](Input_und_Output_015/readme.md) |
|
||||
| 61. | Input und Output | [Serialisierung](Input_und_Output_016/readme.md) |
|
||||
| 62. | Generische Typen | [Einen generischen Typ schreiben](Generische_Typen_001/readme.md) |
|
||||
| 63. | Generische Typen | [Generische Klasse Pair schreiben](Generische_Typen_002/readme.md) |
|
||||
| 64. | Generische Typen | [Generische Klasse Pair erweitern: NumberPair](Generische_Typen_003/readme.md) |
|
||||
| 65. | Generische Typen | [Generische Klasse Pair erweitern: SamePair](Generische_Typen_004/readme.md) |
|
||||
| 66. | Generische Typen | [PairList](Generische_Typen_005/readme.md) |
|
||||
| 67. | Generische Typen | [Wildcard benutzen](Generische_Typen_006/readme.md) |
|
||||
| 68. | Generische Typen | [Generische Queue](Generische_Typen_007/readme.md) |
|
||||
| 69. | Generische Typen | [`super` und `extends` einsetzen](Generische_Typen_008/readme.md) |
|
||||
| 70. | Generische Typen | [Generische Typen zusammen mit Wildcards einsetzen](Generische_Typen_009/readme.md) |
|
||||
| 71. | Geschachtelte Klassen | [Eigene compare-Methode schreiben](Geschachtelte_Klassen_001/readme.md) |
|
||||
| 72. | Geschachtelte Klassen | [Innere Klasse Beobachter](Geschachtelte_Klassen_002/readme.md) |
|
||||
| 73. | Geschachtelte Klassen | [Callback mit anonymer Klasse realisieren](Geschachtelte_Klassen_003/readme.md) |
|
||||
| 74. | Lambdas | [Comparator als Lambda](Lambdas_001/readme.md) |
|
||||
| 75. | Lambdas | [Callback mit Lambda realisieren](Lambdas_002/readme.md) |
|
||||
| 76. | Geschachtelte Klassen | [MatrixSuche](Geschachtelte_Klassen_001/readme.md) |
|
||||
| 77. | Lambdas | [StringTransmogrifier](Lambdas_001/readme.md) |
|
||||
| 78. | Lambdas | [StringTransmogrifier erweitern](Lambdas_002/readme.md) |
|
||||
| 79. | Collections | [Iterator schreiben](Collections_001/readme.md) |
|
||||
| 80. | Collections | [Iterator programmieren](Collections_002/readme.md) |
|
||||
| 81. | Collections | [`List<T>` und dessen Implementierungen](Collections_003/readme.md) |
|
||||
| 82. | Collections | [`Map<T>` verwenden](Collections_004/readme.md) |
|
||||
| 83. | Collections | [ReverserGeneric](Collections_005/readme.md) |
|
||||
| 84. | Collections | [Strings umgekehrt sortieren: Reverser](Collections_006/readme.md) |
|
||||
| 85. | Collections | [`Set<T>` und dessen Implementierungen](Collections_007/readme.md) |
|
||||
| 86. | Collections | [CommandLineSorter](Collections_008/readme.md) |
|
||||
| 87. | Collections | [CommandLineSorter -- Version 2](Collections_009/readme.md) |
|
||||
| 88. | Collections | [`Comparator<T>` verwenden und Objekte sortieren](Collections_010/readme.md) |
|
||||
| 89. | Collections | [Wörterbuchprogramm](Collections_011/readme.md) |
|
||||
| 90. | Streams | [Kleinbuchstaben in einem String zählen](Streams_001/readme.md) |
|
||||
| 91. | Streams | [Buchstaben in einer Liste von Strings zählen](Streams_002/readme.md) |
|
||||
| 92. | Streams | [Kleinbuchstaben in einem String zählen](Streams_003/readme.md) |
|
||||
| 93. | Streams | [Liste filtern](Streams_004/readme.md) |
|
||||
| 94. | Streams | [Streams mit interner Iteration](Streams_005/readme.md) |
|
||||
| 95. | Streams | [Map und Filter auf Streams](Streams_006/readme.md) |
|
||||
| 96. | Streams | [Map und Reduce auf Streams](Streams_007/readme.md) |
|
||||
| 97. | Streams | [Reduce](Streams_008/readme.md) |
|
||||
| 98. | Streams | [Summe über reduce bestimmen](Streams_009/readme.md) |
|
||||
| 99. | Streams | [Wörter zählen](Streams_010/readme.md) |
|
||||
| 100. | Threads | [Fakultät parallel berechnen](Threads_001/readme.md) |
|
||||
| 101. | Threads | [Thread per interrupt beenden](Threads_002/readme.md) |
|
||||
| 102. | Threads | [wait und notify benutzen](Threads_003/readme.md) |
|
||||
| 103. | Threads | [Parallele Ausgaben erzeugen](Threads_004/readme.md) |
|
||||
| 104. | Threads | [Race-Condition finden und beheben](Threads_005/readme.md) |
|
||||
| 105. | Threads | [Stack und Heap unterscheiden](Threads_006/readme.md) |
|
||||
| 106. | Threads | [synchronized verwenden](Threads_007/readme.md) |
|
||||
| 107. | Threads | [Timer und TimerTask verwenden](Threads_008/readme.md) |
|
||||
| 108. | Reflection | [Klasse per Reflection analysieren](Reflection_001/readme.md) |
|
||||
| 109. | Reflection | [Objekte per Reflection erzeugen](Reflection_002/readme.md) |
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
package pr2.auffrischung.grossmacher;
|
||||
|
||||
public class Grossmacher {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
System.err.println("Kein Argument angeben!");
|
||||
return;
|
||||
}
|
||||
|
||||
String ergebnis = args[0].toUpperCase();
|
||||
|
||||
System.out.printf("Ergebnis: %s%n", ergebnis);
|
||||
System.out.printf("Zeichen : %d%n", ergebnis.length());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package pr2.auffrischung.labeled_break;
|
||||
|
||||
public class ArraySucher {
|
||||
|
||||
/**
|
||||
* Sucht das erste Element, dass nicht 0 ist.
|
||||
*
|
||||
* @param array das Array in dem gesucht werden soll
|
||||
* @return {@code true}, wenn ein Element gefunden wird,
|
||||
* andernfalls {@code false}.
|
||||
*/
|
||||
public boolean suche(int[][] array) {
|
||||
boolean found = false;
|
||||
|
||||
outer:
|
||||
for (int[] is : array) {
|
||||
for (int i : is) {
|
||||
if (i != 0) {
|
||||
found = true;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package pr2.auffrischung.password;
|
||||
|
||||
public class PasswortChecker {
|
||||
|
||||
private static final char[] NUMBERS = "1234567890".toCharArray();
|
||||
private static final char[] LOWERCASE
|
||||
= "abcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||
private static final char[] UPPERCASE
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
|
||||
private static final char[] SPECIAL_CHARS = "!%()\"".toCharArray();
|
||||
|
||||
private static boolean contains(String string, char[] chars) {
|
||||
for (char c : chars) {
|
||||
if (string.indexOf(c) >= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int checkPassword(String password) {
|
||||
int points = 0;
|
||||
|
||||
if (password.length() >= 8) {
|
||||
points++;
|
||||
}
|
||||
|
||||
if (contains(password, NUMBERS)
|
||||
&& (contains(password, LOWERCASE)
|
||||
|| contains(password, UPPERCASE))) {
|
||||
points++;
|
||||
}
|
||||
|
||||
if (contains(password, SPECIAL_CHARS)) {
|
||||
points++;
|
||||
}
|
||||
|
||||
if (contains(password, LOWERCASE) && contains(password, UPPERCASE)) {
|
||||
points++;
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(checkPassword("mutti"));
|
||||
System.out.println(checkPassword("Mutti"));
|
||||
System.out.println(checkPassword("mutti123"));
|
||||
System.out.println(checkPassword("Mutti123"));
|
||||
System.out.println(checkPassword("Mutti123!%"));
|
||||
System.out.println(checkPassword("1234"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package pr2.auffrischung.printf;
|
||||
|
||||
public class DoubleFormatter {
|
||||
|
||||
public static void printDouble(double d) {
|
||||
System.out.printf("%.3f%n", d);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
printDouble(1.0);
|
||||
printDouble(10.1);
|
||||
printDouble(2.01);
|
||||
printDouble(2.001);
|
||||
printDouble(2.0001);
|
||||
printDouble(2.0004);
|
||||
printDouble(2.0005);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package pr2.auffrischung.suchemax;
|
||||
|
||||
public class GroessteZahl {
|
||||
|
||||
public int sucheMax(int[] zahlen) {
|
||||
int max = Integer.MIN_VALUE;
|
||||
|
||||
for (int zahl : zahlen) {
|
||||
max = Math.max(max, zahl);
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GroessteZahl g = new GroessteZahl();
|
||||
System.out.println(g.sucheMax(new int[] {1, 5, 8, 2, 0}));
|
||||
System.out.println(g.sucheMax(new int[] {-1, -5, -8, -2, -20}));
|
||||
System.out.println(g.sucheMax(new int[] {10000, -10000, 1, 2, 33}));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package pr2.auffrischung.taschenrechner;
|
||||
|
||||
public class Taschenrechner {
|
||||
|
||||
public double rechne(double o1, char op, double o2) {
|
||||
return switch (op) {
|
||||
case '+' -> o1 + o2;
|
||||
case '-' -> o1 - o2;
|
||||
case '*' -> o1 * o2;
|
||||
case '/' -> o1 / o2;
|
||||
case '^' -> Math.pow(o1, o2);
|
||||
default -> Double.NaN;
|
||||
};
|
||||
// return 0.0;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Taschenrechner t = new Taschenrechner();
|
||||
System.out.println(t.rechne(1, '+', 2));
|
||||
System.out.println(t.rechne(1, '-', 2));
|
||||
System.out.println(t.rechne(2, '*', 2));
|
||||
System.out.println(t.rechne(4, '/', 2));
|
||||
System.out.println(t.rechne(2, '^', 32));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
package pr2.intro.coding_standard;
|
||||
|
||||
/**
|
||||
* Klasse dient als Beispiel für den Coding-Standard und die Namenskonventionen
|
||||
* bei Java-Programmen.
|
||||
*/
|
||||
@SuppressWarnings("PMD.UnusedPrivateField")
|
||||
public class CodingStandard {
|
||||
|
||||
/**
|
||||
* Konstante, die dem Rest der Welt etwas mitteilen soll.
|
||||
*/
|
||||
public static final int KONSTANTE_MIT_TOLLEM_WERT = 3;
|
||||
|
||||
private int erstesFeld;
|
||||
|
||||
private double zweitesFeld;
|
||||
|
||||
/**
|
||||
* Legt eine neue Instanz an.
|
||||
*
|
||||
* @param erstesFeld das erste Feld.
|
||||
* @param zweitesFeld das zweite Feld.
|
||||
*/
|
||||
public CodingStandard(int erstesFeld, double zweitesFeld) {
|
||||
this.erstesFeld = erstesFeld;
|
||||
this.zweitesFeld = zweitesFeld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode, die etwas tut.
|
||||
*
|
||||
* @param parameter Eingabewert für die Methode.
|
||||
* @return gibt einen Wert abhängig von {@code parameter} zurück.
|
||||
*/
|
||||
public int methodeDieWasTut(int parameter) {
|
||||
|
||||
int result;
|
||||
|
||||
if (parameter > KONSTANTE_MIT_TOLLEM_WERT) {
|
||||
result = 12;
|
||||
}
|
||||
else {
|
||||
result = 13;
|
||||
}
|
||||
|
||||
erstesFeld = result;
|
||||
zweitesFeld = 2 * result;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
package pr2.intro.javadoc;
|
||||
|
||||
/**
|
||||
* Objekte dieser Klasse repräsentieren eine Währung. Eine Währung zeichnet
|
||||
* sich durch einen Namen (z.B. EURO), ein Kürzel (z.B. € oder EUR) und einen
|
||||
* Umrechnungskurs zum US-Dollar aus.
|
||||
* <p>
|
||||
* Objekte dieser Klasse sind imutable, d.h. sie können nach der Erzeugung
|
||||
* nicht mehr verändert werden.
|
||||
*/
|
||||
public class Waehrung {
|
||||
|
||||
/**
|
||||
* Teiler für die Nachkommastellen.
|
||||
*/
|
||||
private static final long TEILER = 10000;
|
||||
|
||||
/**
|
||||
* Umrechnungskurs zum Dollar.
|
||||
*/
|
||||
private final int kurs;
|
||||
|
||||
/**
|
||||
* Langer Name der Währung.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Abkürzung zur Währung.
|
||||
*/
|
||||
private final String kuerzel;
|
||||
|
||||
/**
|
||||
* Erzeugt ein neues Objekt.
|
||||
*
|
||||
* @param name Name der Währung (z.B. EURO).
|
||||
* @param kuerzel Kürzel der Währung (z.B. €).
|
||||
* @param kurs Wechselkurs zum Dollar.
|
||||
*/
|
||||
public Waehrung(String name, String kuerzel, double kurs) {
|
||||
this.kurs = (int) (kurs * TEILER);
|
||||
this.name = name;
|
||||
this.kuerzel = kuerzel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rechnet einen Berag in der aktuellen Währung in eine andere Währung
|
||||
* um.
|
||||
*
|
||||
* @param betrag Betrag der umgerechnet werden soll.
|
||||
* @param toWaehrung die Zielwährung.
|
||||
* @return Ergebnis der Umrechnung.
|
||||
*/
|
||||
public long umrechnen(long betrag, Waehrung toWaehrung) {
|
||||
return betrag * kurs / toWaehrung.kurs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Kurs der aktuellen Währung zurück.
|
||||
*
|
||||
* @return Wechselkurs bezogen auf den US-Dollar.
|
||||
*/
|
||||
public int getKurs() {
|
||||
return kurs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Namen der Währung zurück.
|
||||
*
|
||||
* @return Name der Währung (z.B. Euro oder Dollar).
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt das Kürzel für die Währung zurück.
|
||||
*
|
||||
* @return Das Kürzel der Währung (z.B. EUR oder $)
|
||||
*/
|
||||
public String getKuerzel() {
|
||||
return kuerzel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s [%s] 1 %s = %.4f %s", name, kuerzel, "$",
|
||||
kurs / (double) TEILER, kuerzel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + kurs;
|
||||
result = prime * result + ((kuerzel == null) ? 0 : kuerzel.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Waehrung other = (Waehrung) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
if (kurs != other.kurs) {
|
||||
return false;
|
||||
}
|
||||
if (kuerzel == null) {
|
||||
return other.kuerzel == null;
|
||||
}
|
||||
else {
|
||||
return kuerzel.equals(other.kuerzel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package pr2.strukturierung.information_hiding;
|
||||
|
||||
/**
|
||||
* Ein einfacher Taschenrechner.
|
||||
*/
|
||||
public class Rechner {
|
||||
|
||||
/** Speicher des Taschenrechners. */
|
||||
private double speicher;
|
||||
|
||||
/**
|
||||
* Addiert zwei Werte und gibt das Ergebnis zurück.
|
||||
*
|
||||
* @param a erster Operand.
|
||||
* @param b zweiter Operand.
|
||||
* @return das Ergebnis.
|
||||
*/
|
||||
public double addiere(double a, double b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtrahiert zwei Werte und gibt das Ergebnis zurück.
|
||||
*
|
||||
* @param a erster Operand.
|
||||
* @param b zweiter Operand.
|
||||
* @return das Ergebnis.
|
||||
*/
|
||||
public double subtrahiere(double a, double b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multipliziert zwei Werte und gibt das Ergebnis zurück.
|
||||
*
|
||||
* @param a erster Operand.
|
||||
* @param b zweiter Operand.
|
||||
* @return das Ergebnis.
|
||||
*/
|
||||
public double multipliziere(double a, double b) {
|
||||
return a * b;
|
||||
}
|
||||
/**
|
||||
* Gibt den gespeicherten Wert zurück.
|
||||
*
|
||||
* @return gespeicherter Wert.
|
||||
*/
|
||||
public double getSpeicher() {
|
||||
return speicher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert den gegebenen Wert.
|
||||
*
|
||||
* @param wert Wert, der gespeichert werden soll.
|
||||
*/
|
||||
public void setSpeicher(double wert) {
|
||||
speicher = wert;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package pr2.auffrischung.grossmacher;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class GrossmacherTest {
|
||||
|
||||
private static PrintStream out;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
out = System.out;
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDown() {
|
||||
System.setOut(out);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = { "alles klein", "ALLES GROSS", "gemIschT" })
|
||||
void testMain(String text) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
PrintStream ps = new PrintStream(bos);
|
||||
System.setOut(ps);
|
||||
|
||||
Grossmacher.main(new String[] { text });
|
||||
String result = String.format("Ergebnis: %s\nZeichen : %d",
|
||||
text.toUpperCase(),
|
||||
text.length());
|
||||
|
||||
assertEquals(result, bos.toString().trim());
|
||||
bos.close();
|
||||
// Don't close ps!
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package pr2.auffrischung.labeled_break;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class ArraySucherTest {
|
||||
|
||||
final int[][] EMPTY = {{}};
|
||||
final int[][] ZERO = { { 0, 0, 0 }, { 0, 0, 0 }};
|
||||
final int[][] END = { { 0, 0, 0 }, { 0, 0, 1 }};
|
||||
final int[][] BEGINNING = { { 1, 0, 0 }, { 0, 0, 0 }};
|
||||
final int[][] ONE = { { 1, 1, 1 }, { 1, 1, 1 }};
|
||||
final int[][] TRIANGLE = { { 0, 0 }, { 0, 0 }, { 0, 0, 0 }, { 0, 0, 0, 1 } };
|
||||
|
||||
|
||||
@Test
|
||||
void testSuche() {
|
||||
var as = new ArraySucher();
|
||||
assertFalse(as.suche(EMPTY));
|
||||
assertFalse(as.suche(ZERO));
|
||||
assertTrue(as.suche(END));
|
||||
assertTrue(as.suche(BEGINNING));
|
||||
assertTrue(as.suche(ONE));
|
||||
assertTrue(as.suche(TRIANGLE));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package pr2.auffrischung.password;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static pr2.auffrischung.password.PasswortChecker.checkPassword;
|
||||
|
||||
public class PasswortCheckerTest {
|
||||
|
||||
@Test
|
||||
void testPasswordChecker() {
|
||||
assertEquals(0, checkPassword("mutti"));
|
||||
assertEquals(0, checkPassword("1234"));
|
||||
assertEquals(1, checkPassword("Mutti"));
|
||||
assertEquals(2, checkPassword("mutti123"));
|
||||
assertEquals(3, checkPassword("Mutti123"));
|
||||
assertEquals(4, checkPassword("Mutti123!%"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package pr2.auffrischung.printf;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static pr2.auffrischung.printf.DoubleFormatter.printDouble;
|
||||
|
||||
public class DoubleFormatterTest {
|
||||
|
||||
private static PrintStream out;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
out = System.out;
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDown() {
|
||||
System.setOut(out);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPrintf() throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
PrintStream out = System.out;
|
||||
PrintStream ps = new PrintStream(bos);
|
||||
System.setOut(ps);
|
||||
|
||||
printDouble(1.0);
|
||||
assertEquals("1.000", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(10.1);
|
||||
assertEquals("10.100", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.01);
|
||||
assertEquals("2.010", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.001);
|
||||
assertEquals("2.001", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.0001);
|
||||
assertEquals("2.000", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.0004);
|
||||
assertEquals("2.000", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.0005);
|
||||
assertEquals("2.001", bos.toString().trim());
|
||||
bos.reset();
|
||||
|
||||
bos.close();
|
||||
// Don't close ps!
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package pr2.auffrischung.suchemax;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class GroessteZahlTest {
|
||||
|
||||
@Test
|
||||
void testSucheMax() {
|
||||
GroessteZahl g = new GroessteZahl();
|
||||
assertEquals(8, g.sucheMax(
|
||||
new int[] {1, 5, 8, 2, 0}));
|
||||
assertEquals(-1, g.sucheMax(
|
||||
new int[] {-1, -5, -8, -2, -20}));
|
||||
assertEquals(10000, g.sucheMax(
|
||||
new int[] {10000, -10000, 1, 2, 33}));
|
||||
assertEquals(9, g.sucheMax(
|
||||
new int[] {9}));
|
||||
assertEquals(0, g.sucheMax(
|
||||
new int[] {0, 0, 0, 0, 0, 0, 0}));
|
||||
assertEquals(Integer.MAX_VALUE, g.sucheMax(
|
||||
new int[] {Integer.MIN_VALUE, Integer.MAX_VALUE}));
|
||||
assertEquals(Integer.MIN_VALUE, g.sucheMax(
|
||||
new int[] {Integer.MIN_VALUE, Integer.MIN_VALUE}));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package pr2.auffrischung.taschenrechner;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
public class TaschenrechnerTest {
|
||||
|
||||
@Test
|
||||
void testRechne() {
|
||||
Taschenrechner t = new Taschenrechner();
|
||||
assertEquals(0.0, t.rechne(0.0, '+', 0.0));
|
||||
assertEquals(0.0, t.rechne(0.0, '-', 0.0));
|
||||
assertEquals(0.0, t.rechne(0.0, '*', 0.0));
|
||||
assertEquals(0.0, t.rechne(0.0, '/', 1.0));
|
||||
assertEquals(0.0, t.rechne(0.0, '^', 1.0));
|
||||
|
||||
assertEquals(2.0, t.rechne(1.0, '+', 1.0));
|
||||
assertEquals(0.0, t.rechne(1.0, '-', 1.0));
|
||||
assertEquals(1.0, t.rechne(1.0, '*', 1.0));
|
||||
assertEquals(1.0, t.rechne(1.0, '/', 1.0));
|
||||
assertEquals(1.0, t.rechne(1.0, '^', 1.0));
|
||||
|
||||
assertEquals(4.4, t.rechne(2.2, '+', 2.2));
|
||||
assertEquals(2.2, t.rechne(4.4, '-', 2.2));
|
||||
assertEquals(4.4, t.rechne(2.2, '*', 2.0));
|
||||
assertEquals(2.0, t.rechne(2.2, '/', 1.1));
|
||||
assertEquals(4.0, t.rechne(2.0, '^', 2.0));
|
||||
|
||||
assertEquals(Double.NaN, t.rechne(1.0, '~', 1.0));
|
||||
|
||||
assertNotEquals(0.0, t.rechne(1.0, '~', 1.0) );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
package pr2.strukturierung.information_hiding.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.strukturierung.information_hiding.Rechner;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit-Test für den Rechner.
|
||||
*/
|
||||
public class RechnerTest {
|
||||
|
||||
/**
|
||||
* Testet alle Grundoperationen des Rechners.
|
||||
*/
|
||||
@Test
|
||||
void testRechner() {
|
||||
Rechner r = new Rechner();
|
||||
|
||||
// 2 + 2 = 4
|
||||
assertEquals(4.0, r.addiere(2.0, 2.0), 0.0001);
|
||||
|
||||
// 3 - 1 = 2
|
||||
assertEquals(2.0, r.subtrahiere(3, 1), 0.0001);
|
||||
|
||||
// 3 * 3 = 9
|
||||
assertEquals(9.0, r.multipliziere(3, 3), 0.0001);
|
||||
|
||||
// 2 + 2 * 2 = 6
|
||||
r.setSpeicher(r.multipliziere(2, 2));
|
||||
assertEquals(6.0, r.addiere(2, r.getSpeicher()), 0.0001);
|
||||
// // 2 + 2 = 4
|
||||
// r.addiere(2.0, 2.0);
|
||||
// assertEquals(4.0, r.wert, 0.0001);
|
||||
//
|
||||
// // 3 - 1 = 2
|
||||
// r.subtrahiere(3, 1);
|
||||
// assertEquals(2.0, r.wert, 0.0001);
|
||||
//
|
||||
// // 3 * 3 = 9
|
||||
// r.multipliziere(3, 3);
|
||||
// assertEquals(9.0, r.wert, 0.0001);
|
||||
//
|
||||
// // 2 + 2 * 2 = 6
|
||||
// r.multipliziere(2, 2);
|
||||
// r.speichern();
|
||||
// r.addiere(2, r.speicher);
|
||||
// assertEquals(6.0, r.wert, 0.0001);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package pr2.intro.junit_factorial;
|
||||
package pr2.intro.junit_faculty;
|
||||
|
||||
public class Fakultaet {
|
||||
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package pr2.auffrischung.grossmacher;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class GrossmacherTest {
|
||||
|
||||
private static PrintStream out;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
out = System.out;
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDown() {
|
||||
System.setOut(out);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = { "alles klein", "ALLES GROSS", "gemIschT" })
|
||||
void testMain(String text) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
PrintStream ps = new PrintStream(bos);
|
||||
System.setOut(ps);
|
||||
|
||||
Grossmacher.main(new String[] { text });
|
||||
String result = String.format("Ergebnis: %s\nZeichen : %d",
|
||||
text.toUpperCase(),
|
||||
text.length());
|
||||
|
||||
assertEquals(result, bos.toString().trim());
|
||||
bos.close();
|
||||
// Don't close ps!
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package pr2.auffrischung.labeled_break;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class ArraySucherTest {
|
||||
|
||||
final int[][] EMPTY = {{}};
|
||||
final int[][] ZERO = { { 0, 0, 0 }, { 0, 0, 0 }};
|
||||
final int[][] END = { { 0, 0, 0 }, { 0, 0, 1 }};
|
||||
final int[][] BEGINNING = { { 1, 0, 0 }, { 0, 0, 0 }};
|
||||
final int[][] ONE = { { 1, 1, 1 }, { 1, 1, 1 }};
|
||||
final int[][] TRIANGLE = { { 0, 0 }, { 0, 0 }, { 0, 0, 0 }, { 0, 0, 0, 1 } };
|
||||
|
||||
|
||||
@Test
|
||||
void testSuche() {
|
||||
var as = new ArraySucher();
|
||||
assertFalse(as.suche(EMPTY));
|
||||
assertFalse(as.suche(ZERO));
|
||||
assertTrue(as.suche(END));
|
||||
assertTrue(as.suche(BEGINNING));
|
||||
assertTrue(as.suche(ONE));
|
||||
assertTrue(as.suche(TRIANGLE));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package pr2.auffrischung.password;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static pr2.auffrischung.password.PasswortChecker.checkPassword;
|
||||
|
||||
public class PasswortCheckerTest {
|
||||
|
||||
@Test
|
||||
void testPasswordChecker() {
|
||||
assertEquals(0, checkPassword("mutti"));
|
||||
assertEquals(0, checkPassword("1234"));
|
||||
assertEquals(1, checkPassword("Mutti"));
|
||||
assertEquals(2, checkPassword("mutti123"));
|
||||
assertEquals(3, checkPassword("Mutti123"));
|
||||
assertEquals(4, checkPassword("Mutti123!%"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package pr2.auffrischung.printf;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static pr2.auffrischung.printf.DoubleFormatter.printDouble;
|
||||
|
||||
public class DoubleFormatterTest {
|
||||
|
||||
private static PrintStream out;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
out = System.out;
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDown() {
|
||||
System.setOut(out);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPrintf() throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
PrintStream out = System.out;
|
||||
PrintStream ps = new PrintStream(bos);
|
||||
System.setOut(ps);
|
||||
|
||||
printDouble(1.0);
|
||||
assertEquals("1.000", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(10.1);
|
||||
assertEquals("10.100", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.01);
|
||||
assertEquals("2.010", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.001);
|
||||
assertEquals("2.001", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.0001);
|
||||
assertEquals("2.000", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.0004);
|
||||
assertEquals("2.000", bos.toString().trim());
|
||||
bos.reset();
|
||||
printDouble(2.0005);
|
||||
assertEquals("2.001", bos.toString().trim());
|
||||
bos.reset();
|
||||
|
||||
bos.close();
|
||||
// Don't close ps!
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package pr2.auffrischung.suchemax;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class GroessteZahlTest {
|
||||
|
||||
@Test
|
||||
void testSucheMax() {
|
||||
GroessteZahl g = new GroessteZahl();
|
||||
assertEquals(8, g.sucheMax(
|
||||
new int[] {1, 5, 8, 2, 0}));
|
||||
assertEquals(-1, g.sucheMax(
|
||||
new int[] {-1, -5, -8, -2, -20}));
|
||||
assertEquals(10000, g.sucheMax(
|
||||
new int[] {10000, -10000, 1, 2, 33}));
|
||||
assertEquals(9, g.sucheMax(
|
||||
new int[] {9}));
|
||||
assertEquals(0, g.sucheMax(
|
||||
new int[] {0, 0, 0, 0, 0, 0, 0}));
|
||||
assertEquals(Integer.MAX_VALUE, g.sucheMax(
|
||||
new int[] {Integer.MIN_VALUE, Integer.MAX_VALUE}));
|
||||
assertEquals(Integer.MIN_VALUE, g.sucheMax(
|
||||
new int[] {Integer.MIN_VALUE, Integer.MIN_VALUE}));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package pr2.auffrischung.taschenrechner;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
public class TaschenrechnerTest {
|
||||
|
||||
@Test
|
||||
void testRechne() {
|
||||
Taschenrechner t = new Taschenrechner();
|
||||
assertEquals(0.0, t.rechne(0.0, '+', 0.0));
|
||||
assertEquals(0.0, t.rechne(0.0, '-', 0.0));
|
||||
assertEquals(0.0, t.rechne(0.0, '*', 0.0));
|
||||
assertEquals(0.0, t.rechne(0.0, '/', 1.0));
|
||||
assertEquals(0.0, t.rechne(0.0, '^', 1.0));
|
||||
|
||||
assertEquals(2.0, t.rechne(1.0, '+', 1.0));
|
||||
assertEquals(0.0, t.rechne(1.0, '-', 1.0));
|
||||
assertEquals(1.0, t.rechne(1.0, '*', 1.0));
|
||||
assertEquals(1.0, t.rechne(1.0, '/', 1.0));
|
||||
assertEquals(1.0, t.rechne(1.0, '^', 1.0));
|
||||
|
||||
assertEquals(4.4, t.rechne(2.2, '+', 2.2));
|
||||
assertEquals(2.2, t.rechne(4.4, '-', 2.2));
|
||||
assertEquals(4.4, t.rechne(2.2, '*', 2.0));
|
||||
assertEquals(2.0, t.rechne(2.2, '/', 1.1));
|
||||
assertEquals(4.0, t.rechne(2.0, '^', 2.0));
|
||||
|
||||
assertEquals(Double.NaN, t.rechne(1.0, '~', 1.0));
|
||||
|
||||
assertNotEquals(0.0, t.rechne(1.0, '~', 1.0) );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
package pr2.collections.iterator.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.collections.iterator.SimpleStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Test für den Stack.
|
||||
*/
|
||||
public class SimpleStackTest {
|
||||
|
||||
/**
|
||||
* Testet den Stack an sich.
|
||||
*/
|
||||
@Test
|
||||
void testStack() {
|
||||
SimpleStack<String> s = new SimpleStack<>(10);
|
||||
s.push("A");
|
||||
s.push("B");
|
||||
s.push("C");
|
||||
s.push("D");
|
||||
assertEquals("D", s.peek());
|
||||
assertEquals("D", s.pop());
|
||||
assertEquals("C", s.pop());
|
||||
assertEquals("B", s.pop());
|
||||
s.push("A2");
|
||||
s.push("A3");
|
||||
assertEquals("A3", s.peek());
|
||||
assertEquals("A3", s.pop());
|
||||
assertEquals("A2", s.pop());
|
||||
assertEquals("A", s.pop());
|
||||
}
|
||||
|
||||
// TODO: Einkommentieren
|
||||
//
|
||||
// /**
|
||||
// * Testet den Iterator.
|
||||
// */
|
||||
// @Test
|
||||
// void testIterator() {
|
||||
// SimpleStack<String> s = new SimpleStack<>(10);
|
||||
// s.push("A");
|
||||
// s.push("B");
|
||||
// s.push("C");
|
||||
// s.push("D");
|
||||
//
|
||||
// String[] result = new String[5];
|
||||
// int count = 0;
|
||||
//
|
||||
// for (String string : s) {
|
||||
// result[count++] = string;
|
||||
// }
|
||||
//
|
||||
// assertEquals("D", s.peek());
|
||||
//
|
||||
// assertEquals("D", result[0]);
|
||||
// assertEquals("C", result[1]);
|
||||
// assertEquals("B", result[2]);
|
||||
// assertEquals("A", result[3]);
|
||||
//
|
||||
// s.push("E");
|
||||
//
|
||||
// Iterator<String> it = s.iterator();
|
||||
//
|
||||
// count = 0;
|
||||
// while (it.hasNext()) {
|
||||
// result[count++] = it.next();
|
||||
// }
|
||||
//
|
||||
// assertEquals("E", result[0]);
|
||||
// assertEquals("D", result[1]);
|
||||
// assertEquals("C", result[2]);
|
||||
// assertEquals("B", result[3]);
|
||||
// assertEquals("A", result[4]);
|
||||
//
|
||||
// assertFalse(it.hasNext());
|
||||
//
|
||||
// it = s.iterator();
|
||||
//
|
||||
// assertTrue(it.hasNext());
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package pr2.collections.reverser.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.collections.reverser.Reverser;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ReverserTest {
|
||||
|
||||
@Test
|
||||
void testReverser() {
|
||||
// TODO: Reverser testen
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package pr2.collections.reverser_generic.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.collections.reverser_generic.Reverser;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ReverserTest {
|
||||
|
||||
@Test
|
||||
void testReverser() {
|
||||
// TODO: Reverser testen
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
package pr2.collections.sortieren.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.collections.sortieren.Sorter;
|
||||
import pr2.collections.sortieren.Sorter.SortOrder;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Test für die Sortierung.
|
||||
*/
|
||||
public class SorterTest {
|
||||
|
||||
private static final String[] DATA =
|
||||
{"aaron", "ALFONS", "bond", "BerND", "henry", "Hugo"};
|
||||
|
||||
/**
|
||||
* Testet die Sortierung: aufsteigend.
|
||||
*/
|
||||
@Test
|
||||
void testAscendingSorting() {
|
||||
|
||||
String[] asc = DATA.clone();
|
||||
|
||||
Sorter.sort(asc, SortOrder.ASCENDING);
|
||||
|
||||
assertArrayEquals(
|
||||
new String[] {"ALFONS", "BerND", "Hugo", "aaron", "bond",
|
||||
"henry"}, asc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet die Sortierung: Absteigend.
|
||||
*/
|
||||
@Test
|
||||
void testDescendingSorting() {
|
||||
|
||||
String[] desc = DATA.clone();
|
||||
Sorter.sort(desc, SortOrder.DESCENDING);
|
||||
|
||||
assertArrayEquals(
|
||||
new String[] {"henry", "bond", "aaron", "Hugo", "BerND",
|
||||
"ALFONS"}, desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet die Sortierung: Aufsteigend, CI.
|
||||
*/
|
||||
@Test
|
||||
void testAscendingCISorting() {
|
||||
|
||||
String[] ascCI = DATA.clone();
|
||||
Sorter.sort(ascCI, SortOrder.ASCENDING_CASE_INSENSITIVE);
|
||||
|
||||
assertArrayEquals(
|
||||
new String[] {"aaron", "ALFONS", "BerND", "bond", "henry",
|
||||
"Hugo"}, ascCI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet die Sortierung: Absteigend, CI.
|
||||
*/
|
||||
@Test
|
||||
void testDescendingCISorting() {
|
||||
|
||||
String[] descCI = DATA.clone();
|
||||
|
||||
Sorter.sort(descCI, SortOrder.DESCENDING_CASE_INSENSITIVE);
|
||||
|
||||
assertArrayEquals(
|
||||
new String[] {"Hugo", "henry", "bond", "BerND", "ALFONS",
|
||||
"aaron"}, descCI);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package pr2.enums.eigene.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.enums.eigene.Wuerfel;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test für die Würfel.
|
||||
*/
|
||||
public class WuerfelTest {
|
||||
|
||||
/**
|
||||
* Anzahl der Durchläufe (Gesetz der großen Zahl!).
|
||||
*/
|
||||
private static final int RUNS = 10000000;
|
||||
|
||||
|
||||
@Test
|
||||
void testFairnessD4() {
|
||||
internalTestFairness(new Wuerfel(Wuerfel.D4), 2.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFairnessD6() {
|
||||
internalTestFairness(new Wuerfel(Wuerfel.D6), 3.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFairnessD8() {
|
||||
internalTestFairness(new Wuerfel(Wuerfel.D8), 4.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFairnessD10() {
|
||||
internalTestFairness(new Wuerfel(Wuerfel.D10), 5.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFairnessD12() {
|
||||
internalTestFairness(new Wuerfel(Wuerfel.D12), 6.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interne Hilfsmethode, um die Fairness zu testen.
|
||||
*
|
||||
* @param w der zu testende Wuerfel.
|
||||
* @param expected Erwartungswert.
|
||||
*/
|
||||
private void internalTestFairness(Wuerfel w, double expected) {
|
||||
long sum = 0;
|
||||
|
||||
for (int i = 0; i < RUNS; i++) {
|
||||
sum += w.roll();
|
||||
}
|
||||
double average = (double) sum / (double) RUNS;
|
||||
assertEquals(expected, average, 0.1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
package pr2.exceptions.ausnahmen_testen.test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.exceptions.ausnahmen_testen.CrypterCaesar;
|
||||
import pr2.exceptions.ausnahmen_testen.IllegalKeyException;
|
||||
import pr2.exceptions.ausnahmen_testen.IllegalMessageException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Testklasse für die Verschlüsselung.
|
||||
*/
|
||||
public class CaesarTest {
|
||||
|
||||
// TODO: Tests für die Ausnahmen hinzufügen
|
||||
|
||||
/**
|
||||
* Testet die Verschlüsselung an sich.
|
||||
*
|
||||
* @throws IllegalMessageException Wird geworfen, wenn die
|
||||
* Nachricht ungültig ist.
|
||||
* @throws IllegalKeyException Wird geworfen, wenn der Schlüssel
|
||||
* ungültig ist.
|
||||
*/
|
||||
@Test
|
||||
void testCaesar()
|
||||
throws IllegalKeyException, IllegalMessageException {
|
||||
String klarText = "KATHARGOMUSSFALLEN";
|
||||
CrypterCaesar c = new CrypterCaesar();
|
||||
assertEquals(klarText, c.decrypt("C", c.encrypt("C", klarText)));
|
||||
assertEquals("FDHVDU", c.encrypt("C", "CAESAR"));
|
||||
assertEquals(klarText, c.encrypt("Z", klarText));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
package pr2.exceptions.eigene_ausnahme.test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.exceptions.eigene_ausnahme.Fuse;
|
||||
import pr2.exceptions.eigene_ausnahme.FuseTrippedException;
|
||||
import pr2.exceptions.eigene_ausnahme.IllegalCurrentException;
|
||||
|
||||
/**
|
||||
* Testet die Sicherung.
|
||||
*/
|
||||
public class FuseTest {
|
||||
|
||||
// TODO: Quellcode wieder einkommentieren
|
||||
//
|
||||
// /**
|
||||
// * Testet die Erzeugung von Sicherungen mit gültigen Werten.
|
||||
// *
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testCreationValid() throws IllegalCurrentException {
|
||||
// new Fuse(Fuse.A16);
|
||||
// new Fuse(Fuse.A25);
|
||||
// new Fuse(Fuse.A32);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet die Erzeugung von Sicherungen mit ungültigen Werten.
|
||||
// *
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testCreationValid1() throws IllegalCurrentException {
|
||||
// Assertions.assertThrows(IllegalCurrentException.class, () -> {
|
||||
// new Fuse(15);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet die Erzeugung von Sicherungen mit ungültigen Werten.
|
||||
// *
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testCreationValid2() throws IllegalCurrentException {
|
||||
// Assertions.assertThrows(IllegalCurrentException.class, () -> {
|
||||
// new Fuse(-1);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet die Erzeugung von Sicherungen mit ungültigen Werten.
|
||||
// *
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testCreationValid3() throws IllegalCurrentException {
|
||||
// Assertions.assertThrows(IllegalCurrentException.class, () -> {
|
||||
// new Fuse(0);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet die Erzeugung von Sicherungen mit ungültigen Werten.
|
||||
// *
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testCreationValid4() throws IllegalCurrentException {
|
||||
// Assertions.assertThrows(IllegalCurrentException.class, () -> {
|
||||
// new Fuse(Integer.MAX_VALUE);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet die Erzeugung von Sicherungen mit ungültigen Werten.
|
||||
// *
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testCreationValid5() throws IllegalCurrentException {
|
||||
// Assertions.assertThrows(IllegalCurrentException.class, () -> {
|
||||
// new Fuse(Integer.MIN_VALUE);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet das Auslösen der Sicherung.
|
||||
// *
|
||||
// * @throws FuseTrippedException Sicherung hat ausgelöst.
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testTripping1()
|
||||
// throws FuseTrippedException, IllegalCurrentException {
|
||||
//
|
||||
// Fuse f = new Fuse(Fuse.A16);
|
||||
// f.use(5);
|
||||
// f.use(16);
|
||||
// f.use(0);
|
||||
//
|
||||
// f = new Fuse(Fuse.A25);
|
||||
// f.use(5);
|
||||
// f.use(16);
|
||||
// f.use(25);
|
||||
//
|
||||
//
|
||||
// Assertions.assertThrows(FuseTrippedException.class, () -> {
|
||||
// Fuse f2 = new Fuse(Fuse.A16);
|
||||
// f2.use(0);
|
||||
// f2.use(16);
|
||||
// f2.use(25);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet das Auslösen der Sicherung.
|
||||
// *
|
||||
// * @throws FuseTrippedException Sicherung hat ausgelöst.
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testTripping2()
|
||||
// throws FuseTrippedException, IllegalCurrentException {
|
||||
// Assertions.assertThrows(FuseTrippedException.class, () -> {
|
||||
// new Fuse(Fuse.A16).use(17);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet das Auslösen der Sicherung.
|
||||
// *
|
||||
// * @throws FuseTrippedException Sicherung hat ausgelöst.
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testTripping3()
|
||||
// throws FuseTrippedException, IllegalCurrentException {
|
||||
//
|
||||
// Assertions.assertThrows(FuseTrippedException.class, () -> {
|
||||
// new Fuse(Fuse.A16).use(Integer.MAX_VALUE);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Testet das Auslösen der Sicherung.
|
||||
// *
|
||||
// * @throws FuseTrippedException Sicherung hat ausgelöst.
|
||||
// * @throws IllegalCurrentException ungültiger Wert für die Sicherung.
|
||||
// */
|
||||
// @Test
|
||||
// void testTripping4()
|
||||
// throws FuseTrippedException, IllegalCurrentException {
|
||||
// Assertions.assertThrows(FuseTrippedException.class, () -> {
|
||||
// new Fuse(Fuse.A32).use(40);
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package pr2.exceptions.fakultaet.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.exceptions.fakultaet.Fakultaet;
|
||||
import pr2.exceptions.fakultaet.FakultaetException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
public class FakultaetTest {
|
||||
|
||||
@Test
|
||||
void testFact() {
|
||||
Fakultaet f = new Fakultaet();
|
||||
assertEquals(1, f.fact(0));
|
||||
assertEquals(1, f.fact(1));
|
||||
assertEquals(2, f.fact(2));
|
||||
assertEquals(6, f.fact(3));
|
||||
assertEquals(24, f.fact(4));
|
||||
assertEquals(3628800, f.fact(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFactEx1() {
|
||||
// TODO: Auf Ausnahme testen
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFactEx2() {
|
||||
// TODO: Auf Ausnahme testen
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package pr2.generics.einfach.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.generics.einfach.Liste;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* Test für die Liste.
|
||||
*/
|
||||
public class ListeTest {
|
||||
|
||||
/**
|
||||
* Testet das Hinzufügen und Löschen der Liste.
|
||||
*/
|
||||
@Test
|
||||
void testAddAndClear() {
|
||||
Liste l = new Liste();
|
||||
|
||||
assertEquals(0, l.size());
|
||||
|
||||
l.add("Hallo");
|
||||
assertEquals(1, l.size());
|
||||
l.add("Hugo");
|
||||
assertEquals(2, l.size());
|
||||
l.add("Peter");
|
||||
l.add("Alfons");
|
||||
assertEquals(4, l.size());
|
||||
|
||||
l.clear();
|
||||
assertEquals(0, l.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet das Lesen von Elementen.
|
||||
*/
|
||||
@Test
|
||||
void testGet() {
|
||||
Liste l = new Liste();
|
||||
l.add("Hallo");
|
||||
l.add("Hugo");
|
||||
l.add("Peter");
|
||||
l.add("Alfons");
|
||||
|
||||
assertNull(l.get(-1));
|
||||
assertNull(l.get(4));
|
||||
assertEquals("Hallo", l.get(0));
|
||||
assertEquals("Hugo", l.get(1));
|
||||
assertEquals("Peter", l.get(2));
|
||||
assertEquals("Alfons", l.get(3));
|
||||
|
||||
assertEquals(4, l.size());
|
||||
l.clear();
|
||||
assertEquals(0, l.size());
|
||||
assertNull(l.get(0));
|
||||
assertNull(l.get(1));
|
||||
assertNull(l.get(2));
|
||||
assertNull(l.get(3));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
package pr2.generics.super_extends.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.generics.super_extends.Liste;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Test für die Liste.
|
||||
*/
|
||||
public class ListeTest {
|
||||
|
||||
/**
|
||||
* Testet das Umkopieren.
|
||||
*/
|
||||
@Test
|
||||
void testAddAndClear() {
|
||||
// TODO: Einkommentieren
|
||||
// Liste<String> ls = new Liste<>();
|
||||
// Liste<Object> lo = new Liste<>();
|
||||
//
|
||||
// ls.add("Hallo");
|
||||
// ls.add("Hugo");
|
||||
// ls.add("Peter");
|
||||
// ls.add("Alfons");
|
||||
//
|
||||
// ls.copyInto(lo);
|
||||
//
|
||||
// assertEquals("Hallo", lo.get(0));
|
||||
// assertEquals("Hugo", lo.get(1));
|
||||
// assertEquals("Peter", lo.get(2));
|
||||
// assertEquals("Alfons", lo.get(3));
|
||||
//
|
||||
// lo = new Liste<>();
|
||||
// lo.fillFrom(ls);
|
||||
//
|
||||
// assertEquals("Hallo", lo.get(0));
|
||||
// assertEquals("Hugo", lo.get(1));
|
||||
// assertEquals("Peter", lo.get(2));
|
||||
// assertEquals("Alfons", lo.get(3));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package pr2.interfaces.comparable_student;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
public class ComparableStudentTest {
|
||||
|
||||
@Test
|
||||
void testCompare() {
|
||||
final Student s1 = new Student("Andreas", "Herrmann", 12348);
|
||||
final Student s2 = new Student("Frank", "Herrmann", 22348);
|
||||
final Student s3 = new Student("Alfons", "Meier", 12345);
|
||||
final Student s4 = new Student("Alfons", "Meier", 12346);
|
||||
final Student s5 = new Student("Andreas", "Muster", 12347);
|
||||
|
||||
Student[] a = { s1, s2, s3, s4, s5 };
|
||||
Student[] expected = a.clone();
|
||||
|
||||
Arrays.sort(a);
|
||||
assertArrayEquals(expected, a);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package pr2.interfaces.interfaces_e.test;
|
||||
|
||||
//import org.junit.jupiter.api.Test;
|
||||
|
||||
//import tpe.vererbung.interfaces.api.AnalogController;
|
||||
//import tpe.vererbung.interfaces.chinesen.AnalogControllerImpl;
|
||||
|
||||
/**
|
||||
* Tests für einen analogen Joystick.
|
||||
*/
|
||||
public class AnalogControllerTest extends DigitalControllerTest {
|
||||
//
|
||||
// /**
|
||||
// * Testet einen anlogen Controller.
|
||||
// */
|
||||
// @Test
|
||||
// void testAnalogController() {
|
||||
// AnalogController c = new AnalogControllerImpl();
|
||||
// testAnalogController(c);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Interne Hilfsmethode zum Test von analogen Controllern.
|
||||
// *
|
||||
// * @param c Controller, der getestet wird
|
||||
// */
|
||||
// protected void testAnalogController(AnalogController c) {
|
||||
// c.up(0.5);
|
||||
// assertPointEquals(0, 0, c.getPosition());
|
||||
// c.up(0.5);
|
||||
// assertPointEquals(0, -1, c.getPosition());
|
||||
//
|
||||
// c.left(0.3);
|
||||
// c.left(0.3);
|
||||
// c.left(0.3);
|
||||
// assertPointEquals(0, -1, c.getPosition());
|
||||
// c.left(0.2);
|
||||
// assertPointEquals(-1, -1, c.getPosition());
|
||||
//
|
||||
// c.down(1.0);
|
||||
// assertPointEquals(-1, 0, c.getPosition());
|
||||
//
|
||||
// c.down(1.0);
|
||||
// assertPointEquals(-1, 1, c.getPosition());
|
||||
// c.down(1.0);
|
||||
// assertPointEquals(-1, 2, c.getPosition());
|
||||
//
|
||||
// c.right(0.5);
|
||||
// c.right(0.5);
|
||||
// c.right(0.5);
|
||||
// assertPointEquals(0, 2, c.getPosition());
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
package pr2.interfaces.interfaces_e.test;
|
||||
|
||||
import java.awt.Point;
|
||||
import org.junit.jupiter.api.Test;
|
||||
//
|
||||
//import org.junit.jupiter.api.Test;
|
||||
import pr2.interfaces.interfaces_e.impl.DigitalControllerImpl;
|
||||
import pr2.interfaces.interfaces_e.api.DigitalController;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests für einen digitalen Joystick.
|
||||
*/
|
||||
public class DigitalControllerTest {
|
||||
|
||||
/**
|
||||
* Testet einen digitalen Controller.
|
||||
*/
|
||||
@Test
|
||||
void testDigitalController() {
|
||||
DigitalController c = new DigitalControllerImpl();
|
||||
testDigitalController(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interne Hilfsmethode zum Test von digitalen Controllern.
|
||||
*
|
||||
* @param c Controller, der getestet wird
|
||||
*/
|
||||
protected void testDigitalController(DigitalController c) {
|
||||
assertPointEquals(0, 0, c.getPosition());
|
||||
c.up();
|
||||
c.up();
|
||||
assertPointEquals(0, -2, c.getPosition());
|
||||
c.down();
|
||||
c.down();
|
||||
assertPointEquals(0, 0, c.getPosition());
|
||||
c.left();
|
||||
c.right();
|
||||
assertPointEquals(0, 0, c.getPosition());
|
||||
c.left();
|
||||
assertPointEquals(-1, 0, c.getPosition());
|
||||
c.left();
|
||||
assertPointEquals(-2, 0, c.getPosition());
|
||||
c.right();
|
||||
c.right();
|
||||
c.right();
|
||||
assertPointEquals(1, 0, c.getPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Interne Hilfsmethode, um einen Punkt mit seinem x und
|
||||
* y-Wert zu vergleichen.
|
||||
*
|
||||
* @param x x-Wert
|
||||
* @param y y-Wert
|
||||
* @param point Punkt, der verglichen werden soll
|
||||
*/
|
||||
protected void assertPointEquals(int x, int y, Point point) {
|
||||
assertEquals(new Point(x, y), point);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
package pr2.interfaces.interfaces_e.test;
|
||||
|
||||
//import org.junit.jupiter.api.Test;
|
||||
|
||||
//import pr2.interfaces.interfaces_e.api.DigitalController;
|
||||
|
||||
/**
|
||||
* Tests für einen analogen Joystick.
|
||||
*/
|
||||
public class DualShock4Test extends AnalogControllerTest {
|
||||
//
|
||||
// /**
|
||||
// * Testet einen DualShock4 Kombi-Controller.
|
||||
// */
|
||||
// @Test
|
||||
// void testDualShock4() {
|
||||
// DigitalController cd = new DualShock4();
|
||||
// testDigitalController(cd);
|
||||
//
|
||||
// AnalogController ca = new DualShock4();
|
||||
// testAnalogController(ca);
|
||||
//
|
||||
// DualShock4 ds = new DualShock4();
|
||||
//
|
||||
// ds.up();
|
||||
// ds.up(1.0);
|
||||
// assertPointEquals(0, -2, ds.getPosition());
|
||||
//
|
||||
// ds.left();
|
||||
// ds.right();
|
||||
// ds.right(0.5);
|
||||
// ds.right(0.5);
|
||||
// assertPointEquals(1, -2, ds.getPosition());
|
||||
//
|
||||
// ds.down();
|
||||
// ds.down();
|
||||
// ds.down(0.3);
|
||||
// ds.down(0.3);
|
||||
// ds.down(0.3);
|
||||
// ds.down(0.1);
|
||||
// assertPointEquals(1, 1, ds.getPosition());
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package pr2.interfaces.stack;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.interfaces.stack.Stack;
|
||||
import pr2.interfaces.stack.StackImpl;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class StackTest {
|
||||
|
||||
@Test
|
||||
void testStack() {
|
||||
Stack s = new StackImpl(100);
|
||||
|
||||
assertEquals(0, s.size());
|
||||
|
||||
s.push("Hallo");
|
||||
s.push("wie");
|
||||
s.push("gehts");
|
||||
|
||||
assertEquals(3, s.size());
|
||||
|
||||
assertEquals("gehts", s.peek());
|
||||
assertEquals("gehts", s.pop());
|
||||
|
||||
assertEquals("wie", s.peek());
|
||||
assertEquals("wie", s.pop());
|
||||
|
||||
assertEquals("Hallo", s.peek());
|
||||
assertEquals("Hallo", s.pop());
|
||||
|
||||
assertNull(s.pop());
|
||||
assertEquals(0, s.size());
|
||||
|
||||
s.push("A");
|
||||
assertEquals("A", s.pop());
|
||||
assertNull(s.pop());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
package pr2.interfaces.stack.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.interfaces.stack.Stack;
|
||||
import pr2.interfaces.stack.StackImpl;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class StackTest {
|
||||
|
||||
@Test
|
||||
void testStack() {
|
||||
// TODO: Einkommentieren
|
||||
// Stack s = new StackImpl(100);
|
||||
//
|
||||
// assertEquals(0, s.size());
|
||||
//
|
||||
// s.push("Hallo");
|
||||
// s.push("wie");
|
||||
// s.push("gehts");
|
||||
//
|
||||
// assertEquals(3, s.size());
|
||||
//
|
||||
// assertEquals("gehts", s.peek());
|
||||
// assertEquals("gehts", s.pop());
|
||||
//
|
||||
// assertEquals("wie", s.peek());
|
||||
// assertEquals("wie", s.pop());
|
||||
//
|
||||
// assertEquals("Hallo", s.peek());
|
||||
// assertEquals("Hallo", s.pop());
|
||||
//
|
||||
// assertNull(s.pop());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package pr2.intro.junit_factorial.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.intro.junit_factorial.Fakultaet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class FakultaetTest {
|
||||
|
||||
@Test
|
||||
void testFact() {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
package pr2.io.data_output.test;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.io.data_output.Board;
|
||||
import pr2.io.data_output.Color;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
public class BoardTest {
|
||||
|
||||
private static final byte[] RESULT = new byte[] {
|
||||
0x00, 0x0B, 0x53, 0x63, 0x68, 0x61, 0x63, 0x68, 0x62, 0x72, 0x65,
|
||||
0x74, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06,
|
||||
0x00, 0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x02,
|
||||
0x04, 0x00, 0x00, 0x00, 0x01, 0x04, 0x05, 0x00, 0x00, 0x00, 0x01,
|
||||
0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x00, 0x00, 0x00,
|
||||
0x00, (byte) 0xff, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
|
||||
(byte) 0xFF, (byte) 0xFF
|
||||
};
|
||||
|
||||
/**
|
||||
* Test für die Implementierung des Spielbrettes.
|
||||
*
|
||||
* @throws IOException Datei-Probleme.
|
||||
*/
|
||||
@Test
|
||||
void testDame() throws IOException {
|
||||
Board s = new Board();
|
||||
s.set("a1", Color.BLACK);
|
||||
s.set("b1", Color.WHITE);
|
||||
s.set("h1", Color.BLACK);
|
||||
s.set("h2", Color.BLACK);
|
||||
s.set("a8", Color.BLACK);
|
||||
s.set("f8", Color.BLACK);
|
||||
s.set("f5", Color.WHITE);
|
||||
s.set("e3", Color.WHITE);
|
||||
s.set("g2", Color.WHITE);
|
||||
|
||||
String stringRepresentation = s.toString();
|
||||
|
||||
s.writeToFile("/tmp/daten.dat");
|
||||
|
||||
s = Board.loadFromFile("/tmp/daten.dat");
|
||||
|
||||
assertEquals(stringRepresentation, s.toString());
|
||||
|
||||
FileOutputStream fos = new FileOutputStream("/tmp/testdata.dat");
|
||||
fos.write(RESULT);
|
||||
fos.close();
|
||||
|
||||
s = Board.loadFromFile("/tmp/testdata.dat");
|
||||
|
||||
assertEquals(stringRepresentation, s.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package pr2.io.datei_schreiben.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.io.datei_schreiben.WriteData;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
/**
|
||||
* Test für die geschriebenen Daten.
|
||||
*/
|
||||
public class WriteDataTest {
|
||||
|
||||
/**
|
||||
* Geschriebene Daten testen.
|
||||
*
|
||||
* @throws IOException Datei-Probleme.
|
||||
*/
|
||||
@Test
|
||||
void testData() throws IOException {
|
||||
final String testFile = "/tmp/test.dat";
|
||||
|
||||
WriteData.main(new String[] { testFile });
|
||||
|
||||
InputStream is = new FileInputStream(testFile);
|
||||
|
||||
byte[] buffer = new byte[10];
|
||||
is.read(buffer);
|
||||
assertArrayEquals(
|
||||
new byte[] {(byte) 0xca, (byte) 0xff, (byte) 0xfe, (byte) 0xba,
|
||||
(byte) 0xbe, (byte) 0x00, (byte) 0xde, (byte) 0xad,
|
||||
(byte) 0xbe, (byte) 0xef}, buffer);
|
||||
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package pr2.io.filter.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.io.filter.UCaseReader;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test für die Rot13 "Verschlüsselung".
|
||||
*/
|
||||
public class UCaseReaderTest {
|
||||
|
||||
/**
|
||||
* Testmethode.
|
||||
*
|
||||
* @throws IOException IO-Probleme
|
||||
*/
|
||||
@Test
|
||||
void testReader() throws IOException {
|
||||
|
||||
// TODO: Einkommentieren
|
||||
// BufferedReader br = new BufferedReader(
|
||||
// new UCaseReader(new StringReader(
|
||||
// "Dies ist" + " ein Test für den UCASE-Reader.")));
|
||||
//
|
||||
// String line = br.readLine();
|
||||
// assertEquals("DIES IST EIN TEST FÜR DEN UCASE-READER.", line);
|
||||
//
|
||||
// br.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
package pr2.io.random_access.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.io.random_access.FileSort;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Testet die Sortierung per Random-Access-File.
|
||||
*/
|
||||
public class FileSortTest {
|
||||
|
||||
/**
|
||||
* Kopiert die Datei f1 als Datei f2.
|
||||
*
|
||||
* @param f1 Quell-Datei
|
||||
* @param f2 Ziel-Datei
|
||||
* @throws IOException IO-Probleme
|
||||
*/
|
||||
private static void copyFile(String f1, String f2) throws IOException {
|
||||
|
||||
FileInputStream fis = new FileInputStream(f1);
|
||||
FileOutputStream fos = new FileOutputStream(f2);
|
||||
|
||||
int b;
|
||||
|
||||
while ((b = fis.read()) != -1) {
|
||||
fos.write(b);
|
||||
}
|
||||
|
||||
fis.close();
|
||||
fos.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet die File-Sortierung.
|
||||
*
|
||||
* @throws IOException IO-Problem
|
||||
*/
|
||||
@Test
|
||||
void testBubbleSort() throws IOException {
|
||||
String path = getClass().getResource("data.dat").getFile();
|
||||
|
||||
copyFile(path, "/tmp/data.dat");
|
||||
FileSort.sortFile("/tmp/data.dat");
|
||||
|
||||
InputStream is = new FileInputStream("/tmp/data.dat");
|
||||
|
||||
int data;
|
||||
byte lastByte = 0;
|
||||
|
||||
while ((data = is.read()) >= 0) {
|
||||
byte b = (byte) data;
|
||||
assertTrue(b >= lastByte);
|
||||
lastByte = b;
|
||||
}
|
||||
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package pr2.io.serialisierung.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.io.serialisierung.Board;
|
||||
import pr2.io.serialisierung.Color;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
public class BoardTest {
|
||||
|
||||
/**
|
||||
* Test für die Implementierung des Spielbrettes.
|
||||
*
|
||||
* @throws IOException Datei-Probleme.
|
||||
*/
|
||||
@Test
|
||||
void testDame() throws IOException {
|
||||
Board s = new Board();
|
||||
s.set("a1", Color.BLACK);
|
||||
s.set("b1", Color.WHITE);
|
||||
s.set("h1", Color.BLACK);
|
||||
s.set("h2", Color.BLACK);
|
||||
s.set("a8", Color.BLACK);
|
||||
s.set("f8", Color.BLACK);
|
||||
s.set("f5", Color.WHITE);
|
||||
s.set("e3", Color.WHITE);
|
||||
s.set("g2", Color.WHITE);
|
||||
|
||||
String stringRepresentation = s.toString();
|
||||
|
||||
s.writeToFile("/tmp/board.dat");
|
||||
|
||||
s = Board.loadFromFile("/tmp/board.dat");
|
||||
|
||||
assertEquals(stringRepresentation, s.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package pr2.lambda.matrixsuche.test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.lambda.matrixsuche.MatrixSuche;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class MatrixSucheTest {
|
||||
|
||||
@Test
|
||||
void testSuche() {
|
||||
|
||||
// TODO: Einkommentieren
|
||||
// int[][] matrix = {
|
||||
// {3, 5, 6, 7, 8},
|
||||
// {10, 12, 14, 16, 18},
|
||||
// {23, 25, 26, 27, 28}
|
||||
// };
|
||||
//
|
||||
// Assertions.assertEquals("(0, 1)",
|
||||
// MatrixSuche.findEntry(matrix, 5).toString());
|
||||
// assertEquals("(2, 0)",
|
||||
// MatrixSuche.findEntry(matrix, 23).toString());
|
||||
// assertEquals("(1, 2)",
|
||||
// MatrixSuche.findEntry(matrix, 14).toString());
|
||||
// assertEquals("(0, 4)",
|
||||
// MatrixSuche.findEntry(matrix, 8).toString());
|
||||
// assertNull(
|
||||
// MatrixSuche.findEntry(matrix, 99));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package pr2.lambda.mogrifier_1.test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.lambda.mogrifier_1.StringTransmogrifier;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
public class StringTransmogrifierTest {
|
||||
|
||||
@Test
|
||||
void testMogrification() {
|
||||
// TODO: Tests durchführen
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
package pr2.lambda.mogrifier_2.test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.lambda.mogrifier_2.StringFunction;
|
||||
import pr2.lambda.mogrifier_2.StringTransmogrifier;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
public class StringTransmogrifierTest {
|
||||
|
||||
static final String[] ELEMENTS = {"Hello", "World"};
|
||||
|
||||
@Test
|
||||
void testMogrification() {
|
||||
|
||||
|
||||
Assertions.assertArrayEquals(new String[] {"hello", "world"},
|
||||
StringTransmogrifier.transmogrify(ELEMENTS,
|
||||
String::toLowerCase));
|
||||
|
||||
assertArrayEquals(new String[] {"HELLO", "WORLD"},
|
||||
StringTransmogrifier.transmogrify(ELEMENTS,
|
||||
String::toUpperCase));
|
||||
|
||||
assertArrayEquals(new String[] {"Ifmmp", "Xpsme"},
|
||||
StringTransmogrifier.transmogrify(ELEMENTS,
|
||||
s -> {
|
||||
char[] c = s.toCharArray();
|
||||
for (int i = 0; i < c.length; i++) {
|
||||
c[i] = (char) (c[i] + 1);
|
||||
}
|
||||
return new String(c);
|
||||
}));
|
||||
}
|
||||
|
||||
// TODO: Tests für caesar durchführen
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
package pr2.object.clone_alien.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.object.clone_alien.Alien;
|
||||
import pr2.object.clone_alien.Raumanzug;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
|
||||
/**
|
||||
* Test für die Clone-Methoden.
|
||||
*/
|
||||
public class AlienCloneTest {
|
||||
|
||||
/**
|
||||
* Test-Methode.
|
||||
*
|
||||
* @throws CloneNotSupportedException wird geworfen, wenn clone_alien
|
||||
* nicht korrekt implementiert wurde.
|
||||
*/
|
||||
@Test
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
// TODO: Einkommentieren
|
||||
// Raumanzug r1 = new Raumanzug();
|
||||
// Alien a1 = new Alien("Predator", r1);
|
||||
//
|
||||
// Alien a2 = (Alien) a1.clone();
|
||||
// Raumanzug r2 = a2.getAnzug();
|
||||
//
|
||||
// assertNotSame(a1, a2);
|
||||
// assertNotSame(r1, r2);
|
||||
//
|
||||
// assertEquals(a1, a2);
|
||||
// assertEquals(r1, r2);
|
||||
// assertEquals(r1.getSauerstoffVorrat(), r2.getSauerstoffVorrat(),
|
||||
// 0.0001);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
package pr2.object.equals_hashcode.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.object.equals_hashcode.Ork;
|
||||
import pr2.object.equals_hashcode.Wesen;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
|
||||
/**
|
||||
* Testklasse für die Wesen.
|
||||
*/
|
||||
public class WesenTest {
|
||||
|
||||
/**
|
||||
* Testet equals und hashCode von Wesen.
|
||||
*/
|
||||
@Test
|
||||
void testWesen() {
|
||||
Wesen w1 = new Wesen("Azok", 30);
|
||||
Wesen w2 = new Wesen("Azok", 30);
|
||||
Wesen w3 = new Wesen("Azok", 31);
|
||||
Wesen w4 = new Wesen("Gorrok", 30);
|
||||
Wesen w5 = new Wesen("Gorrok", 31);
|
||||
|
||||
assertNotSame(w1, w2);
|
||||
assertEquals(w1, w2);
|
||||
|
||||
assertNotSame(w1, w3);
|
||||
assertNotEquals(w1, w3);
|
||||
|
||||
assertNotSame(w1, w4);
|
||||
assertNotEquals(w1, w4);
|
||||
|
||||
assertNotSame(w1, w5);
|
||||
assertNotEquals(w1, w5);
|
||||
|
||||
assertEquals(w1.hashCode(), w2.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet equals und hashCode von Ork.
|
||||
*/
|
||||
@Test
|
||||
void testOrk() {
|
||||
Ork o1 = new Ork("Snagas", true);
|
||||
Ork o2 = new Ork("Snagas", true);
|
||||
Ork o3 = new Ork("Snagas", false);
|
||||
Ork o4 = new Ork("Berg-Ork", false);
|
||||
Ork o5 = new Ork("Berg-Ork", true);
|
||||
Ork o6 = new Ork("Berg-Ork", false);
|
||||
Wesen w = new Wesen("Snagas", 17);
|
||||
|
||||
assertNotSame(o1, o2);
|
||||
assertEquals(o1, o2);
|
||||
|
||||
assertNotSame(o1, o3);
|
||||
assertNotEquals(o1, o3);
|
||||
|
||||
assertNotSame(o1, o4);
|
||||
assertNotEquals(o1, o4);
|
||||
|
||||
assertNotSame(o1, o5);
|
||||
assertNotEquals(o1, o5);
|
||||
|
||||
assertEquals(o1.hashCode(), o2.hashCode());
|
||||
assertEquals(o4.hashCode(), o6.hashCode());
|
||||
|
||||
assertNotEquals(w, o1);
|
||||
assertNotEquals(w, o2);
|
||||
assertNotEquals(w, o3);
|
||||
assertNotEquals(null, o1);
|
||||
assertNotEquals("Hugo", o1);
|
||||
assertEquals(o1, o1);
|
||||
|
||||
// Diese Tests muss nicht zwangsweise funktionieren, da
|
||||
// ungleiche Objekte einen identischen Hashcode haben können.
|
||||
// Wir gehen hier aber davon aus, dass eine Hashkollision
|
||||
// sehr selten ist und machen daher aus didaktischen Gründen
|
||||
// diesen Test.
|
||||
assertNotEquals(o1.hashCode(), o3.hashCode());
|
||||
assertNotEquals(o1.hashCode(), o4.hashCode());
|
||||
assertNotEquals(o1.hashCode(), o5.hashCode());
|
||||
assertNotEquals(o4.hashCode(), o5.hashCode());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package pr2.streams.chars_1.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.streams.chars_1.CountLetters;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class CountLettersTest {
|
||||
@Test
|
||||
void testCount() {
|
||||
// TODO: Methode count testen
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package pr2.streams.chars_2.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.streams.chars_2.CountLetters;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class CountLettersTest {
|
||||
@Test
|
||||
void testCount() {
|
||||
// TODO: Methode count testen
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package pr2.streams.chars_3.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.streams.chars_3.CountLetters;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class CountLettersTest {
|
||||
@Test
|
||||
void testCount() {
|
||||
// TODO: Methode count testen
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package pr2.streams.filter.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.streams.filter.FilterList;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class FilterListTest {
|
||||
|
||||
@Test
|
||||
void testFilter() {
|
||||
List<String> liste = Arrays.asList(
|
||||
"Hallo", "Welt", "Dampfschifffahrt", "Hundekuchen",
|
||||
"Fiction", "Java", "Visual Basic", "Drucker");
|
||||
|
||||
List<String> result = Arrays.asList(
|
||||
"hallo", "dampfschifffahrt", "hundekuchen",
|
||||
"fiction", "visual basic", "drucker");
|
||||
|
||||
assertEquals(result, FilterList.filter(liste));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package pr2.streams.reduce.test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.streams.reduce.Squarer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SquarerTest {
|
||||
|
||||
@Test
|
||||
void testMitMap() {
|
||||
List<Integer> l = Arrays.asList(1, 5, 8, 9, 12, 10, 3);
|
||||
Assertions.assertEquals(424, Squarer.mitMap(l));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOhneMap() {
|
||||
List<Integer> l = Arrays.asList(1, 5, 8, 9, 12, 10, 3);
|
||||
assertEquals(424, Squarer.ohneMap(l));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package pr2.streams.summieren.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.streams.summieren.SumUp;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SumUpTest {
|
||||
|
||||
@Test
|
||||
void testSum() {
|
||||
List<Integer> l = Arrays.asList(1, 5, 8, 9, 12, 10, 3);
|
||||
assertEquals(48, SumUp.sumUp(l.stream()));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package pr2.streams.word_count.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.streams.word_count.WordCount;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class WordCountTest {
|
||||
|
||||
@Test
|
||||
void testWordCount() {
|
||||
List<String> liste = Arrays.asList("A", "A", "B", "B", "B", "C",
|
||||
"D", "D", "E", "E", "E", "F");
|
||||
|
||||
assertEquals(Arrays.asList("A->2", "B->3", "C->1", "D->2",
|
||||
"E->3", "F->1"), WordCount.count(liste));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
package pr2.strukturierung.information_hiding.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.strukturierung.information_hiding.Rechner;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit-Test für den Rechner.
|
||||
*/
|
||||
public class RechnerTest {
|
||||
|
||||
/**
|
||||
* Testet alle Grundoperationen des Rechners.
|
||||
*/
|
||||
@Test
|
||||
void testRechner() {
|
||||
Rechner r = new Rechner();
|
||||
|
||||
// 2 + 2 = 4
|
||||
r.addiere(2.0, 2.0);
|
||||
assertEquals(4.0, r.wert, 0.0001);
|
||||
|
||||
// 3 - 1 = 2
|
||||
r.subtrahiere(3, 1);
|
||||
assertEquals(2.0, r.wert, 0.0001);
|
||||
|
||||
// 3 * 3 = 9
|
||||
r.multipliziere(3, 3);
|
||||
assertEquals(9.0, r.wert, 0.0001);
|
||||
|
||||
// 2 + 2 * 2 = 6
|
||||
r.multipliziere(2, 2);
|
||||
r.speichern();
|
||||
r.addiere(2, r.speicher);
|
||||
assertEquals(6.0, r.wert, 0.0001);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package pr2.vererbung.konstruktoren.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.vererbung.konstruktoren.Nachtelf;
|
||||
import pr2.vererbung.konstruktoren.Untoter;
|
||||
import pr2.vererbung.konstruktoren.Wesen;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Test für die Aufgabe.
|
||||
*/
|
||||
public class WesenTest {
|
||||
|
||||
/**
|
||||
* Testet den Nachtelf.
|
||||
*/
|
||||
@Test
|
||||
void testNachtelf() {
|
||||
// TODO: Einkommentieren
|
||||
// assertTrue(new Nachtelf("") instanceof Wesen,
|
||||
// "Nachtelf erbt nicht " + "von Wesen");
|
||||
//
|
||||
// assertEquals(Nachtelf.STANDARD_NATURWIDERSTAND,
|
||||
// new Nachtelf("").getNaturwiderstand());
|
||||
//
|
||||
// assertEquals(120, new Nachtelf("", 120).getNaturwiderstand());
|
||||
//
|
||||
// assertEquals("Hugo", new Nachtelf("Hugo").getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testet den Untoten.
|
||||
*/
|
||||
@Test
|
||||
void testUntoten() {
|
||||
// TODO: Einkommentieren
|
||||
// assertTrue(new Untoter("") instanceof Wesen,
|
||||
// "Untoter erbt nicht von " + "Wesen");
|
||||
//
|
||||
// assertEquals(Untoter.STANDARD_UNTERWASSERATMUNG,
|
||||
// new Untoter("").getUnterwasseratmung());
|
||||
//
|
||||
// assertEquals(120, new Untoter("", 120).getUnterwasseratmung());
|
||||
//
|
||||
// assertEquals("Hugo", new Untoter("Hugo").getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package pr2.vererbung.ueberladen_summe;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.vererbung.ueberladen_summe.Summator;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SummatorTest {
|
||||
|
||||
@Test
|
||||
void testSum() {
|
||||
Summator s = new Summator();
|
||||
assertEquals(3, s.sum(1, 2));
|
||||
assertEquals(1, s.sum(-1, 2));
|
||||
assertEquals(6, s.sum(1, 2, 3));
|
||||
assertEquals(0, s.sum(1, 2, -3));
|
||||
assertEquals(10, s.sum(1, 2, 3, 4));
|
||||
assertEquals(2, s.sum(1, 2, 3, -4));
|
||||
assertEquals(15, s.sum(1, 2, 3, 4, 5));
|
||||
assertEquals(5, s.sum(1, 2, 3, 4, -5));
|
||||
assertEquals(0, s.sum(0, 0));
|
||||
assertEquals(0, s.sum(0, 0, 0));
|
||||
assertEquals(0, s.sum(0, 0, 0, 0));
|
||||
assertEquals(0, s.sum(0, 0,0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package pr2.vererbung.ueberladen_summe.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.vererbung.ueberladen_summe.Summator;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SummatorTest {
|
||||
|
||||
@Test
|
||||
void testSum() {
|
||||
// TODO: Einkommentieren
|
||||
// Summator s = new Summator();
|
||||
// assertEquals(3, s.sum(1, 2));
|
||||
// assertEquals(1, s.sum(-1, 2));
|
||||
// assertEquals(6, s.sum(1, 2, 3));
|
||||
// assertEquals(0, s.sum(1, 2, -3));
|
||||
// assertEquals(10, s.sum(1, 2, 3, 4));
|
||||
// assertEquals(2, s.sum(1, 2, 3, -4));
|
||||
// assertEquals(15, s.sum(1, 2, 3, 4, 5));
|
||||
// assertEquals(5, s.sum(1, 2, 3, 4, -5));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package pr2.vererbung.vararg_summe;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.vererbung.vararg_summe.Summator;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SummatorTest {
|
||||
|
||||
@Test
|
||||
void testSum() {
|
||||
Summator s = new Summator();
|
||||
assertEquals(3, s.sum(1, 2));
|
||||
assertEquals(1, s.sum(-1, 2));
|
||||
assertEquals(6, s.sum(1, 2, 3));
|
||||
assertEquals(0, s.sum(1, 2, -3));
|
||||
assertEquals(10, s.sum(1, 2, 3, 4));
|
||||
assertEquals(2, s.sum(1, 2, 3, -4));
|
||||
assertEquals(15, s.sum(1, 2, 3, 4, 5));
|
||||
assertEquals(5, s.sum(1, 2, 3, 4, -5));
|
||||
assertEquals(36, s.sum(1, 2, 3, 4, 5, 6, 7, 8));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package pr2.vererbung.vararg_summe.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.vererbung.vararg_summe.Summator;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SummatorTest {
|
||||
|
||||
@Test
|
||||
void testSum() {
|
||||
// TODO: Einkommentieren
|
||||
// Summator s = new Summator();
|
||||
// assertEquals(3, s.sum(1, 2));
|
||||
// assertEquals(1, s.sum(-1, 2));
|
||||
// assertEquals(6, s.sum(1, 2, 3));
|
||||
// assertEquals(0, s.sum(1, 2, -3));
|
||||
// assertEquals(10, s.sum(1, 2, 3, 4));
|
||||
// assertEquals(2, s.sum(1, 2, 3, -4));
|
||||
// assertEquals(15, s.sum(1, 2, 3, 4, 5));
|
||||
// assertEquals(5, s.sum(1, 2, 3, 4, -5));
|
||||
// assertEquals(36, s.sum(1, 2, 3, 4, 5, 6, 7, 8));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
package pr2.vererbung.vererbung_geometrie;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.vererbung.vererbung_geometrie.Dreieck;
|
||||
import pr2.vererbung.vererbung_geometrie.Gerade;
|
||||
import pr2.vererbung.vererbung_geometrie.Quadrat;
|
||||
import pr2.vererbung.vererbung_geometrie.Rechteck;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests für die Figuren.
|
||||
*/
|
||||
public class FigurenTest {
|
||||
|
||||
private static final double PRECISION = 0.0001;
|
||||
|
||||
/**
|
||||
* Rechteck.
|
||||
*/
|
||||
@Test
|
||||
void testReckteck() {
|
||||
Rechteck r1 = new Rechteck(4.0, 5.0);
|
||||
Rechteck r2 = new Rechteck(0.0, 3.0);
|
||||
assertEquals(20.0, r1.getFlaeche(), PRECISION);
|
||||
assertEquals(0.0, r2.getFlaeche(), PRECISION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dreieck.
|
||||
*/
|
||||
@Test
|
||||
void testDreieck() {
|
||||
Dreieck d1 = new Dreieck(6.0, 3.5);
|
||||
assertEquals(10.5, d1.getFlaeche(), PRECISION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gerade.
|
||||
*/
|
||||
@Test
|
||||
void testGerade() {
|
||||
Gerade g1 = new Gerade(8.0);
|
||||
assertEquals(8.0, g1.getLaenge(), PRECISION);
|
||||
assertEquals(0.0, g1.getFlaeche(), PRECISION);
|
||||
|
||||
g1 = new Gerade(0.0);
|
||||
assertEquals(0.0, g1.getLaenge(), PRECISION);
|
||||
assertEquals(0.0, g1.getFlaeche(), PRECISION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quadrat.
|
||||
*/
|
||||
@Test
|
||||
void testQuadrat() {
|
||||
Quadrat q1 = new Quadrat(3.0);
|
||||
assertEquals(9.0, q1.getFlaeche(), PRECISION);
|
||||
|
||||
Rechteck r1 = new Rechteck(5.0, 5.0);
|
||||
Quadrat q2 = new Quadrat(5.0);
|
||||
assertEquals(r1.getFlaeche(), q2.getFlaeche(), PRECISION);
|
||||
|
||||
q1 = new Quadrat(0.0);
|
||||
assertEquals(0.0, q1.getFlaeche(), PRECISION);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
package pr2.vererbung.vererbung_geometrie.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.vererbung.vererbung_geometrie.Dreieck;
|
||||
import pr2.vererbung.vererbung_geometrie.Gerade;
|
||||
import pr2.vererbung.vererbung_geometrie.Quadrat;
|
||||
import pr2.vererbung.vererbung_geometrie.Rechteck;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests für die Figuren.
|
||||
*/
|
||||
public class FigurenTest {
|
||||
|
||||
private static final double PRECISION = 0.0001;
|
||||
|
||||
/**
|
||||
* Rechteck.
|
||||
*/
|
||||
@Test
|
||||
void testReckteck() {
|
||||
// TODO: Einkommentieren
|
||||
// Rechteck r1 = new Rechteck(4.0, 5.0);
|
||||
// Rechteck r2 = new Rechteck(0.0, 3.0);
|
||||
// assertEquals(20.0, r1.getFlaeche(), PRECISION);
|
||||
// assertEquals(0.0, r2.getFlaeche(), PRECISION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dreieck.
|
||||
*/
|
||||
@Test
|
||||
void testDreieck() {
|
||||
// TODO: Einkommentieren
|
||||
// Dreieck d1 = new Dreieck(6.0, 3.5);
|
||||
// assertEquals(10.5, d1.getFlaeche(), PRECISION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gerade.
|
||||
*/
|
||||
@Test
|
||||
void testGerade() {
|
||||
// TODO: Einkommentieren
|
||||
// Gerade g1 = new Gerade(8.0);
|
||||
// assertEquals(8.0, g1.getLaenge(), PRECISION);
|
||||
// assertEquals(0.0, g1.getFlaeche(), PRECISION);
|
||||
//
|
||||
// g1 = new Gerade(0.0);
|
||||
// assertEquals(0.0, g1.getLaenge(), PRECISION);
|
||||
// assertEquals(0.0, g1.getFlaeche(), PRECISION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quadrat.
|
||||
*/
|
||||
@Test
|
||||
void testQuadrat() {
|
||||
// TODO: Einkommentieren
|
||||
// Quadrat q1 = new Quadrat(3.0);
|
||||
// assertEquals(9.0, q1.getFlaeche(), PRECISION);
|
||||
//
|
||||
// Rechteck r1 = new Rechteck(5.0, 5.0);
|
||||
// Quadrat q2 = new Quadrat(5.0);
|
||||
// assertEquals(r1.getFlaeche(), q2.getFlaeche(), PRECISION);
|
||||
//
|
||||
// q1 = new Quadrat(0.0);
|
||||
// assertEquals(0.0, q1.getFlaeche(), PRECISION);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue