3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-25 07:40:13 +01:00

Use more obvious/broken-down test cases for topological sort tests

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-02-13 19:20:53 -05:00
Ursprung 6e41ce7f15
Commit 9444cfa70f

Datei anzeigen

@ -14,49 +14,64 @@ import org.junit.jupiter.api.Test;
class PluginDependencyUtilsTest {
private static final PluginDescription NO_DEPENDENCY_1_EXAMPLE = testDescription("example");
private static final PluginDescription NEVER_DEPENDED = testDescription("and-again");
private static final PluginDescription SOFT_DEPENDENCY_EXISTS = testDescription("soft",
ImmutableList.of(new PluginDependency("example", "", true)));
private static final PluginDescription SOFT_DEPENDENCY_DOES_NOT_EXIST = testDescription("fluffy",
ImmutableList.of(new PluginDependency("i-dont-exist", "", false)));
private static final PluginDescription MULTI_DEPENDENCY = testDescription("multi-depend",
ImmutableList.of(
new PluginDependency("example", "", false)
)
);
private static final PluginDescription TEST_WITH_DUPLICATE_DEPEND = testDescription("dup-depend",
ImmutableList.of(
new PluginDependency("multi-depend", "", false)
)
);
private static final PluginDescription NO_DEPENDENCY = testDescription("trivial");
private static final PluginDescription NO_DEPENDENCY_2 = testDescription("trivial2");
private static final PluginDescription HAS_DEPENDENCY_1 = testDescription("dependent1",
new PluginDependency("trivial", null, false));
private static final PluginDescription HAS_DEPENDENCY_2 = testDescription("dependent2",
new PluginDependency("dependent1", null, false));
private static final PluginDescription HAS_DEPENDENCY_3 = testDescription("dependent3",
new PluginDependency("trivial", null, false));
private static final PluginDescription CIRCULAR_DEPENDENCY_1 = testDescription("circle",
ImmutableList.of(new PluginDependency("oval", "", false)));
new PluginDependency("oval", "", false));
private static final PluginDescription CIRCULAR_DEPENDENCY_2 = testDescription("oval",
ImmutableList.of(new PluginDependency("circle", "", false)));
private static final ImmutableList<PluginDescription> EXPECTED = ImmutableList.of(
NEVER_DEPENDED,
NO_DEPENDENCY_1_EXAMPLE,
MULTI_DEPENDENCY,
TEST_WITH_DUPLICATE_DEPEND,
SOFT_DEPENDENCY_DOES_NOT_EXIST,
SOFT_DEPENDENCY_EXISTS
);
new PluginDependency("circle", "", false));
@Test
void sortCandidates() throws Exception {
void sortCandidatesTrivial() throws Exception {
List<PluginDescription> descriptionList = new ArrayList<>();
descriptionList.add(NO_DEPENDENCY_1_EXAMPLE);
descriptionList.add(NEVER_DEPENDED);
descriptionList.add(SOFT_DEPENDENCY_DOES_NOT_EXIST);
descriptionList.add(SOFT_DEPENDENCY_EXISTS);
descriptionList.add(MULTI_DEPENDENCY);
descriptionList.add(TEST_WITH_DUPLICATE_DEPEND);
descriptionList.sort(Comparator.comparing(PluginDescription::getId));
assertEquals(descriptionList, PluginDependencyUtils.sortCandidates(descriptionList));
}
assertEquals(EXPECTED, PluginDependencyUtils.sortCandidates(descriptionList));
@Test
void sortCandidatesSingleton() throws Exception {
List<PluginDescription> plugins = ImmutableList.of(NO_DEPENDENCY);
assertEquals(plugins, PluginDependencyUtils.sortCandidates(plugins));
}
@Test
void sortCandidatesBasicDependency() throws Exception {
List<PluginDescription> plugins = ImmutableList.of(HAS_DEPENDENCY_1, NO_DEPENDENCY);
List<PluginDescription> expected = ImmutableList.of(NO_DEPENDENCY, HAS_DEPENDENCY_1);
assertEquals(expected, PluginDependencyUtils.sortCandidates(plugins));
}
@Test
void sortCandidatesNestedDependency() throws Exception {
List<PluginDescription> plugins = ImmutableList.of(HAS_DEPENDENCY_1, HAS_DEPENDENCY_2,
NO_DEPENDENCY);
List<PluginDescription> expected = ImmutableList.of(NO_DEPENDENCY, HAS_DEPENDENCY_1,
HAS_DEPENDENCY_2);
assertEquals(expected, PluginDependencyUtils.sortCandidates(plugins));
}
@Test
void sortCandidatesTypical() throws Exception {
List<PluginDescription> plugins = ImmutableList.of(HAS_DEPENDENCY_2, NO_DEPENDENCY_2,
HAS_DEPENDENCY_1, NO_DEPENDENCY);
List<PluginDescription> expected = ImmutableList.of(NO_DEPENDENCY, HAS_DEPENDENCY_1,
HAS_DEPENDENCY_2, NO_DEPENDENCY_2);
assertEquals(expected, PluginDependencyUtils.sortCandidates(plugins));
}
@Test
void sortCandidatesMultiplePluginsDependentOnOne() throws Exception {
List<PluginDescription> plugins = ImmutableList.of(HAS_DEPENDENCY_3, HAS_DEPENDENCY_1,
NO_DEPENDENCY);
List<PluginDescription> expected = ImmutableList.of(NO_DEPENDENCY, HAS_DEPENDENCY_3,
HAS_DEPENDENCY_1);
assertEquals(expected, PluginDependencyUtils.sortCandidates(plugins));
}
@Test
@ -65,14 +80,10 @@ class PluginDependencyUtilsTest {
assertThrows(IllegalStateException.class, () -> PluginDependencyUtils.sortCandidates(descs));
}
private static PluginDescription testDescription(String id) {
return testDescription(id, ImmutableList.of());
}
private static PluginDescription testDescription(String id, List<PluginDependency> dependencies) {
private static PluginDescription testDescription(String id, PluginDependency... dependencies) {
return new VelocityPluginDescription(
id, "tuxed", "0.1", null, null, ImmutableList.of(),
dependencies, null
ImmutableList.copyOf(dependencies), null
);
}
}