test enhc: cll insert after & before - more test scenarios
This commit is contained in:
@@ -10,7 +10,6 @@ import org.junit.jupiter.params.converter.ConvertWith;
|
|||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.CsvSource;
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.jupiter.params.provider.MethodSources;
|
|
||||||
|
|
||||||
import appointmentplanner.StringArrayConverter;
|
import appointmentplanner.StringArrayConverter;
|
||||||
import appointmentplanner.customlist.CustomLinkedListImpl;
|
import appointmentplanner.customlist.CustomLinkedListImpl;
|
||||||
@@ -68,7 +67,7 @@ public class CustomLinkedListTest {
|
|||||||
assertThat(list.contains(toRemove)).isFalse();
|
assertThat(list.contains(toRemove)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static enum LlGetPosition {
|
private static enum LlItemPosition {
|
||||||
BEFORE, AFTER
|
BEFORE, AFTER
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,16 +75,16 @@ public class CustomLinkedListTest {
|
|||||||
|
|
||||||
private static Stream<Arguments> getAfterBeforeData() {
|
private static Stream<Arguments> getAfterBeforeData() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.of(someBasicDataSet, LlGetPosition.BEFORE, "MUJ", "O"),
|
Arguments.of(someBasicDataSet, LlItemPosition.BEFORE, "MUJ", "O"),
|
||||||
Arguments.of(someBasicDataSet, LlGetPosition.AFTER, "MUJ", "BOZE"),
|
Arguments.of(someBasicDataSet, LlItemPosition.AFTER, "MUJ", "BOZE"),
|
||||||
Arguments.of(someBasicDataSet, LlGetPosition.AFTER, "O", "MUJ"),
|
Arguments.of(someBasicDataSet, LlItemPosition.AFTER, "O", "MUJ"),
|
||||||
Arguments.of(someBasicDataSet, LlGetPosition.AFTER, "BOZE", null),
|
Arguments.of(someBasicDataSet, LlItemPosition.AFTER, "BOZE", null),
|
||||||
Arguments.of(someBasicDataSet, LlGetPosition.BEFORE, "O", null));
|
Arguments.of(someBasicDataSet, LlItemPosition.BEFORE, "O", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("getAfterBeforeData")
|
@MethodSource("getAfterBeforeData")
|
||||||
void cllGetAfter_shouldReturnCorrectResult(String[] data, LlGetPosition position, String reference,
|
void cllGetAfter_shouldReturnCorrectResult(String[] data, LlItemPosition position, String reference,
|
||||||
String expectedResult) {
|
String expectedResult) {
|
||||||
|
|
||||||
CustomLinkedList<String> list = new CustomLinkedListImpl<>();
|
CustomLinkedList<String> list = new CustomLinkedListImpl<>();
|
||||||
@@ -107,4 +106,49 @@ public class CustomLinkedListTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Stream<Arguments> insertBeforeAfterData() {
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of(someBasicDataSet, "DOPRDELE", "BOZE", LlItemPosition.AFTER),
|
||||||
|
Arguments.of(new String[] { "Ahoj" }, "vole", "Ahoj", LlItemPosition.AFTER),
|
||||||
|
Arguments.of(new String[] { "ahoj" }, "More", "ahoj", LlItemPosition.BEFORE),
|
||||||
|
Arguments.of(new String[] { "A", "tak", "se", "pochcal", "posral", "a", "jeste", "nakonec", "serval" },
|
||||||
|
"vyblil",
|
||||||
|
"posral", LlItemPosition.BEFORE),
|
||||||
|
Arguments.of(new String[] { "A", "tak", "se", "pochcal", "posral", "a", "jeste", "nakonec", "serval" },
|
||||||
|
"vyblil",
|
||||||
|
"posral", LlItemPosition.AFTER),
|
||||||
|
Arguments.of(someBasicDataSet, "PREMOCNY", "BOZE", LlItemPosition.BEFORE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("insertBeforeAfterData")
|
||||||
|
void cllInsertAfterBefore_shouldInsertItemSuccessfully(String[] initData, String toInsert, String reference,
|
||||||
|
LlItemPosition position) {
|
||||||
|
|
||||||
|
CustomLinkedList<String> list = initPopulaterList(initData);
|
||||||
|
|
||||||
|
switch (position) {
|
||||||
|
case AFTER:
|
||||||
|
list.insertAfter(reference, toInsert);
|
||||||
|
assertThat(list.getAfter(reference)).isEqualTo(toInsert);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BEFORE:
|
||||||
|
list.insertBefore(reference, toInsert);
|
||||||
|
assertThat(list.getBefore(reference)).isEqualTo(toInsert);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fail("Incorrect position parameter");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomLinkedList<String> initPopulaterList(String[] initData) {
|
||||||
|
CustomLinkedList<String> list = new CustomLinkedListImpl<>();
|
||||||
|
Stream.of(initData).forEach(list::add);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user