diff --git a/2021-WS-Testat-G1-TagAnalyzer-LV/.project b/2021-WS-Testat-G1-TagAnalyzer-LV/.project
new file mode 100644
index 0000000..7ff366a
--- /dev/null
+++ b/2021-WS-Testat-G1-TagAnalyzer-LV/.project
@@ -0,0 +1,17 @@
+
+
+ 2021-WS-Testat-G1-TagAnalyzer-LV
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/2021-WS-Testat-G1-TagAnalyzer-LV/2021-WS Testat-G1-TweetAnalyzer.pdf b/2021-WS-Testat-G1-TagAnalyzer-LV/2021-WS Testat-G1-TweetAnalyzer.pdf
new file mode 100644
index 0000000..fc8318a
Binary files /dev/null and b/2021-WS-Testat-G1-TagAnalyzer-LV/2021-WS Testat-G1-TweetAnalyzer.pdf differ
diff --git a/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1/ATweetTagAnalyser.java b/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1/ATweetTagAnalyser.java
new file mode 100644
index 0000000..0c8d2d4
--- /dev/null
+++ b/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1/ATweetTagAnalyser.java
@@ -0,0 +1,58 @@
+package G1;
+
+import twitter.TweetObject;
+
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+public abstract class ATweetTagAnalyser {
+
+ // ----------------------------------------------------
+ // API
+ // ----------------------------------------------------
+
+ public int prepareTweetObject(TweetObject tweet) {
+ return prepareTweetObject(tweet, t -> true);
+ }
+
+ // Extrahiert die Tags aus dem Text des Tweet-Objektes in eine Liste und fügt diese dem
+ // Tweet-Objekt hinzu, falls dass Tweet-Objekt den filter erfüllt (Methode filter.test(...))
+ // muss true liefern. Achtung: Das "#"-Zeichen muss entfernt werden
+ // Rückgabe: 0 falls tweet == null oder filter.test(tweet)==False
+ // Sonst: Anzahl an gefundenen Tags
+ // Beachten Sie die Hinweise
+ public abstract int prepareTweetObject(TweetObject tweet, Predicate filter);
+
+ // Fügt die Tags eines tweet-Objektes zum Analyzer hinzu. Das Tweet-Objekt muss die Tags als
+ // Liste enthalten (im Attribut tagList).
+ // Rückgabe: Anzahl an Tags, die noch nicht im Analyzer enthalten waren
+ // 0 falls tweet==null
+ public abstract int addTags(TweetObject tweet);
+
+ // Liefert die Anzahl, wie oft der Tag tag zum Analyzer hinzugefügt wurde
+ // 0 falls der Tag nicht enthalten ist
+ public abstract int getTagCount(String tag);
+
+ // Ist der Tag im Analyzer enthalten?
+ public abstract boolean contains(String tag);
+
+ // Löscht einen Tag und gibt die Anzahl zurück,wie oft er addiert wurde
+ public abstract int remove(String tag);
+
+
+ // Undo-Operation für addTags(TweetObject tweet).
+ public abstract int removeTags(TweetObject tweet);
+
+ //public abstract int forEach(Consumer action);
+ public abstract Set getTags();
+
+
+ // ----------------------------------------------------
+ // Delegate methods
+ // ----------------------------------------------------
+
+
+
+
+}
diff --git a/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1/ATweetTagAnalyserTest.java b/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1/ATweetTagAnalyserTest.java
new file mode 100644
index 0000000..dffa079
--- /dev/null
+++ b/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1/ATweetTagAnalyserTest.java
@@ -0,0 +1,252 @@
+package G1;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import twitter.TweetObject;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public abstract class ATweetTagAnalyserTest {
+
+ private ATweetTagAnalyser analyser;
+
+ private Set interestingTags = new HashSet<>();
+ private ATweetTagAnalyser preparation;
+ protected Predicate filter = t -> {
+ if(t.getId().equals("123459876543211")) {return false;}
+ else {return true;}
+ };
+
+ static TweetObject tw1, tw1c, tw2, tw2c, tw3, tw4, tw5;
+
+ @BeforeAll
+ static void setUpBeforeAll() {
+ tw1c = new TweetObject("123459876543211", null, "Mein #PCR Test ist positiv, #Corona " +
+ "#Covid19");
+ tw1c.setTags(Arrays.asList("corona", "pcr", "covid19"));
+ tw2c = new TweetObject("123459876543212", null, "Geht zur #Corona #Impfung " +
+ "#COVID19");
+ tw2c.setTags(Arrays.asList("corona", "impfung", "covid19"));
+ }
+
+ protected abstract ATweetTagAnalyser getInstance();
+
+ @BeforeEach
+ void setUp() {
+ analyser = getInstance();
+ tw1 = new TweetObject("123459876543211", null, "Mein #PCR Test ist positiv, #Corona " +
+ "#Covid19");
+ tw2 = new TweetObject("123459876543212", null, "Geht zur #Corona #Impfung " +
+ "#COVID19");
+ tw3 = new TweetObject("123459876543212", null, "Hallo Welt");
+ tw4 = new TweetObject("123459876543212", null, "#CORONA ist #Mist");
+ tw4.setTags(Arrays.asList("corona", "mist"));
+ tw5 = new TweetObject("123459876543211", null, "Am BVerfG gelten für alle " +
+ "Prozessbeteiligten strengste " +
+ "Zugangsbeschränkungen: 2G plus " +
+ "PCR Test. Erste Bundesländer vom " +
+ "Grundsatz ab, die Justiz bei " +
+ "Corona-Beschränkungen auszusparen " +
+ "#covid #corona #Grundgesetz");
+
+ }
+
+ @Test
+ void prepareTweetObject1() {
+ var actual = analyser.prepareTweetObject(null);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void prepareTweetObject2() {
+ var actual = analyser.prepareTweetObject(tw1);
+ assertEquals(3, actual);
+ }
+
+ @Test
+ void prepareTweetObject3() {
+ var actual = analyser.prepareTweetObject(tw5, this.filter);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void prepareTweetObject4() {
+ analyser.prepareTweetObject(tw1);
+ var actual = tw1.getTags().size();
+ assertEquals(3, actual);
+ }
+
+ @Test
+ void prepareTweetObject5() {
+ analyser.prepareTweetObject(tw1);
+ List tagList = tw1.getTags();
+ var actual = tagList.contains("corona");
+ assertEquals(true, actual);
+ actual = tagList.contains("covid19");
+ assertEquals(true, actual);
+ actual = tagList.contains("pcr");
+ assertEquals(true, actual);
+ }
+
+ @Test
+ void addTags1() {
+ var actual = analyser.addTags(null);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void addTags2() {
+ var actual = analyser.addTags(tw1c);
+ assertEquals(3, actual);
+ }
+
+ @Test
+ void addTags3() {
+ analyser.addTags(tw1c);
+ var actual = analyser.addTags(tw1c);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void addTags4() {
+ analyser.addTags(tw1c);
+ var actual = analyser.addTags(tw2c);
+ assertEquals(1, actual);
+ }
+
+
+ @Test
+ void getTagCount1() {
+ var actual = analyser.getTagCount("corona");
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void getTagCount2a() {
+ analyser.addTags(tw1c);
+ var actual = analyser.getTagCount("corona");
+ assertEquals(1, actual);
+ }
+
+ @Test
+ void getTagCount2b() {
+ analyser.addTags(tw1c);
+ var actual = analyser.getTagCount("CORONa");
+ assertEquals(1, actual);
+ }
+
+ @Test
+ void getTagCount3() {
+ analyser.addTags(tw1c);
+ analyser.addTags(tw2c);
+ var actual = analyser.getTagCount("corona");
+ assertEquals(2, actual);
+ }
+
+
+ @Test
+ void remove1a() {
+ var actual = analyser.remove(null);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void remove1b() {
+ var actual = analyser.remove("corona");
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void remove2a() {
+ analyser.addTags(tw1c);
+ var actual = analyser.remove("corona");
+ assertEquals(1, actual);
+ actual = analyser.getTagCount("corona");
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void remove2b() {
+ analyser.addTags(tw1c);
+ var actual = analyser.remove("Corona");
+ assertEquals(1, actual);
+ actual = analyser.getTagCount("corona");
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void remove3() {
+ analyser.addTags(tw1c);
+ analyser.addTags(tw2c);
+ var actual = analyser.remove("corona");
+ assertEquals(2, actual);
+ actual = analyser.getTagCount("corona");
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void remove4() {
+ analyser.addTags(tw1c);
+ analyser.addTags(tw2c);
+ analyser.remove("corona");
+ var actual = analyser.getTagCount("pcr");
+ assertEquals(1, actual);
+ }
+
+ @Test
+ void removeTweet1a() {
+ var actual = analyser.removeTags(null);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void removeTweet1b() {
+ var actual = analyser.removeTags(tw1c);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void removeTweet2a() {
+ analyser.addTags(tw1c);
+ analyser.addTags(tw2c);
+ analyser.addTags(tw4);
+ var actual = analyser.removeTags(tw1c);
+ assertEquals(3, actual);
+ }
+
+ @Test
+ void removeTweet2b() {
+ analyser.addTags(tw1c);
+ analyser.addTags(tw2c);
+ analyser.addTags(tw4);
+ analyser.removeTags(tw1c);
+ var actual = analyser.getTagCount("Corona");
+ assertEquals(2, actual);
+ }
+
+// @Test
+// void forEach1() {
+// var actual = analyser.forEach(null);
+// assertEquals(0, actual);
+// }
+//
+// @Test
+// void forEach2() {
+// AtomicInteger counter = new AtomicInteger();
+// Consumer action = s -> counter.getAndAdd(s);
+// analyser.addTags(tw1);
+// analyser.addTags(tw2);
+// var actual = analyser.forEach(action);
+// assertEquals(4, actual);
+// assertEquals(6, counter.intValue());
+// }
+}
\ No newline at end of file
diff --git a/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1_solution/TweetTagAnalyzer.java b/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1_solution/TweetTagAnalyzer.java
new file mode 100644
index 0000000..363ebb9
--- /dev/null
+++ b/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1_solution/TweetTagAnalyzer.java
@@ -0,0 +1,100 @@
+package G1_solution;
+
+import G1.ATweetTagAnalyser;
+import twitter.TweetObject;
+
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+public class TweetTagAnalyzer extends ATweetTagAnalyser {
+
+ private Map tagCounter;
+ private Set interestingTags;
+
+ public TweetTagAnalyzer(Set interestingTags) {
+ this.interestingTags = interestingTags;
+ }
+
+ public TweetTagAnalyzer() {
+ this.interestingTags = null;
+ this.tagCounter = new HashMap<>();
+ }
+
+ @Override
+ public int prepareTweetObject(TweetObject tweet, Predicate filter) {
+ if(tweet == null) {return 0;}
+ if(!filter.test(tweet)) {return 0;}
+ List tagList = new LinkedList<>();
+ String[] parts = tweet.getText().toLowerCase().split(" ");
+ for(int i = 0; i < parts.length; i++) {
+ if(parts[i].contains("#")) {
+ String tag = parts[i].replace("#", "");
+ tagList.add(tag);
+ }
+ }
+ tweet.setTags(tagList);
+ return tagList.size();
+ }
+
+ @Override
+ public int addTags(TweetObject tweet) {
+ if(tweet == null) {return 0;}
+ int counter = 0;
+ for(String tag : tweet.getTags()) {
+ Integer tagCount = tagCounter.get(tag);
+ if(tagCount == null) {
+ counter++;
+ tagCount = 0;
+ }
+ tagCounter.put(tag, tagCount + 1);
+ }
+ return counter;
+ }
+
+
+ @Override
+ public int getTagCount(String tag) {
+ Integer counter = this.tagCounter.get(tag.toLowerCase(Locale.ROOT));
+ if(counter == null) {return 0;}
+ return counter;
+ }
+
+ @Override
+ public boolean contains(String tag) {
+ return this.tagCounter.values().contains(tag);
+ }
+
+ @Override
+ public int remove(String tag) {
+ if(tag == null) {return 0;}
+ Integer counter = this.tagCounter.remove(tag.toLowerCase(Locale.ROOT));
+ if(counter != null) {return counter;}
+ return 0;
+ }
+
+ @Override
+ public int removeTags(TweetObject tweet) {
+ if(tweet == null) {return 0;}
+ int counter = 0;
+ for(String tag : tweet.getTags()) {
+ int tagCount = getTagCount(tag.toLowerCase());
+ if(tagCount > 0) {
+ this.tagCounter.put(tag.toLowerCase(Locale.ROOT), --tagCount);
+ counter++;
+ }
+ }
+ return counter;
+ }
+
+// @Override
+// public int forEach(Consumer action) {
+// this.tagCounter.values().forEach(v -> action.accept(v));
+// return this.tagCounter.size();
+// }
+
+ @Override
+ public Set getTags() {
+ return null;
+ }
+}
diff --git a/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1_solution/TweetTagAnalyzerTest.java b/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1_solution/TweetTagAnalyzerTest.java
new file mode 100644
index 0000000..0118f8c
--- /dev/null
+++ b/2021-WS-Testat-G1-TagAnalyzer-LV/src/G1_solution/TweetTagAnalyzerTest.java
@@ -0,0 +1,11 @@
+package G1_solution;
+
+import G1.ATweetTagAnalyser;
+import G1.ATweetTagAnalyserTest;
+
+public class TweetTagAnalyzerTest extends ATweetTagAnalyserTest {
+ @Override
+ protected ATweetTagAnalyser getInstance() {
+ return new TweetTagAnalyzer();
+ }
+}
diff --git a/2021-WS-Testat-G1-TagAnalyzer-LV/src/twitter/AbstractTestClass.java b/2021-WS-Testat-G1-TagAnalyzer-LV/src/twitter/AbstractTestClass.java
new file mode 100644
index 0000000..433d5d7
--- /dev/null
+++ b/2021-WS-Testat-G1-TagAnalyzer-LV/src/twitter/AbstractTestClass.java
@@ -0,0 +1,15 @@
+package twitter;
+
+import org.junit.jupiter.api.BeforeEach;
+
+public abstract class AbstractTestClass {
+ protected T testObject;
+
+ protected abstract T getInstance();
+
+ @BeforeEach
+ void setUp() {
+ testObject = getInstance();
+ }
+
+}
diff --git a/2021-WS-Testat-G1-TagAnalyzer-LV/src/twitter/TweetObject.java b/2021-WS-Testat-G1-TagAnalyzer-LV/src/twitter/TweetObject.java
new file mode 100644
index 0000000..f19c82a
--- /dev/null
+++ b/2021-WS-Testat-G1-TagAnalyzer-LV/src/twitter/TweetObject.java
@@ -0,0 +1,86 @@
+package twitter;
+
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+
+public class TweetObject {
+ private String id;
+ private String created_at;
+ private String text;
+ private String user;
+ private int wordCount;
+ private List tags;
+
+ public TweetObject() {}
+
+ public TweetObject(String id, String created_at, String text) {
+ this.id = id;
+ this.created_at = created_at;
+ this.text = text;
+ this.tags = new LinkedList<>();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getCreated_at() {
+ return created_at;
+ }
+
+ public void setCreated_at(String created_at) {
+ this.created_at = created_at;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public int getWordCount() {return wordCount;}
+
+ public void setWordCount(int wordCount) {this.wordCount = wordCount;}
+
+ public List getTags() {
+ return tags;
+ }
+
+ public void setTags(List tags) {
+ this.tags.addAll(tags);
+ }
+
+ public void addTag(String tag) {this.tags.add(tag);}
+
+ @Override
+ public boolean equals(Object obj) {
+ if(obj == null) {return false;}
+ if(obj instanceof TweetObject) {
+ TweetObject that = (TweetObject) obj;
+ return this.id.equals(that.id);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return id + ';' + created_at + ';' + text + ';' + user;
+ }
+}
+
+
diff --git a/2021-WS-Testat-G2-TweetGen/.project b/2021-WS-Testat-G2-TweetGen/.project
new file mode 100644
index 0000000..73cadf1
--- /dev/null
+++ b/2021-WS-Testat-G2-TweetGen/.project
@@ -0,0 +1,17 @@
+
+
+ 2021-WS-Testat-G2-TweetGen-LV
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/2021-WS-Testat-G2-TweetGen/2021-WS Testat-G2-TwitterClient.pdf b/2021-WS-Testat-G2-TweetGen/2021-WS Testat-G2-TwitterClient.pdf
new file mode 100644
index 0000000..72a14e4
Binary files /dev/null and b/2021-WS-Testat-G2-TweetGen/2021-WS Testat-G2-TwitterClient.pdf differ
diff --git a/2021-WS-Testat-G2-TweetGen/src/G2/ATweetGenerator.java b/2021-WS-Testat-G2-TweetGen/src/G2/ATweetGenerator.java
new file mode 100644
index 0000000..94bb53c
--- /dev/null
+++ b/2021-WS-Testat-G2-TweetGen/src/G2/ATweetGenerator.java
@@ -0,0 +1,86 @@
+package G2;
+
+import twitter.TweetObject;
+
+import java.util.*;
+
+public abstract class ATweetGenerator {
+
+ private ITwitterConnector connector;
+
+ public interface ITwitterConnector {
+ public boolean testConnection();
+
+ public boolean postTweets(Collection tweetObjects);
+ }
+
+ public ATweetGenerator() {
+
+ }
+
+ // ----------------------------------------------------
+ // API
+ // ----------------------------------------------------
+
+
+ // Umwandlung der Zeichenkette csvTweet in ein TweetObject
+ // Die Tags können mit extractTags(String text) extrahiert werden (s.u.)
+ // Rückgabe: TweetObjekt, null falls csvString == null oder syntaktisch nicht korrekt ist
+ // Format csvString: id;created_at;text;user
+ // Hinweis: text enthält kein ";"
+ public abstract TweetObject addTweetCSV(String csvTweed);
+
+ // Fügt das tweetObjekt hinzu sofern es nicht null oder bereits enthalten ist
+ // Falls das TweetObjekt hinzugefügt wird, wird die Anzahl an Wörtern im Text zu der bereits
+ // gespeicherten Anzahl der Wörter des Users tweet.getUser() hinzugefügt
+ // Falls Tweet keine Wörter enthält, nicht aufnehmen
+ // Rückgabe: Anzahl der neu aufgenommenen Wörter (0 falls tweet bereits enthalten ist)
+ public abstract int addTweet(TweetObject tweet);
+
+ // Gesamte Anzahl an Wörtern
+ public abstract int getNrOfWords();
+
+ // Gesamte Anzahl an Wörtern von User user
+ public abstract int getNrOfWords(String user);
+
+ // Tweet enthalten
+ public abstract boolean contains(TweetObject tweet);
+
+ // Löscht den Tweet und entfernt die entsprechende Anzahl an Wörtern bei User tweet.getUser()
+ // Rückgabe: Die Anzahl an verbleibenden Wörter des User
+ // Ist tweet == null oder der Tweet nicht enthalten, wird 0 zurückgegeben
+ public abstract int remove(TweetObject tweet);
+
+ // Postet alle gesammelten Tweets, sofern testConnection() true ergibt
+ // Rückgabe true, falls postTweet() true liefert
+ // danach ist der CLient leer
+ public abstract int postTweets(ITwitterConnector connector);
+
+
+ // Support
+ public int addTweetsCSV(Collection csvTweedCollection) {
+ Set collectedTweeds = new HashSet<>();
+ csvTweedCollection.forEach(csvTweet -> collectedTweeds.add(this.addTweetCSV(csvTweet)));
+ return addTweets(collectedTweeds);
+ }
+
+ public int addTweets(Collection tweetObjects) {
+ int counter = 0;
+ for(TweetObject t : tweetObjects) {
+ counter += this.addTweet(t);
+ }
+ return counter;
+ }
+
+ protected static List extractTags(String text) {
+ List tagList = new LinkedList<>();
+ String[] parts = text.split(" ");
+ for(int i = 0; i < parts.length; i++) {
+ if(parts[i].contains("#")) {
+ String[] tagParts = parts[i].split("#");
+ tagList.add(tagParts[1]);
+ }
+ }
+ return tagList;
+ }
+}
diff --git a/2021-WS-Testat-G2-TweetGen/src/G2/ATweetGeneratorTest.java b/2021-WS-Testat-G2-TweetGen/src/G2/ATweetGeneratorTest.java
new file mode 100644
index 0000000..e428e01
--- /dev/null
+++ b/2021-WS-Testat-G2-TweetGen/src/G2/ATweetGeneratorTest.java
@@ -0,0 +1,296 @@
+package G2;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import twitter.TweetObject;
+
+import java.util.Collection;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public abstract class ATweetGeneratorTest {
+ private ATweetGenerator client;
+ private ATweetGenerator.ITwitterConnector defaultConnector = new ATweetGenerator.ITwitterConnector() {
+ @Override
+ public boolean testConnection() {
+ return false;
+ }
+
+ @Override
+ public boolean postTweets(Collection tweetObjects) {
+ return false;
+ }
+ };
+ private ATweetGenerator.ITwitterConnector connector = new ATweetGenerator.ITwitterConnector() {
+ @Override
+ public boolean testConnection() {
+ return true;
+ }
+
+ @Override
+ public boolean postTweets(Collection tweetObjects) {
+ return true;
+ }
+ };
+ static TweetObject tw1, tw2, tw3;
+ static String csv1;
+ static String csv2 = "123456789;2020-12-22T13:28:30.000Z;OOPP-Testat trotz #corona #Covid19;1234";
+ static String csv3 = "123456719;2020-12-22T13:28:30.000Z;OOPP-Testat im #Corona-Semester " +
+ "#Covid19;" +
+ "271895613";
+ ;
+
+ @BeforeAll
+ static void setUpBeforeAll() { }
+
+ protected abstract ATweetGenerator getInstance();
+
+ @BeforeEach
+ void setUp() {
+ client = getInstance();
+ tw1 = new TweetObject("1341375150298697728", null, "Mein #PCR-Test ist positiv, #Corona " +
+ "#Covid19");
+ tw1.setUser("271895613");
+ csv1 = tw1.toString();
+ tw2 = new TweetObject("1341375111920758786", null, "");
+ tw2.setUser("151949069");
+
+ tw3 = new TweetObject("2221375150298697728", null, "Mein #PCR Test ist negativ, #Corona " +
+ "#Covid19");
+ tw3.setUser("271895613");
+ }
+
+ @Test
+ void addTweetCSV1a() {
+ var actual = client.addTweetCSV(null);
+ assertEquals(null, actual);
+ }
+
+ @Test
+ void addTweetCSV1b() {
+ var actual = client.addTweetCSV("");
+ assertEquals(null,actual);
+ }
+
+ @Test
+ void addTweetCSV2() {
+ var actual = client.addTweetCSV(csv1);
+ assertEquals(tw1, actual);
+ }
+
+ @Test
+ void addTweetCSV3() {
+ var actual = client.addTweetCSV(csv2);
+ assertEquals("OOPP-Testat trotz #corona #Covid19", actual.getText());
+ assertEquals(2, actual.getTags().size());
+ assertEquals("1234", actual.getUser());
+ }
+
+ @Test
+ void addTweet1() {
+ var actual = client.addTweet(null);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void addTweet2() {
+ var actual = client.addTweet(tw1);
+ assertEquals(6, actual);
+ }
+
+ @Test
+ void addTweet3() {
+ client.addTweet(tw1);
+ var actual = client.addTweet(tw2);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void addTweet4() {
+ client.addTweet(tw1);
+ var actual = client.addTweet(tw1);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void nrOfWords1() {
+ var actual = client.getNrOfWords();
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void nrOfWords2() {
+ client.addTweet(tw1);
+ var actual = client.getNrOfWords();
+ assertEquals(6, actual);
+ }
+
+ @Test
+ void nrOfWords3() {
+ client.addTweet(tw1);
+ client.addTweet(tw1);
+ var actual = client.getNrOfWords();
+ assertEquals(6, actual);
+ }
+
+ @Test
+ void nrOfWordsUser1a() {
+ var actual = client.getNrOfWords(null);
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void nrOfWordsUser1b() {
+ var actual = client.getNrOfWords("");
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void nrOfWordsUser2a() {
+ client.addTweet(tw1);
+ var actual = client.getNrOfWords("271895613");
+ assertEquals(6, actual);
+ }
+
+ @Test
+ void nrOfWordsUser2b() {
+ client.addTweet(tw1);
+ var actual = client.getNrOfWords("2718956000");
+ assertEquals(0, actual);
+ }
+
+ @Test
+ void nrOfWordsUser3() {
+ client.addTweet(tw1);
+ var actual = client.getNrOfWords("271895613");
+ assertEquals(6, actual);
+ }
+
+ @Test
+ void nrOfWordsUser4() {
+ client.addTweet(tw1);
+ client.addTweet(tw3);
+ var actual = client.getNrOfWords("271895613");
+ assertEquals(13, actual);
+ }
+
+ @Test
+ void testContains1a() {
+ var actual = client.contains(null);
+ assertEquals(false, actual);
+ }
+ @Test
+ void testContains1b() {
+ var actual = client.contains(tw1);
+ assertEquals(false, actual);
+ }
+ @Test
+ void testContains2() {
+ client.addTweet(tw1);
+ client.addTweet(tw2);
+ var actual = client.contains(tw1);
+ assertEquals(true, actual);
+ }
+ @Test
+ void testContains3() {
+ client.addTweet(tw1);
+ var actual = client.contains(tw2);
+ assertEquals(false, actual);
+ }
+
+ @Test
+ void testRemove1a() {
+ var actual = client.remove(null);
+ assertEquals(0, actual);
+ }
+ @Test
+ void testRemove1b() {
+ var actual = client.remove(tw1);
+ assertEquals(0, actual);
+ }
+ @Test
+ void testRemove2a() {
+ client.addTweet(tw1);
+ var actual = client.remove(tw1);
+ assertEquals(0, actual);
+ }
+ @Test
+ void testRemove2b() {
+ client.addTweet(tw1);
+ client.addTweet(tw3);
+ var actual = client.remove(tw1);
+ assertEquals(7, actual);
+ }
+ @Test
+ void testRemove3() {
+ client.addTweet(tw1);
+ client.addTweet(tw3);
+ client.remove(tw1);
+ var actual = client.contains(tw1);
+ assertEquals(false, actual);
+ }
+ @Test
+ void testRemove4() {
+ client.addTweet(tw1);
+ client.addTweet(tw3);
+ client.remove(tw1);
+ var actual = client.getNrOfWords("271895613");
+ assertEquals(7, actual);
+ }
+
+ @Test
+ void testPostTweets1a() {
+ var actual = client.postTweets(null);
+ assertEquals(0,actual);
+ }
+ @Test
+ void testPostTweets1b() {
+ var actual = client.postTweets(this.defaultConnector);
+ assertEquals(0,actual);
+ }
+
+ @Test
+ void testPostTweets2a() {
+ client.addTweet(tw1);
+ var actual = client.postTweets(this.defaultConnector);
+ assertEquals(0,actual);
+ }
+ @Test
+ void testPostTweets2b() {
+ client.addTweet(tw1);
+ client.postTweets(this.defaultConnector);
+ var actual = client.getNrOfWords();
+ assertEquals(6,actual);
+ }
+ @Test
+ void testPostTweets3a() {
+ client.addTweet(tw1);
+ var actual = client.postTweets(this.connector);
+ assertEquals(6,actual);
+ }
+ @Test
+ void testPostTweets3b() {
+ client.addTweet(tw1);
+ client.postTweets(this.connector);
+ var actual = client.getNrOfWords("271895613");
+ assertEquals(0,actual);
+ }
+ @Test
+ void testPostTweets3c() {
+ client.addTweet(tw1);
+ client.postTweets(this.connector);
+ var actual = client.contains(tw1);
+ assertEquals(false,actual);
+ }
+ @Test
+ void testPostTweets3d() {
+ client.addTweet(tw1);
+ client.postTweets(this.connector);
+ var actual = client.getNrOfWords(tw1.getUser());
+ assertEquals(0,actual);
+ }
+ @Test
+ void size() {
+ }
+}
\ No newline at end of file
diff --git a/2021-WS-Testat-G2-TweetGen/src/G2_solution/TweetGenerator.java b/2021-WS-Testat-G2-TweetGen/src/G2_solution/TweetGenerator.java
new file mode 100644
index 0000000..17c54d6
--- /dev/null
+++ b/2021-WS-Testat-G2-TweetGen/src/G2_solution/TweetGenerator.java
@@ -0,0 +1,88 @@
+package G2_solution;
+
+import G2.ATweetGenerator;
+import twitter.TweetObject;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class TweetGenerator extends ATweetGenerator {
+
+ private Set tweetObjects;
+ private Map wordMap;
+
+ public TweetGenerator() {
+ tweetObjects = new HashSet<>();
+ wordMap = new HashMap<>();
+ }
+
+ @Override
+ public TweetObject addTweetCSV(String csvTweed) {
+ if(csvTweed == null) {return null;}
+ String[] parts = csvTweed.split(";");
+ if(parts.length != 4) {return null;}
+ TweetObject tweetObject = new TweetObject(parts[0], parts[1], parts[2]);
+ tweetObject.setUser(parts[3]);
+ tweetObject.setTags(super.extractTags(parts[2]));
+ return tweetObject;
+ }
+
+
+ @Override
+ public int addTweet(TweetObject tweet) {
+ if(tweet == null) {return 0;}
+ if(tweet.getText().length() == 0) {return 0;}
+ if(this.tweetObjects.add(tweet)) {
+ String[] parts = tweet.getText().split(" ");
+ Integer wordCount = this.wordMap.get(tweet.getUser());
+ if(wordCount == null) {wordCount = 0;}
+ this.wordMap.put(tweet.getUser(), wordCount + parts.length);
+ tweet.setWordCount(parts.length);
+ return parts.length;
+ }
+ else {return 0;}
+ }
+
+ @Override
+ public int getNrOfWords() {
+ return this.wordMap.values().stream().collect(Collectors.summingInt(value -> value));
+ }
+
+ @Override
+ public int getNrOfWords(String user) {
+ Integer wordCount = this.wordMap.get(user);
+ if(wordCount == null) {wordCount = 0;}
+ return wordCount;
+ }
+
+ @Override
+ public boolean contains(TweetObject tweet) {
+ return this.tweetObjects.contains(tweet);
+ }
+
+ @Override
+ public int remove(TweetObject tweet) {
+ Integer wordCount = 0;
+ if(this.tweetObjects.remove(tweet)) {
+ String user = tweet.getUser();
+ wordCount = this.wordMap.get(user) - tweet.getWordCount();
+ this.wordMap.put(user,wordCount);
+
+ }
+ return wordCount;
+ }
+
+ @Override
+ public int postTweets(ITwitterConnector connector) {
+ if(connector==null) return 0;
+ if(connector.testConnection()){
+ if(connector.postTweets(this.tweetObjects)){
+ int nrOfWords = getNrOfWords();
+ this.tweetObjects.clear();
+ this.wordMap.clear();
+ return nrOfWords;
+ };
+ }
+ return 0;
+ }
+}
diff --git a/2021-WS-Testat-G2-TweetGen/src/G2_solution/TweetGeneratorTest.java b/2021-WS-Testat-G2-TweetGen/src/G2_solution/TweetGeneratorTest.java
new file mode 100644
index 0000000..9181ba0
--- /dev/null
+++ b/2021-WS-Testat-G2-TweetGen/src/G2_solution/TweetGeneratorTest.java
@@ -0,0 +1,11 @@
+package G2_solution;
+
+import G2.ATweetGenerator;
+import G2.ATweetGeneratorTest;
+
+public class TweetGeneratorTest extends ATweetGeneratorTest {
+ @Override
+ protected ATweetGenerator getInstance() {
+ return new TweetGenerator();
+ }
+}
diff --git a/2021-WS-Testat-G2-TweetGen/src/twitter/AbstractTestClass.java b/2021-WS-Testat-G2-TweetGen/src/twitter/AbstractTestClass.java
new file mode 100644
index 0000000..433d5d7
--- /dev/null
+++ b/2021-WS-Testat-G2-TweetGen/src/twitter/AbstractTestClass.java
@@ -0,0 +1,15 @@
+package twitter;
+
+import org.junit.jupiter.api.BeforeEach;
+
+public abstract class AbstractTestClass {
+ protected T testObject;
+
+ protected abstract T getInstance();
+
+ @BeforeEach
+ void setUp() {
+ testObject = getInstance();
+ }
+
+}
diff --git a/2021-WS-Testat-G2-TweetGen/src/twitter/TweetObject.java b/2021-WS-Testat-G2-TweetGen/src/twitter/TweetObject.java
new file mode 100644
index 0000000..f19c82a
--- /dev/null
+++ b/2021-WS-Testat-G2-TweetGen/src/twitter/TweetObject.java
@@ -0,0 +1,86 @@
+package twitter;
+
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+
+public class TweetObject {
+ private String id;
+ private String created_at;
+ private String text;
+ private String user;
+ private int wordCount;
+ private List tags;
+
+ public TweetObject() {}
+
+ public TweetObject(String id, String created_at, String text) {
+ this.id = id;
+ this.created_at = created_at;
+ this.text = text;
+ this.tags = new LinkedList<>();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getCreated_at() {
+ return created_at;
+ }
+
+ public void setCreated_at(String created_at) {
+ this.created_at = created_at;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public int getWordCount() {return wordCount;}
+
+ public void setWordCount(int wordCount) {this.wordCount = wordCount;}
+
+ public List getTags() {
+ return tags;
+ }
+
+ public void setTags(List tags) {
+ this.tags.addAll(tags);
+ }
+
+ public void addTag(String tag) {this.tags.add(tag);}
+
+ @Override
+ public boolean equals(Object obj) {
+ if(obj == null) {return false;}
+ if(obj instanceof TweetObject) {
+ TweetObject that = (TweetObject) obj;
+ return this.id.equals(that.id);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return id + ';' + created_at + ';' + text + ';' + user;
+ }
+}
+
+
diff --git a/2022-SS Testat/.project b/2022-SS Testat/.project
new file mode 100644
index 0000000..7c9f605
--- /dev/null
+++ b/2022-SS Testat/.project
@@ -0,0 +1,17 @@
+
+
+ 2022-SS Testate
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/2022-SS Testat/2022-SS Testat-G1-Digital VC.pdf b/2022-SS Testat/2022-SS Testat-G1-Digital VC.pdf
new file mode 100644
index 0000000..ad3170c
Binary files /dev/null and b/2022-SS Testat/2022-SS Testat-G1-Digital VC.pdf differ
diff --git a/2022-SS Testat/2022-SS Testat-G2-TankApp.pdf b/2022-SS Testat/2022-SS Testat-G2-TankApp.pdf
new file mode 100644
index 0000000..304261a
Binary files /dev/null and b/2022-SS Testat/2022-SS Testat-G2-TankApp.pdf differ
diff --git a/2022-SS Testat/src/base/GasStation.java b/2022-SS Testat/src/base/GasStation.java
new file mode 100644
index 0000000..819f648
--- /dev/null
+++ b/2022-SS Testat/src/base/GasStation.java
@@ -0,0 +1,34 @@
+package base;
+
+import java.util.Objects;
+
+public class GasStation {
+ private String name;
+ private int id;
+
+ public GasStation(String name, int id) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if(this == o) { return true; }
+ if(o == null || getClass() != o.getClass()) { return false; }
+ GasStation station = (GasStation) o;
+ return id == station.id;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id);
+ }
+}
diff --git a/2022-SS Testat/src/base/Person.java b/2022-SS Testat/src/base/Person.java
new file mode 100644
index 0000000..5d05923
--- /dev/null
+++ b/2022-SS Testat/src/base/Person.java
@@ -0,0 +1,34 @@
+package base;
+
+import java.util.Objects;
+
+public class Person {
+ private String name;
+ private int id;
+
+ public Person(String name, int id) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if(this == o) { return true; }
+ if(o == null || getClass() != o.getClass()) { return false; }
+ Person student = (Person) o;
+ return id == student.id;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id);
+ }
+}
diff --git a/2022-SS Testat/src/base/Vaccination.java b/2022-SS Testat/src/base/Vaccination.java
new file mode 100644
index 0000000..fae2f93
--- /dev/null
+++ b/2022-SS Testat/src/base/Vaccination.java
@@ -0,0 +1,12 @@
+package base;
+
+public class Vaccination {
+
+ private int id;
+ private String title;
+
+ public Vaccination(int id, String title) {
+ this.id = id;
+ this.title = title;
+ }
+}
diff --git a/2022-SS Testat/src/solution_1/DigitalVaccinationRegister.java b/2022-SS Testat/src/solution_1/DigitalVaccinationRegister.java
new file mode 100644
index 0000000..4bb7c38
--- /dev/null
+++ b/2022-SS Testat/src/solution_1/DigitalVaccinationRegister.java
@@ -0,0 +1,65 @@
+package solution_1;
+
+import base.Person;
+import base.Vaccination;
+import testat_1.ADigitalVaccinationRegister;
+
+import java.util.*;
+import java.util.function.Consumer;
+
+public class DigitalVaccinationRegister extends ADigitalVaccinationRegister {
+
+ private Map> register = new HashMap<>();
+
+ @Override
+ public int size() {
+ return register.size();
+ }
+
+ @Override
+ public boolean add(Person person, Vaccination vaccination) {
+ if(person == null || vaccination == null) {return false;}
+ var vaccinationSet = register.get(person);
+ if(vaccinationSet == null) {
+ vaccinationSet = new HashSet<>();
+ register.put(person, vaccinationSet);
+ }
+ return vaccinationSet.add(vaccination);
+ }
+
+ @Override
+ public int contains(Person person) {
+ var vaccinationSet = register.get(person);
+ if(vaccinationSet == null) {return 0;}
+ return vaccinationSet.size();
+ }
+
+ @Override
+ public boolean contains(Person person, Vaccination vaccination) {
+ var vaccinationSet = register.get(person);
+ if(vaccinationSet == null) {return false;}
+ return vaccinationSet.contains(vaccination);
+ }
+
+ @Override
+ public Collection get(Person person) {
+ return register.get(person);
+ }
+
+ @Override
+ public boolean remove(Person person, Vaccination vaccination) {
+ var vaccinationSet = register.get(person);
+ if(vaccinationSet == null) {return false;}
+ return vaccinationSet.remove(vaccination);
+ }
+
+ @Override
+ public Collection remove(Person person) {
+ return register.remove(person);
+ }
+
+ @Override
+ public void forEach(Consumer> consumer) {
+ if(consumer != null) {register.values().forEach(consumer);}
+ }
+}
diff --git a/2022-SS Testat/src/solution_1/DigitalVaccinationRegisterTest.java b/2022-SS Testat/src/solution_1/DigitalVaccinationRegisterTest.java
new file mode 100644
index 0000000..5823e88
--- /dev/null
+++ b/2022-SS Testat/src/solution_1/DigitalVaccinationRegisterTest.java
@@ -0,0 +1,11 @@
+package solution_1;
+
+import testat_1.ADigitalVaccinationRegister;
+import testat_1.ADigitalVaccinationRegisterTest;
+
+public class DigitalVaccinationRegisterTest extends ADigitalVaccinationRegisterTest {
+ @Override
+ protected ADigitalVaccinationRegister getInstance() {
+ return new DigitalVaccinationRegister();
+ }
+}
diff --git a/2022-SS Testat/src/solution_2/LowPriceFinder.java b/2022-SS Testat/src/solution_2/LowPriceFinder.java
new file mode 100644
index 0000000..0bc2a40
--- /dev/null
+++ b/2022-SS Testat/src/solution_2/LowPriceFinder.java
@@ -0,0 +1,79 @@
+package solution_2;
+
+import base.GasStation;
+
+import java.util.*;
+import java.util.function.Predicate;
+
+public class LowPriceFinder extends testat_2.ALowPriceFinder {
+
+ private static class Entry {
+ GasStation station;
+ int avgPrice;
+
+ public Entry(GasStation station, int avgPrice) {
+ this.station = station;
+ this.avgPrice = avgPrice;
+ }
+ }
+
+ private Comparator comparator = Comparator.comparingInt(e -> e.avgPrice);
+
+ private List list;
+
+ public LowPriceFinder(int maxSize) {
+ super(maxSize);
+ list = new ArrayList<>();
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+ @Override
+ public int size(Predicate predicate) {
+ return (int) list.stream().filter(e -> predicate.test(e.station)).count();
+ }
+
+ @Override
+ public int add(GasStation station, int averagePrice) {
+ if(station == null || averagePrice <= 0) {return 0;}
+ int rank = this.contains(station);
+ if(rank > 0) {this.list.get(rank - 1).avgPrice = averagePrice;}
+ else {list.add(new Entry(station, averagePrice));}
+ list.sort(comparator);
+ if(list.size() > maxSize) {list.remove(maxSize);}
+ return contains(station);
+ }
+
+ @Override
+ public Collection getStations(int threshold) {
+ Set stationSet = new HashSet<>();
+ for(Entry e : list) {
+ if(e.avgPrice <= threshold) {stationSet.add(e.station);}
+ }
+ return stationSet;
+ }
+
+
+ @Override
+ public int contains(GasStation station) {
+ for(int i = 0; i < list.size(); i++) {
+ if(list.get(i).station.equals(station)) {return i + 1;}
+ }
+ return 0;
+ }
+
+ @Override
+ public int remove(GasStation station) {
+ int rank = this.contains(station);
+ if(rank > 0) {this.list.remove(rank - 1);}
+ return rank;
+ }
+
+ @Override
+ public GasStation get(int rank) {
+ return list.get(rank - 1).station;
+ }
+}
diff --git a/2022-SS Testat/src/solution_2/LowPriceFinderTest.java b/2022-SS Testat/src/solution_2/LowPriceFinderTest.java
new file mode 100644
index 0000000..2086122
--- /dev/null
+++ b/2022-SS Testat/src/solution_2/LowPriceFinderTest.java
@@ -0,0 +1,11 @@
+package solution_2;
+
+import testat_2.ALowPriceFinder;
+import testat_2.ALowPriceFinderTest;
+
+public class LowPriceFinderTest extends ALowPriceFinderTest {
+ @Override
+ protected ALowPriceFinder getInstance() {
+ return new LowPriceFinder(5);
+ }
+}
diff --git a/2022-SS Testat/src/testat_1/ADigitalVaccinationRegister.java b/2022-SS Testat/src/testat_1/ADigitalVaccinationRegister.java
new file mode 100644
index 0000000..f3f5eda
--- /dev/null
+++ b/2022-SS Testat/src/testat_1/ADigitalVaccinationRegister.java
@@ -0,0 +1,53 @@
+package testat_1;
+
+import base.Person;
+import base.Vaccination;
+
+import java.util.Collection;
+import java.util.function.Consumer;
+
+public abstract class ADigitalVaccinationRegister {
+
+ // Anzahl an gespeicherter Personen (mit mindestens einer Impfung)
+ public abstract int size();
+
+ // Fügt zur Person person die Impfung vaccination hinzu, falls Person
+ // != null und vaccination != null ist. Die Impfung wird nur einmal hinzugefüg
+ // Rückgabe: True falls Impfung hinzugefügt, false sonst
+ // Beachten Sie: Ein Person kann nur einmal enthalten sein
+ public abstract boolean add(Person person, Vaccination vaccination);
+
+ // Fügt alle Impfungen der Collection vaccinations zum Person Person hinzu, sofern sie noch
+ // nicht enthalten waren.
+ // Rückgabe: Anzahl an hinzugefügter Impfungen
+ public int addAll(Person person, Collection vaccinations) {
+ int counter = 0;
+ for(Vaccination v : vaccinations) {
+ if(this.add(person, v)) {counter++;}
+ }
+ return counter;
+ }
+
+ // Anzahl Impfungen, die Person person erhalten hat. Rückabe 0, falls Person nicht enthalten ist
+ public abstract int contains(Person person);
+
+ // True: Person hat Impfung vaccination erhalten
+ // False sonst
+ public abstract boolean contains(Person person, Vaccination vaccination);
+
+
+ // Rückgabe; Collection, die alle Impfungen der Person person enthält
+ // Sind zu Person person keine Impfungen enthalten, wird null zurückgegeben
+ public abstract Collection get(Person person);
+
+ // Löscht die Impfung vaccination der Person person aus der zugeordneten Collection
+ // Rückgabe = True falls Impfung erfolgreich entfernt wurde, false sonst
+ public abstract boolean remove(Person person, Vaccination vaccination);
+
+ // Löscht Person person aus der Collection
+ // Rückgabe = Alle Impfungen der Person person
+ public abstract Collection remove(Person person);
+
+ // Wendet consumer.action() auf alle gespeicherten Impfungen an
+ public abstract void forEach(Consumer> consumer);
+}
diff --git a/2022-SS Testat/src/testat_1/ADigitalVaccinationRegisterTest.java b/2022-SS Testat/src/testat_1/ADigitalVaccinationRegisterTest.java
new file mode 100644
index 0000000..62af62c
--- /dev/null
+++ b/2022-SS Testat/src/testat_1/ADigitalVaccinationRegisterTest.java
@@ -0,0 +1,301 @@
+package testat_1;
+
+import base.Person;
+import base.Vaccination;
+
+import java.util.Collection;
+import java.util.function.Consumer;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public abstract class ADigitalVaccinationRegisterTest {
+
+ Person s1 = new Person("person 1", 1);
+ Person s2 = new Person("person 2", 2);
+ Person s3 = new Person("person 3", 3);
+ Person s4 = new Person("person 4", 4);
+ Person s5 = new Person("person 1", 5);
+
+ Vaccination l1 = new Vaccination(1, "influenza");
+ Vaccination l2 = new Vaccination(2, "measls");
+ Vaccination l3 = new Vaccination(3, "FSME");
+ Vaccination l4 = new Vaccination(4, "SARS-CoV2");
+ Vaccination l5 = new Vaccination(5, "smallpox");
+
+
+ ADigitalVaccinationRegister register;
+ private int counter;
+ private Consumer> action = c -> {
+ counter += c.size();
+ };
+
+ @org.junit.jupiter.api.BeforeEach
+ void setUp() {
+ register = getInstance();
+ counter = 0;
+ }
+
+ protected abstract ADigitalVaccinationRegister getInstance();
+
+ @org.junit.jupiter.api.Test
+ void add1a() {
+ var actual = register.add(null, l1);
+ assertEquals(false, actual);
+ }
+
+ void add1b() {
+ var actual = register.add(s1, null);
+ assertEquals(false, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2a() {
+ var actual = register.add(s1, l1);
+ assertEquals(true, actual);
+ }
+
+
+ @org.junit.jupiter.api.Test
+ void add2b() {
+ register.add(s1, l1);
+ var actual = register.add(s1, l2);
+ assertEquals(true, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2c() {
+ register.add(s1, l1);
+ var actual = register.add(s1, l1);
+ assertEquals(false, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2d() {
+ addPersons();
+ var actual = register.add(s4, l1);
+ assertEquals(true, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2e() {
+ addPersons();
+ var actual = register.add(s1, l4);
+ assertEquals(true, actual);
+ }
+
+
+ @org.junit.jupiter.api.Test
+ void size1() {
+ var actual = register.size();
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void size2() {
+ addPersons();
+ var actual = register.size();
+ assertEquals(3, actual);
+ }
+
+ private void addPersons() {
+ register.add(s3, l1);
+ register.add(s2, l1);
+ register.add(s1, l1);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains1a() {
+ var actual = register.contains(s1, null);
+ assertEquals(false, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains1b() {
+ var actual = register.contains(s1, l1);
+ assertEquals(false, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains2a() {
+ addPersons();
+ var actual = register.contains(s1, l1);
+ assertEquals(true, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains2b() {
+ addPersons();
+ var actual = register.contains(s1, l2);
+ assertEquals(false, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains2c() {
+ addPersons();
+ register.add(s1, l5);
+ var actual = register.contains(s1, l5);
+ assertEquals(true, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains3a() {
+ var actual = register.contains(null);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains3b() {
+ var actual = register.contains(s1);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains4a() {
+ addPersons();
+ var actual = register.contains(s1);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains4b() {
+ addPersons();
+ register.add(s1, l4);
+ var actual = register.contains(s1);
+ assertEquals(2, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void get1() {
+ var actual = register.get(s1);
+ assertEquals(null, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void get2a() {
+ addPersons();
+ var actual = register.get(s1);
+ assertEquals(1, actual.size());
+ }
+
+ @org.junit.jupiter.api.Test
+ void get2b() {
+ addPersons();
+ register.add(s1, l4);
+ var actual = register.get(s1);
+ assertEquals(2, actual.size());
+ }
+
+ @org.junit.jupiter.api.Test
+ void get2c() {
+ addPersons();
+ register.add(s1, l4);
+ var actual = register.get(s1);
+ assertEquals(true, actual.contains(l1));
+ assertEquals(true, actual.contains(l4));
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove1() {
+ var actual = register.remove(s1);
+ assertEquals(null, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove2a() {
+ addPersons();
+ var actual = register.remove(s1);
+ assertEquals(1, actual.size());
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove2b() {
+ addPersons();
+ register.remove(s2);
+ var actual = register.contains(s2);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove2c() {
+ addPersons();
+ register.remove(s1);
+ var actual = register.contains(s2);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove3() {
+ addPersons();
+ register.add(s1, l2);
+ var actual = register.remove(s1);
+ assertEquals(2, actual.size());
+ }
+
+ @org.junit.jupiter.api.Test
+ void removeVaccination1a() {
+ var actual = register.remove(s1, null);
+ assertEquals(false, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void removeVaccination1b() {
+ var actual = register.remove(s1, l1);
+ assertEquals(false, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void removeVaccination2a() {
+ addPersons();
+ var actual = register.remove(s1, l1);
+ assertEquals(true, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void removeVaccination2b() {
+ addPersons();
+ var actual = register.remove(s1, l2);
+ assertEquals(false, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void removeVaccination2c() {
+ addPersons();
+ register.add(s1, l5);
+ var actual = register.remove(s1, l5);
+ assertEquals(true, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void removeVaccination3() {
+ addPersons();
+ register.add(s1, l5);
+ register.remove(s1, l5);
+ var actual = register.contains(s1, l5);
+ assertEquals(false, actual);
+ actual = register.contains(s1, l1);
+ assertEquals(true, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void ferEach1a() {
+ register.forEach(null);
+ var actual = 0;
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void ferEach1b() {
+ register.forEach(this.action);
+ var actual = counter;
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void ferEach2a() {
+ addPersons();
+ register.forEach(this.action);
+ var actual = counter;
+ assertEquals(3, actual);
+ }
+
+}
diff --git a/2022-SS Testat/src/testat_2/ALowPriceFinder.java b/2022-SS Testat/src/testat_2/ALowPriceFinder.java
new file mode 100644
index 0000000..9091973
--- /dev/null
+++ b/2022-SS Testat/src/testat_2/ALowPriceFinder.java
@@ -0,0 +1,48 @@
+package testat_2;
+
+import base.GasStation;
+
+import java.util.Collection;
+import java.util.function.Predicate;
+
+public abstract class ALowPriceFinder {
+ protected int maxSize;
+
+ public ALowPriceFinder(int maxSize) {this.maxSize = maxSize;}
+
+ // Anzahl an gespeicherten Tankstellen
+ public abstract int size();
+
+ // Liefert die GasStation auf Rang rank (Rang 1 = bester Platz)
+ public abstract GasStation get(int rank);
+
+ // Liefert den Rang von GasStation.
+ // Ist GasStation nicht enthalten, wird 0 zurückgegeben
+ // Hinweis: Platz 1 bedeutet Rang 1
+ public abstract int contains(GasStation station);
+
+ // Fügt die GasStation station mit Durchschnittspreis averagePrice hinzu, falls GasStation !=
+ // null und averagePrice > 0.
+ // Ist sie schon enthalten, wird der Preis auf averagePrice gesetzt
+ // Sind maxSize GasStations enthalten, wird die neue GasStation nur aufgenommen, wenn sie
+ // nicht der letzte in der Liste ist (wenn sie nicht den größten averagePrice hat)
+ // In diesem Fall wird die letzte GasStation gelöscht (sodass nicht mehr als maxGasStation
+ // in der Liste sind) und der neue GasStation aufgenommen
+ // Rückgabe: Rang in der HighaveragePrice-Liste; 0, falls der GasStation nicht hinzugefügt wurde
+ // Hinweis: Zur Vereinfachung sind alle averagePrice-Werte ungleich
+ // Beachten Sie: Ein GasStation kann nur einmal enthalten sein
+ public abstract int add(GasStation GasStation, int averagePrice);
+
+ // Liefert eine Collection von Tankstellen (GasStation), deren averagePrice <= threshold ist
+ // Rückgabe: Collection, ggf. leer (nicht null)
+ public abstract Collection getStations(int threshold);
+
+
+ // Löscht den GasStation GasStation aus der Liste.
+ // Rückgabe = Rang der GasStation, (0, falls GasStation nicht enthalten)
+ public abstract int remove(GasStation station);
+
+ // Anzahl an gespeicherter Tankstellen, die das Predicate predicate erfüllen
+ public abstract int size(Predicate predicate);
+
+}
diff --git a/2022-SS Testat/src/testat_2/ALowPriceFinderTest.java b/2022-SS Testat/src/testat_2/ALowPriceFinderTest.java
new file mode 100644
index 0000000..9552ceb
--- /dev/null
+++ b/2022-SS Testat/src/testat_2/ALowPriceFinderTest.java
@@ -0,0 +1,325 @@
+package testat_2;
+
+import base.GasStation;
+
+import java.util.function.Predicate;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public abstract class ALowPriceFinderTest {
+
+ GasStation p1 = new GasStation("Aral Amtzell", 1);
+ GasStation p2 = new GasStation("Aral Weingarten", 2);
+ GasStation p3 = new GasStation("Jet Weingarten", 3);
+ GasStation p4 = new GasStation("Shell Ravensburg", 4);
+ GasStation p5 = new GasStation("Shell Weingarten", 5);
+ GasStation p6 = new GasStation("Shell Wurzach", 6);
+
+ ALowPriceFinder hs;
+ private int counter;
+ private Predicate predicate = gasStation -> gasStation.getId() < 3;
+
+ @org.junit.jupiter.api.BeforeEach
+ void setUp() {
+ hs = getInstance();
+ }
+
+ protected abstract ALowPriceFinder getInstance();
+
+ @org.junit.jupiter.api.Test
+ void add1a() {
+ var actual = hs.add(null, 10);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add1b() {
+ var actual = hs.add(p1, 0);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add1c() {
+ var actual = hs.add(p1, -1);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2a() {
+ var actual = hs.add(p1, 10);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2b() {
+ hs.add(p1, 10);
+ var actual = hs.add(p1, 11);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2c() {
+ hs.add(p1, 10);
+ var actual = hs.add(p2, 9);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2d() {
+ hs.add(p1, 10);
+ hs.add(p2, 20);
+ var actual = hs.add(p1, 30);
+ assertEquals(2, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add2e() {
+ hs.add(p2, 5);
+ hs.add(p1, 10);
+ var actual = hs.add(p1, 2);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add3() {
+ hs.add(p3, 5);
+ hs.add(p2, 7);
+ var actual = hs.add(p1, 1);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add4() {
+ addStations();
+ var actual = hs.add(p4, 40);
+ assertEquals(4, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add5a() {
+ addStations();
+ hs.add(p4, 9);
+ hs.add(p1, 40);
+ var actual = hs.add(p1, 1);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void add6a() {
+ addStations();
+ hs.add(p4, 40);
+ hs.add(p5, 50); // Liste ist voll
+ var actual = hs.add(p6, 60); // neue Tanke wäre letzte
+ assertEquals(0, actual); // nicht aufnehmen
+ }
+
+ @org.junit.jupiter.api.Test
+ void add6b() {
+ addStations();
+ hs.add(p4, 40);
+ hs.add(p5, 50); // Liste ist voll
+ var actual = hs.add(p6, 45); // neue Tanke ist vorletzte
+ assertEquals(5, actual); // aufnehmen
+ actual = hs.contains(p5);
+ assertEquals(0, actual); // p5 ist rausgeflogen
+ }
+
+ @org.junit.jupiter.api.Test
+ void add6c() {
+ addStations();
+ hs.add(p4, 40);
+ hs.add(p5, 50);
+ var actual = hs.add(p1, 45);
+ assertEquals(4, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void size1() {
+ var actual = hs.size();
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void size2() {
+ addStations();
+ var actual = hs.size();
+ assertEquals(3, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void size3() {
+ addStations();
+ hs.add(p4, 1);
+ hs.add(p1, 8);
+ hs.add(p1, 2);
+ var actual = hs.size();
+ assertEquals(4, actual);
+ }
+
+ private void addStations() {
+ hs.add(p3, 30);
+ hs.add(p2, 20);
+ hs.add(p1, 10);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains1() {
+ var actual = hs.contains(p1);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains2() {
+ addStations();
+ var actual = hs.contains(p1);
+ assertEquals(1, actual);
+ actual = hs.contains(p2);
+ assertEquals(2, actual);
+ actual = hs.contains(p3);
+ assertEquals(3, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains3() {
+ addStations();
+ hs.add(p4, 2);
+ hs.add(p5, 1);
+ var actual = hs.contains(p4);
+ assertEquals(2, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains4a() {
+ addStations();
+ hs.add(p4, 19);
+ var actual = hs.contains(p4);
+ assertEquals(2, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void contains4b() {
+ addStations();
+ hs.add(p4, 11);
+ hs.add(p1, 30);
+ var actual = hs.contains(p4);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void get1() {
+ addStations();
+ var actual = hs.get(1);
+ assertEquals(p1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void get2() {
+ addStations();
+ var actual = hs.get(3);
+ assertEquals(p3, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove1() {
+ var actual = hs.remove(p1);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove2a() {
+ addStations();
+ var actual = hs.remove(p1);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove2b() {
+ addStations();
+ hs.remove(p2);
+ var actual = hs.contains(p2);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove2c() {
+ addStations();
+ hs.remove(p1);
+ var actual = hs.contains(p2);
+ assertEquals(1, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove3a() {
+ addStations();
+ hs.add(p4, 1);
+ var actual = hs.remove(p1);
+ assertEquals(2, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void remove3b() {
+ addStations();
+ hs.add(p4, 25);
+ var actual = hs.remove(p4);
+ assertEquals(3, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void sizePred1a() {
+ var actual = hs.size(null);
+ assertEquals(0, actual);
+ }
+
+ void sizePred1b() {
+ var actual = hs.size(predicate);
+ assertEquals(0, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void sizePred2a() {
+ addStations();
+ hs.add(p4, 7);
+ hs.add(p5, 19);
+ var actual = hs.size(predicate);
+ assertEquals(2, actual);
+ }
+
+ @org.junit.jupiter.api.Test
+ void getStations1a() {
+ var actual = hs.getStations(0);
+ assertEquals(0, actual.size());
+ }
+
+ void getStations1b() {
+ var actual = hs.getStations(25);
+ assertEquals(0, actual.size());
+ }
+
+ @org.junit.jupiter.api.Test
+ void getStations2a() {
+ addStations();
+ hs.add(p4, 7);
+ hs.add(p5, 31);
+ var actual = hs.getStations(21);
+ assertEquals(3, actual.size());
+ }
+
+ @org.junit.jupiter.api.Test
+ void getStations2b() {
+ addStations();
+ hs.add(p4, 7);
+ hs.add(p5, 31);
+ var stationCollection = hs.getStations(21);
+ var actual = stationCollection.contains(p1);
+ assertEquals(true, actual);
+ actual = stationCollection.contains(p2);
+ assertEquals(true, actual);
+ actual = stationCollection.contains(p4);
+ assertEquals(true, actual);
+ actual = stationCollection.contains(p3);
+ assertEquals(false, actual);
+ actual = stationCollection.contains(p5);
+ assertEquals(false, actual);
+ }
+}
+