Compare commits

...

2 Commits

Author SHA1 Message Date
chris 9928ee5ed7 Finish Project 2 years ago
chris 527cec763e Hinzufügen von den ws21-ss22 Testaten 3 years ago
  1. 3
      .idea/.gitignore
  2. 17
      .idea/libraries/junit_jupiter.xml
  3. 9
      .idea/markdown.xml
  4. 4
      .idea/misc.xml
  5. 8
      .idea/modules.xml
  6. 13
      .idea/oop_crashkurs.iml
  7. 6
      .idea/vcs.xml
  8. 17
      2021-WS-Testat-G1-TagAnalyzer-LV/.project
  9. BIN
      2021-WS-Testat-G1-TagAnalyzer-LV/2021-WS Testat-G1-TweetAnalyzer.pdf
  10. 58
      2021-WS-Testat-G1-TagAnalyzer-LV/src/G1/ATweetTagAnalyser.java
  11. 252
      2021-WS-Testat-G1-TagAnalyzer-LV/src/G1/ATweetTagAnalyserTest.java
  12. 100
      2021-WS-Testat-G1-TagAnalyzer-LV/src/G1_solution/TweetTagAnalyzer.java
  13. 11
      2021-WS-Testat-G1-TagAnalyzer-LV/src/G1_solution/TweetTagAnalyzerTest.java
  14. 15
      2021-WS-Testat-G1-TagAnalyzer-LV/src/twitter/AbstractTestClass.java
  15. 86
      2021-WS-Testat-G1-TagAnalyzer-LV/src/twitter/TweetObject.java
  16. 17
      2021-WS-Testat-G2-TweetGen/.project
  17. BIN
      2021-WS-Testat-G2-TweetGen/2021-WS Testat-G2-TwitterClient.pdf
  18. 86
      2021-WS-Testat-G2-TweetGen/src/G2/ATweetGenerator.java
  19. 296
      2021-WS-Testat-G2-TweetGen/src/G2/ATweetGeneratorTest.java
  20. 88
      2021-WS-Testat-G2-TweetGen/src/G2_solution/TweetGenerator.java
  21. 11
      2021-WS-Testat-G2-TweetGen/src/G2_solution/TweetGeneratorTest.java
  22. 15
      2021-WS-Testat-G2-TweetGen/src/twitter/AbstractTestClass.java
  23. 86
      2021-WS-Testat-G2-TweetGen/src/twitter/TweetObject.java
  24. 17
      2022-SS Testat/.project
  25. BIN
      2022-SS Testat/2022-SS Testat-G1-Digital VC.pdf
  26. BIN
      2022-SS Testat/2022-SS Testat-G2-TankApp.pdf
  27. 34
      2022-SS Testat/src/base/GasStation.java
  28. 34
      2022-SS Testat/src/base/Person.java
  29. 12
      2022-SS Testat/src/base/Vaccination.java
  30. 65
      2022-SS Testat/src/solution_1/DigitalVaccinationRegister.java
  31. 11
      2022-SS Testat/src/solution_1/DigitalVaccinationRegisterTest.java
  32. 79
      2022-SS Testat/src/solution_2/LowPriceFinder.java
  33. 11
      2022-SS Testat/src/solution_2/LowPriceFinderTest.java
  34. 53
      2022-SS Testat/src/testat_1/ADigitalVaccinationRegister.java
  35. 301
      2022-SS Testat/src/testat_1/ADigitalVaccinationRegisterTest.java
  36. 48
      2022-SS Testat/src/testat_2/ALowPriceFinder.java
  37. 325
      2022-SS Testat/src/testat_2/ALowPriceFinderTest.java
  38. 0
      SimpleArrayMap/.idea/.gitignore
  39. 12
      SimpleArrayMap/.idea/SimpleArrayMap.iml
  40. 17
      SimpleArrayMap/.idea/libraries/junit_jupiter.xml
  41. 9
      SimpleArrayMap/.idea/markdown.xml
  42. 6
      SimpleArrayMap/.idea/misc.xml
  43. 8
      SimpleArrayMap/.idea/modules.xml
  44. 6
      SimpleArrayMap/.idea/vcs.xml
  45. 44
      SimpleArrayMap/.idea/workspace.xml
  46. 3
      SimpleArrayMap/src/solution/SimpleMapTest.java
  47. 13
      SimpleArrayMap/src/testat/ASimpleMapTest.java
  48. 4
      SimpleArrayMap/src/testat/SimpleArrayMap.java
  49. 1
      SimpleLinkedList/src/solution/SimpleLinkedList.java

3
.idea/.gitignore

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

17
.idea/libraries/junit_jupiter.xml

