unsorted lists can become sorted after removal
The old code only set the list to sorted when the lists size was <= 1 after the removal.
This commit is contained in:
@@ -1223,6 +1223,30 @@ public class IntListTest {
|
||||
Assert.assertTrue("unsorted list with no elements becomes sorted", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedFlagRemove_unsortedBecomesSorted_emptyList() {
|
||||
|
||||
final IntList list = IntList.of(4, 3, 2, 1);
|
||||
list.remove(0, 4); // removes all
|
||||
Assert.assertTrue("empty list is sorted", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedFlagRemove_unsortedBecomesSorted_oneElement() {
|
||||
|
||||
final IntList list = IntList.of(4, 3, 2, 1);
|
||||
list.remove(1, 4); // removes 3,2,1
|
||||
Assert.assertTrue("list with one element is", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedFlagRemove_unsortedBecomesSorted() {
|
||||
|
||||
final IntList list = IntList.of(1, 2, 777, 4, 5);
|
||||
list.remove(2, 3); // removes 777
|
||||
Assert.assertTrue("list is sorted after remove", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedFlagRemoveAll() {
|
||||
|
||||
@@ -1253,6 +1277,31 @@ public class IntListTest {
|
||||
Assert.assertTrue("unsorted list with no elements becomes sorted", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedFlagRemoveIf_unsortedBecomesSorted_emptyAfterRemove() {
|
||||
|
||||
final IntList list = IntList.of(1, 3, 2);
|
||||
list.removeIf((value, index) -> true); // makes the list sorted
|
||||
Assert.assertTrue("list is empty", list.isEmpty());
|
||||
Assert.assertTrue("empty list is sorted", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedFlagRemoveIf_unsortedBecomesSorted_oneElementAfterRemove() {
|
||||
|
||||
final IntList list = IntList.of(1, 3, 2);
|
||||
list.removeIf((value, index) -> value > 1); // makes the list sorted
|
||||
Assert.assertTrue("list with one element is sorted", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedFlagRemoveIf_unsortedBecomesSorted() {
|
||||
|
||||
final IntList list = IntList.of(1, 2, 3, 777, 4, 5);
|
||||
list.removeIf((value, index) -> value == 777); // makes the list sorted
|
||||
Assert.assertTrue("unsorted list becomes sorted", list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedFlagReplace() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user