From 05de803468e0e049f568b8fe1a87632c4ce83e28 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 18:50:05 +0100 Subject: [PATCH 1/7] implemented basic louder function for one step louder --- .../java/device/radioPlayer/RadioPlayer.java | 12 ++---------- .../device/radioPlayer/RadioPlayerTest.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index e2cc7d1..f3b6b04 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -29,20 +29,12 @@ public class RadioPlayer implements Device { @Override public void louder() { - if(Lautstaerke < 100) { - Lautstaerke += 1; - } else { - Lautstaerke = 100; - } + Lautstaerke+=1; } @Override public void quieter() { - if(Lautstaerke > 0) { - Lautstaerke -= 1; - } else { - Lautstaerke = 0; - } + } @Override public int getVolume() { diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 3f2c716..e261242 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -16,7 +16,23 @@ class RadioPlayerTest { RadioPlayer rp = new RadioPlayer(); + @ParameterizedTest + @MethodSource("quieterLouderOptions") + void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) { + int volume = testRp.getLautstaerke(); + assertThat(volume).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream quieterLouderOptions() { + RadioPlayer rp1 = new RadioPlayer(); + rp1.setLautstaerke(0); + rp1.louder(); + return Stream.of( + Arguments.of("Test for one louder", rp1, 1) + ); + } +/* @Test void louder() { rp.setLautstaerke(0); @@ -43,7 +59,7 @@ class RadioPlayerTest { rp.quieter(); assertThat(rp.getLautstaerke()).isEqualTo(0); } -/* + Jenkins config test @Test void getVolume() { From d8ae7a98973226fef1e74c19e88f05845a088821 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 19:09:34 +0100 Subject: [PATCH 2/7] implemented Test for louder max --- src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index e261242..6952005 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -25,10 +25,14 @@ class RadioPlayerTest { static Stream quieterLouderOptions() { RadioPlayer rp1 = new RadioPlayer(); + RadioPlayer rp2 = new RadioPlayer(); rp1.setLautstaerke(0); rp1.louder(); + rp2.setLautstaerke(100); + rp2.louder(); return Stream.of( - Arguments.of("Test for one louder", rp1, 1) + Arguments.of("Test for one louder", rp1, 1), + Arguments.of("Test for one louder", rp2, 100) ); } From 43854c18e513abe5431cd8cf5f7efc5173e44c48 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 19:18:36 +0100 Subject: [PATCH 3/7] added productive Code for louder if volume is max --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 +++- src/test/java/device/radioPlayer/RadioPlayerTest.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index f3b6b04..d731482 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -29,7 +29,9 @@ public class RadioPlayer implements Device { @Override public void louder() { - Lautstaerke+=1; + if(Lautstaerke < 100){ + Lautstaerke+=1;} + else Lautstaerke = 100; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 6952005..e5ba0fc 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -31,8 +31,8 @@ class RadioPlayerTest { rp2.setLautstaerke(100); rp2.louder(); return Stream.of( - Arguments.of("Test for one louder", rp1, 1), - Arguments.of("Test for one louder", rp2, 100) + Arguments.of("Test for one step louder", rp1, 1), + Arguments.of("Test for max louder", rp2, 100) ); } From 81035aa6d7855bc190ba8af86831aa07b27da886 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 19:22:32 +0100 Subject: [PATCH 4/7] Test for quieter --- src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index e5ba0fc..1239eb5 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -26,13 +26,17 @@ class RadioPlayerTest { static Stream quieterLouderOptions() { RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); + RadioPlayer rp3 = new RadioPlayer(); rp1.setLautstaerke(0); rp1.louder(); rp2.setLautstaerke(100); rp2.louder(); + rp3.setLautstaerke(1); + rp3.quieter(); return Stream.of( Arguments.of("Test for one step louder", rp1, 1), - Arguments.of("Test for max louder", rp2, 100) + Arguments.of("Test for max louder", rp2, 100), + Arguments.of("Test for one step quieter", rp3, 0) ); } From 72e58fcef962f703952ea5b8fd6e1a0140b83e88 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 19:23:58 +0100 Subject: [PATCH 5/7] added productive Code for function quieter --- src/main/java/device/radioPlayer/RadioPlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index d731482..5c051b8 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -36,7 +36,7 @@ public class RadioPlayer implements Device { @Override public void quieter() { - + Lautstaerke-=1; } @Override public int getVolume() { From 820cfc8cfa9003bc7288acdbf0afa575a5f2aed4 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 19:27:16 +0100 Subject: [PATCH 6/7] added Test for quieter if volume is 0 --- src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 1239eb5..e7e2410 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -27,16 +27,20 @@ class RadioPlayerTest { RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); RadioPlayer rp3 = new RadioPlayer(); + RadioPlayer rp4 = new RadioPlayer(); rp1.setLautstaerke(0); rp1.louder(); rp2.setLautstaerke(100); rp2.louder(); rp3.setLautstaerke(1); rp3.quieter(); + rp4.setLautstaerke(0); + rp4.quieter(); return Stream.of( Arguments.of("Test for one step louder", rp1, 1), Arguments.of("Test for max louder", rp2, 100), - Arguments.of("Test for one step quieter", rp3, 0) + Arguments.of("Test for one step quieter", rp3, 0), + Arguments.of("Test for min quieter", rp4, 0) ); } From e8a5a507dfd85ef5696a8287f3c403cc66ce7a01 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 19:32:21 +0100 Subject: [PATCH 7/7] productive for quieter() if volume is zero --- src/main/java/device/radioPlayer/RadioPlayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 5c051b8..ca8897d 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -29,14 +29,14 @@ public class RadioPlayer implements Device { @Override public void louder() { - if(Lautstaerke < 100){ - Lautstaerke+=1;} + if(Lautstaerke < 100){Lautstaerke+=1;} else Lautstaerke = 100; } @Override public void quieter() { - Lautstaerke-=1; + if(Lautstaerke > 0){Lautstaerke-=1;} + else Lautstaerke = 0; } @Override public int getVolume() {