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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repositories {
}

dependencies {
implementation 'junit:junit:4.13.1'
implementation 'junit:junit:4.13.1'
implementation 'org.junit.jupiter:junit-jupiter:5.7.0'
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
9 changes: 9 additions & 0 deletions src/main/java/de/htwberlin/madlib/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.htwberlin.madlib;

public class App {
public static void main(String[] args){
MadLib p = new MadLib();
System.out.println(p.create());

}
}
29 changes: 28 additions & 1 deletion src/main/java/de/htwberlin/madlib/MadLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,34 @@ public class MadLib {

public String create() {
// TODO: implement this method
int i =0;
int j=0;
String ad;
String ver;
String ver2;
String fa;
String sen;

return ""; // TODO: this is only here so that the code can be compiled, please replace it with your result
i = (int)( Math.random()* 7 ) ; ad = getADJECTIVES()[i];
i = (int)( Math.random()* 8 ) ; ver = getVERBS()[i];
j = (int)( Math.random()* 8 ) ; if( i ==j){ j = (int) ( Math.random()* 8 );} ver2 = getVERBS()[j];
i = (int)( Math.random()* 8 ) ; fa = getFamousPersons()[i];

sen = "Java programming is so "+ ad +"! It makes me so excited all the time because I love to "+ ver+"." +
" Stay hydrated and "+ver2+" like you are "+fa+"!\n";

return sen; // TODO: this is only here so that the code can be compiled, please replace it with your result
}

public static String[] getADJECTIVES() {
return ADJECTIVES;
}

public static String[] getFamousPersons() {
return FAMOUS_PERSONS;
}

public static String[] getVERBS() {
return VERBS;
Comment on lines +31 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

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

Die Methoden wären streng genommen nicht wirklich notwendig gewesen. Die Klasse kann von der create() Methode aus prima direkt auf die Arrays zugreifen.

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

import org.junit.Test;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.Arrays;

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

public class MadLibTest {
static final String[] ADJECTIVES = new String[]{"amazing", "exciting", "excellent", "emotional", "easy", "difficult", "curious", "beautiful"};
static final String[] VERBS = new String[]{"concentrate", "compete", "battle", "cry", "develop", "dance", "destroy", "dream", "sleep"};
static final String[] FAMOUS_PERSONS = new String[]{"Frodo", "Voldemort", "John Wick", "Winnie Pooh", "Thor", "Iron Man", "Hulk", "Supergirl", "Wonder Woman"};

boolean checker (String sen ,String[] spl){
for(String i : spl)
if (sen.contains(i)){
return true;
}
return false;
}


@Test
@DisplayName("should check the inserted variables")
public void createTest() {

MadLib p = new MadLib();


String actual = p.create();
assertTrue(checker(actual, MadLibTest.ADJECTIVES));
assertTrue(checker(actual, MadLib.VERBS));
assertTrue(checker(actual, MadLib.FAMOUS_PERSONS));
}



@Test
@DisplayName("should check the inserted variables")
public void createTest2() {
MadLib p = new MadLib();
String expected = "Java programming is so ";
String actual = p.create();
assertTrue(actual != null && actual.startsWith("Java programming is so "));
}

}