Browse Source

Merge commit 'd57de4380a416d172bb46c247ccf7c57db7d67fd' into HEAD

feature-pr-getVolume
Jenkins 3 years ago
parent
commit
4bfe172f67
  1. 42
      src/main/java/device/usbPlayer/UsbPlayer.java
  2. 108
      src/test/java/device/usbPlayer/UsbPlayerTest.java

42
src/main/java/device/usbPlayer/UsbPlayer.java

@ -104,6 +104,20 @@ public class UsbPlayer implements Device {
} }
} }
public void Louder_10(){
Lautstaerke += 10;
if (Lautstaerke > 100) {
Lautstaerke = 100;
}
}
public void quieter_10(){
Lautstaerke -= 10;
if (Lautstaerke < 0) {
Lautstaerke = 0;
}
}
@Override @Override
public int getVolume() { public int getVolume() {
return 0; return 0;
@ -169,4 +183,32 @@ public class UsbPlayer implements Device {
} }
public int findSong(String songName){
int songIndex =-1, index=-1;
String song;
for (int j = 0; j < getPlaylist().size(); j++) {
song = getPlaylist().get(j);
songIndex=song.toLowerCase().indexOf(songName.toLowerCase());
if (songIndex != -1) {
index = j;
break;
}
}
return index;
}
public boolean GoTo(String songName){
if(findSong(songName) != -1){
playTrack = getPlaylist().get(findSong(songName));//songName;
return true;
}
else
//playTrack = songName;
return false;
}
} }

108
src/test/java/device/usbPlayer/UsbPlayerTest.java

@ -114,7 +114,6 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
); );
} }
////////////////
@ParameterizedTest @ParameterizedTest
@MethodSource("PrevOptions") @MethodSource("PrevOptions")
void PrevTest(String testName, UsbPlayer inputPlay, String expectedResult) { void PrevTest(String testName, UsbPlayer inputPlay, String expectedResult) {
@ -137,4 +136,111 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
); );
} }
@ParameterizedTest
@MethodSource("louder_10_Options")
void louder_10_Test(String testName, UsbPlayer inputPlay, int expectedResult) {
int volumeNum = inputPlay.getLautstaerke();
assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> louder_10_Options() {
UsbPlayer up1 = new UsbPlayer();
up1.Louder_10();
UsbPlayer up2 = new UsbPlayer();
for (int i = 0; i <= 3; i++) {
up2.Louder_10();
}
up2.quieter_10();
UsbPlayer up3 = new UsbPlayer();
up3.setLautstaerke(100);
up3.Louder_10();
return Stream.of(
Arguments.of("Volume was 0, should be 10 ", up1, 10),
Arguments.of("Volume was 0, should be 30 ", up2, 30),
Arguments.of("Volume was 100, should stay 100 ", up3, 100)
);
}
@ParameterizedTest
@MethodSource("quieter_10_Options")
void quieter_10_Test(String testName, UsbPlayer inputPlay, int expectedResult) {
int volumeNum = inputPlay.getLautstaerke();
assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> quieter_10_Options() {
UsbPlayer up1 = new UsbPlayer();
up1.setLautstaerke(10);
up1.quieter_10();
UsbPlayer up2 = new UsbPlayer();
up2.setLautstaerke(50);
for (int i = 0; i < 3; i++) {
up2.quieter_10();
}
UsbPlayer up3 = new UsbPlayer();
up3.quieter_10();
return Stream.of(
Arguments.of("Volume was 10, should be 0 ", up1, 0),
Arguments.of("Volume was 50, should be 20 ", up2, 20),
Arguments.of("Volume was 0, should stay 0 ", up3, 0)
);
}
@ParameterizedTest
@MethodSource("FindSongOptions")
void findSongTest(String testName, int inputPlay, int expectedResult) {
//first case: the song is not in the Album
// int songLoc1 = inputPlay.findSong("song 4");
assertThat(inputPlay).describedAs(testName).isEqualTo(expectedResult);
//Second Case: the song is in the album
// int songLoc2 = inputPlay.findSong("Musik 02");
assertThat(inputPlay).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> FindSongOptions() {
UsbPlayer up1 = new UsbPlayer();
return Stream.of(
Arguments.of("The song is not in the Album", up1.findSong("song 4"), -1),
Arguments.of("The song is in the Album", up1.findSong("Musik 02"), 1),
Arguments.of("Name of the Song is in lower case :", up1.findSong("musik 02"), 1),
Arguments.of("Name of the Song is in upper case :", up1.findSong("MUSIK 02"), 1)
);
}
@ParameterizedTest
@MethodSource("GoToOptions")
void GoToTest(String testName, UsbPlayer inputPlay, String expectedResult) {
String current_Track = inputPlay.getPlayTrack();
assertThat(current_Track).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> GoToOptions() {
UsbPlayer up1 = new UsbPlayer();
up1.GoTo("Musik 03.mp3");
UsbPlayer up2 = new UsbPlayer();
up2.GoTo("Musik 04.mp3");
UsbPlayer up3 = new UsbPlayer();
up3.GoTo("Musik 02");
UsbPlayer up4 = new UsbPlayer();
up4.next();
up4.GoTo("Musik");
return Stream.of(
Arguments.of("Go to Song : Musik 03.mp3 ", up1, "Musik 03.mp3"),
Arguments.of("Go to Song that is not in the Album: Musik 04.mp3 ", up2, "Musik 01.mp3"),
Arguments.of("Go to Song without writing the full Name : Musik 02 ", up3, "Musik 02.mp3"),
Arguments.of("Go to Song and write a Name that many songs starts with : Musik", up4, "Musik 01.mp3")
);
}
} }
Loading…
Cancel
Save