hw5
This commit is contained in:
parent
59be76cf17
commit
d6dcb72b1b
2 changed files with 38 additions and 15 deletions
|
@ -11,7 +11,6 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<junit.platform.version>1.7.0-M1</junit.platform.version>
|
||||
<junit.jupiter.version>5.6.2</junit.jupiter.version>
|
||||
<junit.vintage.version>5.6.2</junit.vintage.version>
|
||||
<junit.version>4.13.1</junit.version>
|
||||
</properties>
|
||||
|
||||
|
@ -93,12 +92,6 @@
|
|||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<version>${junit.vintage.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<reporting>
|
||||
<plugins>
|
||||
|
|
|
@ -6,9 +6,9 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class CollectionUtilsTest {
|
||||
public class CollectionUtilsTest {
|
||||
|
||||
private static <T extends Comparable<T>> void checkSort(List<T> source, List<T> expected) {
|
||||
List<T> target = new ArrayList<>(source);
|
||||
|
@ -20,14 +20,44 @@ class CollectionUtilsTest {
|
|||
return Arrays.asList(elements);
|
||||
}
|
||||
|
||||
private static <T> ArrayList<T> empty() {
|
||||
return new ArrayList<T>();
|
||||
@Test
|
||||
public void checkSorted() {
|
||||
assertThrows(IllegalArgumentException.class, () -> CollectionUtils.sort(null));
|
||||
checkSort(new ArrayList<Integer>(), new ArrayList<>());
|
||||
checkSort(list(0, 1, 2, 3, 4), list(0, 1, 2, 3, 4));
|
||||
checkSort(list(8, 4, 5, 6, 7), list(4, 5, 6, 7, 8));
|
||||
checkSort(list(8, 7), list(7, 8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkSorted() {
|
||||
checkSort(empty(), empty());
|
||||
checkSort(list(0, 1, 2, 3, 4), list(0, 1, 2, 3, 4));
|
||||
checkSort(list(8, 4, 5, 6, 7), list(4, 5, 6, 7, 8));
|
||||
public void checkStability() {
|
||||
class DummyAllSame implements Comparable<DummyAllSame> {
|
||||
@Override
|
||||
public int compareTo(DummyAllSame o) {
|
||||
return 0; // all are same
|
||||
}
|
||||
}
|
||||
|
||||
final DummyAllSame a = new DummyAllSame();
|
||||
final DummyAllSame b = new DummyAllSame();
|
||||
final DummyAllSame c = new DummyAllSame();
|
||||
|
||||
final List<DummyAllSame> list = Arrays.asList(a, b, c);
|
||||
CollectionUtils.sort(list);
|
||||
|
||||
assertSame(a, list.get(0));
|
||||
assertSame(b, list.get(1));
|
||||
assertSame(c, list.get(2));
|
||||
|
||||
assertEquals(3, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkConstructor() {
|
||||
try {
|
||||
new CollectionUtils();
|
||||
} catch (final Exception ignored) {
|
||||
fail(ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue