I want to check, if a LongStream contains a specific number at least once, but not totally consists of this number:
My approach:
public static boolean containsNum(LongStream input, int n) {
return input.anyMatch(i -> i == n);
}
Tests:
assertEquals(false, containsNum(LongStream.of(1, 2, 3), 19)); // ok
assertEquals(true, containsNum(LongStream.of(1, 2, 3, 19), 19)); //ok
assertEquals(true, containsNum(LongStream.of(1, 19, 19), 19)); //ok
assertEquals(false, containsNum(LongStream.of(1), 19)); //ok
assertEquals(false, containsNum(LongStream.of(19, 19), 19)); // FAIL
assertEquals(false, containsNum(LongStream.of(19), 19)); //FAIL
I know that anyMatch can´t work in my problem, but the best solution I found. How can I get all tests passing?