diff options
| author | shedaniel <daniel@shedaniel.me> | 2024-04-16 00:43:25 +0900 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2024-04-16 00:43:25 +0900 |
| commit | 5b03bcea21701b4dd7b0ae40aec7f448fd3513f3 (patch) | |
| tree | b2082db7c8a52f6c1a77197a7b6fe4bb43914407 /runtime/src/test | |
| parent | a01b505ffcdb3ab1c4cf8fcc3aeaaef06c517f82 (diff) | |
| parent | 2af03ce523320bab4b4086f0661f80e466c14477 (diff) | |
| download | RoughlyEnoughItems-5b03bcea21701b4dd7b0ae40aec7f448fd3513f3.tar.gz RoughlyEnoughItems-5b03bcea21701b4dd7b0ae40aec7f448fd3513f3.tar.bz2 RoughlyEnoughItems-5b03bcea21701b4dd7b0ae40aec7f448fd3513f3.zip | |
Merge remote-tracking branch 'origin/feature/9.2' into feature/11.1
# Conflicts:
# default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.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/FilteringScreen.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/gui/performance/PerformanceScreen.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/basewidgets/PanelWidget.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/PaginatedEntryListWidget.java
Diffstat (limited to 'runtime/src/test')
| -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()); + } +} |
