Extract statics getMax and getSecondMax

This commit is contained in:
2021-09-03 11:50:04 +02:00
parent 268361484d
commit 7b4f76f373
2 changed files with 19 additions and 11 deletions

View File

@ -239,10 +239,7 @@ public abstract class SequenceProcessorTest<S> {
void testThat_maxWorks(List<Integer> list) { void testThat_maxWorks(List<Integer> list) {
list.add(-1); list.add(-1);
S s = processor.create(list); S s = processor.create(list);
var max = list Integer max = Tests.getMax(list);
.stream()
.max(CMP)
.orElseThrow();
assertEquals(max, processor.max(s, CMP)); assertEquals(max, processor.max(s, CMP));
} }
@ -252,12 +249,7 @@ public abstract class SequenceProcessorTest<S> {
list.add(-1); list.add(-1);
list.add(-2); list.add(-2);
S s = processor.create(list); S s = processor.create(list);
var max = list Integer max = Tests.getSecondMax(list);
.stream()
.sorted(CMP.reversed())
.skip(1)
.findFirst()
.orElseThrow();
assertEquals(max, processor.secondMax(s, CMP)); assertEquals(max, processor.secondMax(s, CMP));
} }

View File

@ -19,4 +19,20 @@ public class Tests {
.boxed() .boxed()
.collect(Collectors.toList()); .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();
}
}