Extract statics getMax and getSecondMax
This commit is contained in:
		
							parent
							
								
									268361484d
								
							
						
					
					
						commit
						7b4f76f373
					
				
					 2 changed files with 19 additions and 11 deletions
				
			
		|  | @ -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 a new issue