@ -0,0 +1,17 @@
<component name="libraryTable">
<library name="junit.jupiter" type="repository">
<properties maven-id="org.junit.jupiter:junit-jupiter:5.8.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.0/junit-jupiter-5.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.0/junit-jupiter-api-5.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.0/junit-platform-commons-1.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.0/junit-jupiter-params-5.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.0/junit-jupiter-engine-5.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.0/junit-platform-engine-1.8.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

9
.idea/markdown.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettings">
<enabledExtensions>
<entry key="MermaidLanguageExtension" value="false" />
<entry key="PlantUMLLanguageExtension" value="false" />
</enabledExtensions>
</component>
</project>

4
.idea/misc.xml

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project>

8
.idea/modules.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/oop_crashkurs.iml" filepath="$PROJECT_DIR$/.idea/oop_crashkurs.iml" />
</modules>
</component>
</project>

13
.idea/oop_crashkurs.iml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/SimpleArrayMap" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/SimpleLinkedList" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="junit.jupiter" level="project" />
</component>
</module>

6
.idea/vcs.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

17
2021-WS-Testat-G1-TagAnalyzer-LV/.project

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>2021-WS-Testat-G1-TagAnalyzer-LV</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

BIN
2021-WS-Testat-G1-TagAnalyzer-LV/2021-WS Testat-G1-TweetAnalyzer.pdf

Binary file not shown.

58
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<TweetObject> 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<Integer> action);
public abstract Set<String> getTags();
// ----------------------------------------------------
// Delegate methods
// ----------------------------------------------------
}

252
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<String> interestingTags = new HashSet<>();
private ATweetTagAnalyser preparation;
protected Predicate<TweetObject> 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<String> 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<Integer> action = s -> counter.getAndAdd(s);
// analyser.addTags(tw1);
// analyser.addTags(tw2);
// var actual = analyser.forEach(action);
// assertEquals(4, actual);
// assertEquals(6, counter.intValue());
// }
}

100
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<String, Integer> tagCounter;
private Set<String> interestingTags;
public TweetTagAnalyzer(Set<String> interestingTags) {
this.interestingTags = interestingTags;
}
public TweetTagAnalyzer() {
this.interestingTags = null;
this.tagCounter = new HashMap<>();
}
@Override
public int prepareTweetObject(TweetObject tweet, Predicate<TweetObject> filter) {
if(tweet == null) {return 0;}
if(!filter.test(tweet)) {return 0;}
List<String> 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<Integer> action) {
// this.tagCounter.values().forEach(v -> action.accept(v));
// return this.tagCounter.size();
// }
@Override
public Set<String> getTags() {
return null;
}
}

11
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();
}
}

15
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<T> {
protected T testObject;
protected abstract T getInstance();
@BeforeEach
void setUp() {
testObject = getInstance();
}
}

86
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<String> 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<String> getTags() {
return tags;
}
public void setTags(List<String> 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;
}
}

17
2021-WS-Testat-G2-TweetGen/.project

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>2021-WS-Testat-G2-TweetGen-LV</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

BIN
2021-WS-Testat-G2-TweetGen/2021-WS Testat-G2-TwitterClient.pdf

Binary file not shown.

86
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<TweetObject> 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<String> csvTweedCollection) {
Set<TweetObject> collectedTweeds = new HashSet<>();
csvTweedCollection.forEach(csvTweet -> collectedTweeds.add(this.addTweetCSV(csvTweet)));
return addTweets(collectedTweeds);
}
public int addTweets(Collection<TweetObject> tweetObjects) {
int counter = 0;
for(TweetObject t : tweetObjects) {
counter += this.addTweet(t);
}
return counter;
}
protected static List<String> extractTags(String text) {
List<String> 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;
}
}

296
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<TweetObject> tweetObjects) {
return false;
}
};
private ATweetGenerator.ITwitterConnector connector = new ATweetGenerator.ITwitterConnector() {
@Override
public boolean testConnection() {
return true;
}
@Override
public boolean postTweets(Collection<TweetObject> 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() {
}
}

88
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<TweetObject> tweetObjects;
private Map<String, Integer> 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;
}
}

11
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();
}
}

15
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<T> {
protected T testObject;
protected abstract T getInstance();
@BeforeEach
void setUp() {
testObject = getInstance();
}
}

86
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<String> 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<String> getTags() {
return tags;
}
public void setTags(List<String> 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;
}
}

17
2022-SS Testat/.project

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>2022-SS Testate</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

BIN
2022-SS Testat/2022-SS Testat-G1-Digital VC.pdf

Binary file not shown.

BIN
2022-SS Testat/2022-SS Testat-G2-TankApp.pdf

Binary file not shown.

34
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);
}
}

34
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);
}
}

