Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ repositories {
}

dependencies {
implementation 'org.junit.jupiter:junit-jupiter:5.7.0'
implementation 'junit:junit:4.13.1'
Comment on lines +13 to +14
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eigentlich nicht notwendig, da die Dependencies bereits da waren.

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/de/htwberlin/madlib/MadLib.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package de.htwberlin.madlib;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class MadLib {

static final String[] ADJECTIVES = new String[]{"amazing", "exciting", "excellent", "emotional", "easy", "difficult", "curious", "beautiful"};
Expand All @@ -8,7 +13,24 @@ public class MadLib {

public String create() {
// TODO: implement this method
String random_adjective = randomWordOf(ADJECTIVES);
String random_verb = randomWordOf(VERBS);
String other_random_verb = randomWordOf(VERBS);
String random_famous_person= randomWordOf(FAMOUS_PERSONS);

return ""; // TODO: this is only here so that the code can be compiled, please replace it with your result
String toReturnString = "Java programming is so "
+ random_adjective
+" ! It makes me so excited all the time because I love to "
+ random_verb
+ ". Stay hydrated and "
+ other_random_verb
+ " like you are "
+ random_famous_person
+ " !";
return toReturnString; // TODO: this is only here so that the code can be compiled, please replace it with your result
}
private String randomWordOf (String[] targetArray){
return targetArray[(int)Math.floor(Math.random()*targetArray.length)];
}

}
31 changes: 31 additions & 0 deletions src/test/java/de/htwberlin/madlib/MadLibTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.htwberlin.madlib;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;

class MadLibTest {
MadLib testObject = new MadLib();
@Test
@DisplayName("The result string should starts with \"Java programming is so\" ")
void startWithPattern() {
String expectedStartWith = "Java programming is so";
boolean actual = testObject.create().startsWith(expectedStartWith);
assertEquals(true,actual);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ginge etwas einfacher mit:

Suggested change
assertEquals(true,actual);
assertTrue(actual);

}

@Test
@DisplayName("Should contains adjective from ADJECTIVES array, verbs from VERBS array, and famous person from FAMOUS-PERSONS")
void containRequiredWords(){
String returnString = testObject.create();
boolean expected = true;
boolean actual1 = Arrays.stream(MadLib.ADJECTIVES).anyMatch(i -> returnString.contains(i));
boolean actual2 = Arrays.stream(MadLib.VERBS).anyMatch(i -> returnString.contains(i));
boolean actual3 = Arrays.stream(MadLib.FAMOUS_PERSONS).anyMatch(i -> returnString.contains(i));
boolean actual = actual1 && actual2 && actual3;
assertEquals(expected,actual);
}
}