Implement removeEverySecond
This commit is contained in:
@ -272,7 +272,13 @@ public class FullyUsedArrayProcessor<T> implements SequenceProcessor<T, FullyUse
|
||||
|
||||
@Override
|
||||
public void removeEverySecond(FullyUsedArray<T> array) {
|
||||
throw new UnsupportedOperationException();
|
||||
T[] newArray = Arrays.newArray(array.theArray.length - array.theArray.length / 2);
|
||||
|
||||
for (int i = 0; i < newArray.length; i++) {
|
||||
newArray[i] = array.theArray[2*i];
|
||||
}
|
||||
|
||||
array.theArray = newArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@ import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -404,6 +405,22 @@ public abstract class SequenceProcessorTest<S> {
|
||||
assertIterableEquals(list, processor.iterate(s));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(ListProvider.class)
|
||||
void testThat_removeEverySecondWorks(List<Integer> list) {
|
||||
S s = processor.create(list);
|
||||
|
||||
var everyFirst = IntStream
|
||||
.iterate(0, i -> i < list.size(), i -> i+2)
|
||||
.mapToObj(list::get)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
processor.removeEverySecond(s);
|
||||
|
||||
assertTrue(processor.check(s));
|
||||
assertIterableEquals(everyFirst, processor.iterate(s));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(ListProvider.class)
|
||||
void testThat_doubleAllKeysWorks(List<Integer> list) {
|
||||
|
Reference in New Issue
Block a user