Esempio n. 1
0
 @Test
 public void testFillAndClear() {
   for (byte size = 0; size < 100; size++) {
     Slice slice = allocate(size);
     for (int i = 0; i < slice.length(); i++) {
       assertEquals(slice.getByte(i), (byte) 0);
     }
     slice.fill((byte) 0xA5);
     for (int i = 0; i < slice.length(); i++) {
       assertEquals(slice.getByte(i), (byte) 0xA5);
     }
     slice.clear();
     for (int i = 0; i < slice.length(); i++) {
       assertEquals(slice.getByte(i), (byte) 0);
     }
   }
 }
Esempio n. 2
0
  private static void assertByte(Slice slice, byte index) {
    // fill slice with FF
    slice.fill((byte) 0xFF);

    // set and get unsigned value
    slice.setByte(index, 0xA5);
    assertEquals(slice.getUnsignedByte(index), 0x0000_00A5);

    // set and get the value
    slice.setByte(index, 0xA5);
    assertEquals(slice.getByte(index), (byte) 0xA5);

    try {
      slice.getByte(-1);
      fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      slice.getByte((slice.length() - SIZE_OF_BYTE) + 1);
      fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      slice.getByte(slice.length());
      fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }

    try {
      slice.getByte(slice.length() + 1);
      fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }
  }