@Test public void testToArray() { FastFloatBuffer buff = new FastFloatBuffer(); int sum = 0; for (int j = 0; j < COUNT; j++) { for (int i = 1; i <= SIZE; i++) { buff.append(i); sum += i; } } buff.append(173); sum += 173; float[] array = buff.toArray(); int sum2 = 0; for (double l : array) { sum2 += l; } assertEquals(sum, sum2); array = buff.toArray(1, buff.size() - 2); sum2 = 0; for (double l : array) { sum2 += l; } assertEquals(sum - 1 - 173, sum2); }
@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); }