diff --git a/assignment/src/test/java/appointmentplanner/customlist/api/CustomLinkedListTest.java b/assignment/src/test/java/appointmentplanner/customlist/api/CustomLinkedListTest.java index 9fa839d..7884b66 100644 --- a/assignment/src/test/java/appointmentplanner/customlist/api/CustomLinkedListTest.java +++ b/assignment/src/test/java/appointmentplanner/customlist/api/CustomLinkedListTest.java @@ -10,7 +10,6 @@ import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.MethodSources; import appointmentplanner.StringArrayConverter; import appointmentplanner.customlist.CustomLinkedListImpl; @@ -68,7 +67,7 @@ public class CustomLinkedListTest { assertThat(list.contains(toRemove)).isFalse(); } - private static enum LlGetPosition { + private static enum LlItemPosition { BEFORE, AFTER } @@ -76,16 +75,16 @@ public class CustomLinkedListTest { private static Stream getAfterBeforeData() { return Stream.of( - Arguments.of(someBasicDataSet, LlGetPosition.BEFORE, "MUJ", "O"), - Arguments.of(someBasicDataSet, LlGetPosition.AFTER, "MUJ", "BOZE"), - Arguments.of(someBasicDataSet, LlGetPosition.AFTER, "O", "MUJ"), - Arguments.of(someBasicDataSet, LlGetPosition.AFTER, "BOZE", null), - Arguments.of(someBasicDataSet, LlGetPosition.BEFORE, "O", null)); + Arguments.of(someBasicDataSet, LlItemPosition.BEFORE, "MUJ", "O"), + Arguments.of(someBasicDataSet, LlItemPosition.AFTER, "MUJ", "BOZE"), + Arguments.of(someBasicDataSet, LlItemPosition.AFTER, "O", "MUJ"), + Arguments.of(someBasicDataSet, LlItemPosition.AFTER, "BOZE", null), + Arguments.of(someBasicDataSet, LlItemPosition.BEFORE, "O", null)); } @ParameterizedTest @MethodSource("getAfterBeforeData") - void cllGetAfter_shouldReturnCorrectResult(String[] data, LlGetPosition position, String reference, + void cllGetAfter_shouldReturnCorrectResult(String[] data, LlItemPosition position, String reference, String expectedResult) { CustomLinkedList list = new CustomLinkedListImpl<>(); @@ -107,4 +106,49 @@ public class CustomLinkedListTest { } + private static Stream 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 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 initPopulaterList(String[] initData) { + CustomLinkedList list = new CustomLinkedListImpl<>(); + Stream.of(initData).forEach(list::add); + return list; + } + }