12
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;
}
}

65
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<Person, Set<Vaccination>> 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<Vaccination> 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<Vaccination> remove(Person person) {
return register.remove(person);
}
@Override
public void forEach(Consumer<Collection<Vaccination>> consumer) {
if(consumer != null) {register.values().forEach(consumer);}
}
}

11
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();
}
}

79
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<Entry> comparator = Comparator.comparingInt(e -> e.avgPrice);
private List<Entry> list;
public LowPriceFinder(int maxSize) {
super(maxSize);
list = new ArrayList<>();
}
@Override
public int size() {
return list.size();
}
@Override
public int size(Predicate<GasStation> 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<GasStation> getStations(int threshold) {
Set<GasStation> 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;
}
}

11
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);
}
}

53
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<Vaccination> 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<Vaccination> 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<Vaccination> remove(Person person);
// Wendet consumer.action() auf alle gespeicherten Impfungen an
public abstract void forEach(Consumer<Collection<Vaccination>> consumer);
}

301
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<Collection<Vaccination>> 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);
}
}

48
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<GasStation> 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<GasStation> predicate);
}

325
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<GasStation> 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);
}
}

0
SimpleArrayMap/.idea/.gitignore

12
SimpleArrayMap/.idea/SimpleArrayMap.iml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="junit.jupiter" level="project" />
</component>
</module>

17
SimpleArrayMap/.idea/libraries/junit_jupiter.xml

@ -0,0 +1,17 @@
<component name="libraryTable">
<library name="junit.jupiter" type="repository">
<properties maven-id="org.junit.jupiter:junit-jupiter:5.8.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.0/junit-jupiter-5.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.0/junit-jupiter-api-5.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.0/junit-platform-commons-1.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.0/junit-jupiter-params-5.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.0/junit-jupiter-engine-5.8.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.0/junit-platform-engine-1.8.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

9
SimpleArrayMap/.idea/markdown.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettings">
<enabledExtensions>
<entry key="MermaidLanguageExtension" value="false" />
<entry key="PlantUMLLanguageExtension" value="false" />
</enabledExtensions>
</component>
</project>

6
SimpleArrayMap/.idea/misc.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
</project>

8
SimpleArrayMap/.idea/modules.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/SimpleArrayMap.iml" filepath="$PROJECT_DIR$/.idea/SimpleArrayMap.iml" />
</modules>
</component>
</project>

6
SimpleArrayMap/.idea/vcs.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

44
SimpleArrayMap/.idea/workspace.xml

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="82cca40d-6a74-4c74-97be-88548b3f41df" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2FS5DB4h1ZHgsFjtInThNWkKFeC" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../SimpleLinkedList" />
<property name="project.structure.last.edited" value="Project" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="82cca40d-6a74-4c74-97be-88548b3f41df" name="Changes" comment="" />
<created>1664472523385</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1664472523385</updated>
</task>
<servers />
</component>
</project>

3
SimpleArrayMap/src/solution/SimpleMapTest.java

@ -2,12 +2,13 @@ package solution;
import testat.ASimpleMapTest;
import testat.ISimpleMap;
import solution.SimpleArrayMap;
public class SimpleMapTest extends ASimpleMapTest{
@Override
protected ISimpleMap<String, String> getInstance() {
return new SimpleArrayMap<>(5);
return new SimpleArrayMap<String, String>(5);
}
}

13
SimpleArrayMap/src/testat/ASimpleMapTest.java

@ -1,13 +1,14 @@
package testat;
import static org.junit.Assert.assertEquals;
import java.util.function.Consumer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.function.Consumer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import testat.ISimpleMap;
public abstract class ASimpleMapTest {
ISimpleMap<String, String> map;
@ -60,7 +61,7 @@ public abstract class ASimpleMapTest {
void testadd4() {
add3();
map.put("4", "Vier");
map.put("5", "Fünf");
map.put("5", "Fnf");
map.remove("3");
map.put("6", "Sechs");
@ -71,7 +72,7 @@ public abstract class ASimpleMapTest {
actual = map.get("4");
assertEquals("Vier", actual);
actual = map.get("5");
assertEquals("Fünf", actual);
assertEquals("Fnf", actual);
actual = map.get("6");
assertEquals("Sechs", actual);
}

4
SimpleArrayMap/src/testat/SimpleArrayMap.java

@ -0,0 +1,4 @@
package src.testat;
public class SimpleArrayMap {
}

1
SimpleLinkedList/src/solution/SimpleLinkedList.java

@ -9,6 +9,7 @@ public class SimpleLinkedList<E> extends AbstractSimpleList<E> {
firstNode = null;
size = 0;
}
@Override
public int size() {

Loading…
Cancel
Save