I want to check if a LongStream contains a certain number at least once, but does not completely consist 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 may not work in my problem, but the best solution I found. How can I go through all the tests?
source share