diff options
| author | shedaniel <daniel@shedaniel.me> | 2024-04-16 01:12:21 +0900 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2024-04-16 01:12:21 +0900 |
| commit | 6788d2b65edfd1b24f84bd92fbf66ec4098537d6 (patch) | |
| tree | 1d09b18e7a3fe20c6526d125c6e65cff7f594ece /runtime/src/test/java/CyclingListTest.java | |
| parent | e26d21c36b425389e5ff1078a7017f23c7159d1b (diff) | |
| parent | 7717b20cd2f41731bf94ce4c8ee44d3ed63e86f7 (diff) | |
| download | RoughlyEnoughItems-6788d2b65edfd1b24f84bd92fbf66ec4098537d6.tar.gz RoughlyEnoughItems-6788d2b65edfd1b24f84bd92fbf66ec4098537d6.tar.bz2 RoughlyEnoughItems-6788d2b65edfd1b24f84bd92fbf66ec4098537d6.zip | |
Merge remote-tracking branch 'origin/feature/11.1' into feature/12.1
# Conflicts:
# api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java
# api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/WidgetWithBounds.java
# gradle.properties
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigureCategoriesScreen.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringAddRuleScreen.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringCategoriesEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/NoFilteringCategoriesEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/NoFilteringEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/RecipeScreenTypeEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/Menu.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/generic/OptionEntriesScreen.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayCompositeWidget.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayTooltipComponent.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DynamicErrorFreeEntryListWidget.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TabContainerWidget.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/PanelWidget.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/PaginatedEntryListWidget.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/trash/TrashWidget.java
# runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
Diffstat (limited to 'runtime/src/test/java/CyclingListTest.java')
| -rw-r--r-- | runtime/src/test/java/CyclingListTest.java | 338 |
1 files changed, 338 insertions, 0 deletions
diff --git a/runtime/src/test/java/CyclingListTest.java b/runtime/src/test/java/CyclingListTest.java new file mode 100644 index 000000000..bc688c463 --- /dev/null +++ b/runtime/src/test/java/CyclingListTest.java @@ -0,0 +1,338 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import me.shedaniel.rei.impl.client.util.CyclingList; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CyclingListTest { + @Test + void testSimple() { + CyclingList<String> list = CyclingList.of(List.of("a", "b", "c"), () -> "empty"); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("b", list.next()); + + assert list.currentIndex() == 1; + assert list.nextIndex() == 2; + assert list.previousIndex() == 0; + assertEquals("b", list.peek()); + assertEquals("c", list.next()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("a", list.next()); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("c", list.previous()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("b", list.previous()); + + assert list.currentIndex() == 1; + assert list.nextIndex() == 2; + assert list.previousIndex() == 0; + assertEquals("b", list.peek()); + assertEquals("a", list.previous()); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("c", list.previous()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("a", list.next()); + } + + @Test + void testMutable() { + CyclingList.Mutable<String> list = CyclingList.ofMutable(new ArrayList<>(List.of("a", "b", "c")), () -> "empty"); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("b", list.next()); + + assert list.currentIndex() == 1; + assert list.nextIndex() == 2; + assert list.previousIndex() == 0; + assertEquals("b", list.peek()); + assertEquals("c", list.next()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("a", list.next()); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("c", list.previous()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + + list.add("d"); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 3; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("d", list.next()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 0; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("a", list.next()); + + list.add("e"); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 4; + assertEquals("a", list.peek()); + assertEquals("e", list.previous()); + + assert list.currentIndex() == 4; + assert list.nextIndex() == 0; + assert list.previousIndex() == 3; + assertEquals("e", list.peek()); + assertEquals("d", list.previous()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 4; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("c", list.previous()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 3; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("d", list.next()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 4; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("e", list.next()); + } + + @Test + void testImmutableAppendMutableManual() { + CyclingList.Mutable<String> mutable = CyclingList.ofMutable(() -> "empty"); + CyclingList<String> list = CyclingList.concat(List.of(CyclingList.of(List.of("a", "b", "c"), () -> "empty"), mutable), () -> "empty"); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("b", list.next()); + + assert list.currentIndex() == 1; + assert list.nextIndex() == 2; + assert list.previousIndex() == 0; + assertEquals("b", list.peek()); + assertEquals("c", list.next()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("a", list.next()); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("c", list.previous()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + + mutable.add("d"); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 3; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("d", list.next()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 0; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("a", list.next()); + + mutable.add("e"); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 4; + assertEquals("a", list.peek()); + assertEquals("e", list.previous()); + + assert list.currentIndex() == 4; + assert list.nextIndex() == 0; + assert list.previousIndex() == 3; + assertEquals("e", list.peek()); + assertEquals("d", list.previous()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 4; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("c", list.previous()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 3; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("d", list.next()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 4; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("e", list.next()); + } + + @Test + void testImmutableAppendMutable() { + CyclingList.Mutable<String> list = CyclingList.ofMutable(CyclingList.of(List.of("a", "b", "c"), () -> "empty"), () -> "empty"); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("b", list.next()); + + assert list.currentIndex() == 1; + assert list.nextIndex() == 2; + assert list.previousIndex() == 0; + assertEquals("b", list.peek()); + assertEquals("c", list.next()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("a", list.next()); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 2; + assertEquals("a", list.peek()); + assertEquals("c", list.previous()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 0; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + + list.add("d"); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 3; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("d", list.next()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 0; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("a", list.next()); + + list.add("e"); + + assert list.currentIndex() == 0; + assert list.nextIndex() == 1; + assert list.previousIndex() == list.size() - 1; + assert list.previousIndex() == 4; + assertEquals("a", list.peek()); + assertEquals("e", list.previous()); + + assert list.currentIndex() == 4; + assert list.nextIndex() == 0; + assert list.previousIndex() == 3; + assertEquals("e", list.peek()); + assertEquals("d", list.previous()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 4; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("c", list.previous()); + + assert list.currentIndex() == 2; + assert list.nextIndex() == 3; + assert list.previousIndex() == 1; + assertEquals("c", list.peek()); + assertEquals("d", list.next()); + + assert list.currentIndex() == 3; + assert list.nextIndex() == 4; + assert list.previousIndex() == 2; + assertEquals("d", list.peek()); + assertEquals("e", list.next()); + } +} |
