/** When a negative index is used, an {@link IndexOutOfBoundsException} should be thrown. */ @Test public void testIndexOutOfBoundsException() { BooleanBag bag = new BooleanBag(); for (int i = 0; i < 32; i++) { try { bag.set(-(1 << i), true); } catch (IndexOutOfBoundsException ex) { if (ex.getClass() == IndexOutOfBoundsException.class) continue; } fail("IndexOutOfBoundsException expected for index " + (-(1 << i))); } for (int i = 0; i < 32; i++) { try { bag.get(-(1 << i)); } catch (IndexOutOfBoundsException ex) { if (ex.getClass() == IndexOutOfBoundsException.class) continue; } fail("IndexOutOfBoundsException expected for index " + (-(1 << i))); } }