コード例 #1
0
ファイル: FastFloatBufferTest.java プロジェクト: lxmhope/jodd
  @Test
  public void testChunks() {
    FastFloatBuffer buff = new FastFloatBuffer();

    assertEquals(-1, buff.index());
    assertEquals(0, buff.offset());

    buff.append(1);

    assertEquals(0, buff.index());
    assertEquals(1, buff.offset());

    buff.append(2);

    assertEquals(2, buff.offset());

    for (int i = 3; i <= SIZE; i++) {
      buff.append(i);
    }

    assertEquals(0, buff.index());
    assertEquals(SIZE, buff.offset());

    buff.append(SIZE + 1);
    assertEquals(1, buff.index());
    assertEquals(1, buff.offset());

    float[] a = buff.array(0);

    for (int i = 1; i <= SIZE; i++) {
      assertEquals(i, a[i - 1], 0.1);
    }
  }
コード例 #2
0
ファイル: FastFloatBufferTest.java プロジェクト: lxmhope/jodd
  @Test
  public void testChunksOverflow() {
    FastFloatBuffer buff = new FastFloatBuffer();

    assertEquals(-1, buff.index());
    assertEquals(0, buff.offset());

    int sum = 0;

    for (int j = 0; j < COUNT; j++) {
      for (int i = 1; i <= SIZE; i++) {
        buff.append(i);
        sum += i;
      }
    }

    assertEquals(15, buff.index());
    assertEquals(1024, buff.offset());

    buff.append(-1);
    sum--;
    assertEquals(16, buff.index());
    assertEquals(1, buff.offset());

    int sum2 = 0;

    for (int i = 0; i < buff.size(); i++) {
      sum2 += buff.get(i);
    }

    assertEquals(sum, sum2);
  }