Created
December 6, 2021 15:49
-
-
Save pfichtner/ab3507ca2b6dafef9967cfa658a20d36 to your computer and use it in GitHub Desktop.
SonarSweep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package sonarsweep; | |
| import static java.lang.Integer.MAX_VALUE; | |
| import static org.hamcrest.CoreMatchers.is; | |
| import static org.hamcrest.MatcherAssert.assertThat; | |
| import java.util.concurrent.atomic.AtomicInteger; | |
| import java.util.function.IntPredicate; | |
| import java.util.stream.IntStream; | |
| import org.junit.jupiter.api.Test; | |
| class SonarSweepTest { | |
| @Test | |
| void test() { | |
| int[] values = { 199, 200, 208, 210, 200, 207, 240, 269, 260, 263 }; | |
| assertThat(countIncreased(values), is(7L)); | |
| } | |
| long countIncreased(int[] values) { | |
| return IntStream.of(values).filter(isIncreased()).count(); | |
| } | |
| static IntPredicate isIncreased() { | |
| AtomicInteger previous = new AtomicInteger(MAX_VALUE); | |
| return i -> i > previous.getAndSet(i); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment