From 333995bef52f4bc6ef4371c352cf249a7397840c Mon Sep 17 00:00:00 2001 From: Rame Madah Date: Fri, 14 May 2021 16:21:26 +0200 Subject: [PATCH 1/4] project completed with tests --- build.gradle | 3 ++ src/main/java/de/htwberlin/madlib/App.java | 9 +++++ src/main/java/de/htwberlin/madlib/MadLib.java | 29 +++++++++++++- .../java/de/htwberlin/madlib/MadLibTest.java | 40 +++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/htwberlin/madlib/App.java create mode 100644 src/test/java/de/htwberlin/madlib/MadLibTest.java diff --git a/build.gradle b/build.gradle index a89c2a1..77414db 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/src/main/java/de/htwberlin/madlib/App.java b/src/main/java/de/htwberlin/madlib/App.java new file mode 100644 index 0000000..cd304f3 --- /dev/null +++ b/src/main/java/de/htwberlin/madlib/App.java @@ -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()); + + } +} diff --git a/src/main/java/de/htwberlin/madlib/MadLib.java b/src/main/java/de/htwberlin/madlib/MadLib.java index 7b6f3d0..0d37a0d 100644 --- a/src/main/java/de/htwberlin/madlib/MadLib.java +++ b/src/main/java/de/htwberlin/madlib/MadLib.java @@ -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; } } diff --git a/src/test/java/de/htwberlin/madlib/MadLibTest.java b/src/test/java/de/htwberlin/madlib/MadLibTest.java new file mode 100644 index 0000000..ce8bf34 --- /dev/null +++ b/src/test/java/de/htwberlin/madlib/MadLibTest.java @@ -0,0 +1,40 @@ +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.*; + +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"}; + + + + + @Test + @DisplayName("should check the inserted variables") + public void createTest() { + MadLib p = new MadLib(); + String expected = "Java programming is so "+ Arrays.toString(ADJECTIVES) +"! It makes me so excited " + + "all the time because I love to "+ Arrays.toString(VERBS) +"." + + " Stay hydrated and "+ Arrays.toString(VERBS) +" like you are "+ Arrays.toString(FAMOUS_PERSONS) +"!\n"; + String actual = p.create(); + + assertEquals(expected, actual); + + } + @ParameterizedTest + @ValueSource(strings = "Java programming is so") + public void createTest(String ex) { + MadLib p = new MadLib(); + String actual = p.create(); + assertTrue( actual != null && actual.contains("Java programming is so")); + + } +} \ No newline at end of file From be7a43448200a2c93a38d757f32ac700766b5982 Mon Sep 17 00:00:00 2001 From: Rame Madah Date: Fri, 14 May 2021 17:26:36 +0200 Subject: [PATCH 2/4] tests update 0.1 --- .../java/de/htwberlin/madlib/MadLibTest.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/test/java/de/htwberlin/madlib/MadLibTest.java b/src/test/java/de/htwberlin/madlib/MadLibTest.java index ce8bf34..261d70a 100644 --- a/src/test/java/de/htwberlin/madlib/MadLibTest.java +++ b/src/test/java/de/htwberlin/madlib/MadLibTest.java @@ -9,14 +9,11 @@ import static org.junit.jupiter.api.Assertions.*; -class MadLibTest { +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"}; - - - @Test @DisplayName("should check the inserted variables") public void createTest() { @@ -25,16 +22,25 @@ public void createTest() { "all the time because I love to "+ Arrays.toString(VERBS) +"." + " Stay hydrated and "+ Arrays.toString(VERBS) +" like you are "+ Arrays.toString(FAMOUS_PERSONS) +"!\n"; String actual = p.create(); - assertEquals(expected, actual); + } + + @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.contains(expected)); } - @ParameterizedTest + + /* @ParameterizedTest @ValueSource(strings = "Java programming is so") - public void createTest(String ex) { + public void createTest3(String ex) { MadLib p = new MadLib(); String actual = p.create(); assertTrue( actual != null && actual.contains("Java programming is so")); - } + }*/ } \ No newline at end of file From 718e5a82b62cac0681aeefe94c0e9500a891e4a7 Mon Sep 17 00:00:00 2001 From: Rame Madah Date: Fri, 14 May 2021 18:40:41 +0200 Subject: [PATCH 3/4] test update 0.2 --- src/test/java/de/htwberlin/madlib/MadLibTest.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/test/java/de/htwberlin/madlib/MadLibTest.java b/src/test/java/de/htwberlin/madlib/MadLibTest.java index 261d70a..5c53da8 100644 --- a/src/test/java/de/htwberlin/madlib/MadLibTest.java +++ b/src/test/java/de/htwberlin/madlib/MadLibTest.java @@ -17,10 +17,11 @@ public class MadLibTest { @Test @DisplayName("should check the inserted variables") public void createTest() { + MadLib p = new MadLib(); - String expected = "Java programming is so "+ Arrays.toString(ADJECTIVES) +"! It makes me so excited " + - "all the time because I love to "+ Arrays.toString(VERBS) +"." + - " Stay hydrated and "+ Arrays.toString(VERBS) +" like you are "+ Arrays.toString(FAMOUS_PERSONS) +"!\n"; + String expected = "Java programming is so "+ ADJECTIVES +"! It makes me so excited " + + "all the time because I love to "+ VERBS +"." + + " Stay hydrated and "+ VERBS +" like you are "+ FAMOUS_PERSONS +"!\n"; String actual = p.create(); assertEquals(expected, actual); } @@ -35,12 +36,4 @@ public void createTest2() { assertTrue(actual != null && actual.contains(expected)); } - /* @ParameterizedTest - @ValueSource(strings = "Java programming is so") - public void createTest3(String ex) { - MadLib p = new MadLib(); - String actual = p.create(); - assertTrue( actual != null && actual.contains("Java programming is so")); - - }*/ } \ No newline at end of file From b85e1991c05af13282862f4cd3850055e37d94d4 Mon Sep 17 00:00:00 2001 From: Rame Madah Date: Sat, 15 May 2021 01:04:03 +0200 Subject: [PATCH 4/4] test update 0.3 done --- .../java/de/htwberlin/madlib/MadLibTest.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/test/java/de/htwberlin/madlib/MadLibTest.java b/src/test/java/de/htwberlin/madlib/MadLibTest.java index 5c53da8..929f0ba 100644 --- a/src/test/java/de/htwberlin/madlib/MadLibTest.java +++ b/src/test/java/de/htwberlin/madlib/MadLibTest.java @@ -14,26 +14,37 @@ public class MadLibTest { 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 expected = "Java programming is so "+ ADJECTIVES +"! It makes me so excited " + - "all the time because I love to "+ VERBS +"." + - " Stay hydrated and "+ VERBS +" like you are "+ FAMOUS_PERSONS +"!\n"; + + String actual = p.create(); - assertEquals(expected, actual); + 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.contains(expected)); + assertTrue(actual != null && actual.startsWith("Java programming is so ")); } } \ No newline at end of file