コード例 #1
0
ファイル: BooleanBagTest.java プロジェクト: antag99/retinazer
  /** 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)));
    }
  }