Extract statics getMax and getSecondMax
This commit is contained in:
@ -239,10 +239,7 @@ public abstract class SequenceProcessorTest<S> {
|
||||
void testThat_maxWorks(List<Integer> list) {
|
||||
list.add(-1);
|
||||
S s = processor.create(list);
|
||||
var max = list
|
||||
.stream()
|
||||
.max(CMP)
|
||||
.orElseThrow();
|
||||
Integer max = Tests.getMax(list);
|
||||
assertEquals(max, processor.max(s, CMP));
|
||||
}
|
||||
|
||||
@ -252,12 +249,7 @@ public abstract class SequenceProcessorTest<S> {
|
||||
list.add(-1);
|
||||
list.add(-2);
|
||||
S s = processor.create(list);
|
||||
var max = list
|
||||
.stream()
|
||||
.sorted(CMP.reversed())
|
||||
.skip(1)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
Integer max = Tests.getSecondMax(list);
|
||||
assertEquals(max, processor.secondMax(s, CMP));
|
||||
}
|
||||
|
||||
|
@ -19,4 +19,20 @@ public class Tests {
|
||||
.boxed()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getMax(List<Integer> list) {
|
||||
return list
|
||||
.stream()
|
||||
.max(CMP)
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
public static Integer getSecondMax(List<Integer> list) {
|
||||
return list
|
||||
.stream()
|
||||
.sorted(CMP.reversed())
|
||||
.skip(1)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user