private boolean trueNegativesBetween(int min, int max) { for (int i = min; i < max; i++) { if (i % 3 == 0 && !BinaryRegexp.multipleOf3().matcher(Integer.toBinaryString(i)).matches()) { return true; } } return false; }
@Test public void testValid() { assertEquals(true, BinaryRegexp.multipleOf3().matcher("000").matches()); assertEquals(false, BinaryRegexp.multipleOf3().matcher("001").matches()); assertEquals(true, BinaryRegexp.multipleOf3().matcher("011").matches()); assertEquals(true, BinaryRegexp.multipleOf3().matcher("110").matches()); assertEquals(false, BinaryRegexp.multipleOf3().matcher("111").matches()); assertEquals( true, BinaryRegexp.multipleOf3().matcher(Integer.toBinaryString(12345678)).matches()); }
@Test public void testInvalid() { assertEquals(false, BinaryRegexp.multipleOf3().matcher(" 0").matches()); assertEquals(false, BinaryRegexp.multipleOf3().matcher("abc").matches()); assertEquals(false, BinaryRegexp.multipleOf3().matcher("011 110").matches()); }
@Test public void checkType() { // In fact Pattern and Matcher can't be extended as they are final, but let this be assertEquals(Pattern.class, BinaryRegexp.multipleOf3().getClass()); assertEquals(Matcher.class, BinaryRegexp.multipleOf3().matcher("").getClass()); }