Search in sources :

Example 11 with DoubleBuffer

use of java.nio.DoubleBuffer in project robovm by robovm.

the class DoubleBufferTest method testPutdouble.

/*
     * Class under test for java.nio.DoubleBuffer put(double)
     */
public void testPutdouble() {
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        DoubleBuffer ret = buf.put((double) i);
        assertEquals(buf.get(i), (double) i, 0.0);
        assertSame(ret, buf);
    }
    try {
        buf.put(0);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 12 with DoubleBuffer

use of java.nio.DoubleBuffer in project robovm by robovm.

the class DoubleBufferTest method testPutDoubleBuffer.

/*
     * Class under test for java.nio.DoubleBuffer put(java.nio.DoubleBuffer)
     */
public void testPutDoubleBuffer() {
    DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());
    try {
        buf.put(buf);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        buf.put(DoubleBuffer.allocate(buf.capacity() + 1));
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
    loadTestData2(other);
    other.clear();
    buf.clear();
    DoubleBuffer ret = buf.put(other);
    assertEquals(other.position(), other.capacity());
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(other, buf);
    assertSame(ret, buf);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 13 with DoubleBuffer

use of java.nio.DoubleBuffer in project robovm by robovm.

the class DoubleBufferTest method testSlice.

public void testSlice() {
    assertTrue(buf.capacity() > 5);
    buf.position(1);
    buf.limit(buf.capacity() - 1);
    DoubleBuffer slice = buf.slice();
    assertEquals(buf.isReadOnly(), slice.isReadOnly());
    assertEquals(buf.isDirect(), slice.isDirect());
    assertEquals(buf.order(), slice.order());
    assertEquals(slice.position(), 0);
    assertEquals(slice.limit(), buf.remaining());
    assertEquals(slice.capacity(), buf.remaining());
    try {
        slice.reset();
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (InvalidMarkException e) {
    // expected
    }
    // FIXME:
    if (!slice.isReadOnly()) {
        loadTestData1(slice);
        assertContentLikeTestData1(buf, 1, 0, slice.capacity());
        buf.put(2, 500);
        assertEquals(slice.get(1), 500, 0.0);
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) InvalidMarkException(java.nio.InvalidMarkException)

Example 14 with DoubleBuffer

use of java.nio.DoubleBuffer in project robovm by robovm.

the class DoubleBufferTest method testPutdoubleArray.

/*
     * Class under test for java.nio.DoubleBuffer put(double[])
     */
public void testPutdoubleArray() {
    double[] array = new double[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        array[0] = (double) i;
        DoubleBuffer ret = buf.put(array);
        assertEquals(buf.get(i), (double) i, 0.0);
        assertSame(ret, buf);
    }
    try {
        buf.put(array);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Example 15 with DoubleBuffer

use of java.nio.DoubleBuffer in project robovm by robovm.

the class DoubleBufferTest method testGetdoubleArray.

/*
     * Class under test for java.nio.DoubleBuffer get(double[])
     */
public void testGetdoubleArray() {
    double[] array = new double[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        DoubleBuffer ret = buf.get(array);
        assertEquals(array[0], buf.get(i), 0.01);
        assertSame(ret, buf);
    }
    try {
        buf.get(array);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException e) {
    // expected
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) BufferUnderflowException(java.nio.BufferUnderflowException)

Aggregations

DoubleBuffer (java.nio.DoubleBuffer)162 ByteBuffer (java.nio.ByteBuffer)39 FloatBuffer (java.nio.FloatBuffer)26 IntBuffer (java.nio.IntBuffer)25 ShortBuffer (java.nio.ShortBuffer)22 LongBuffer (java.nio.LongBuffer)14 CharBuffer (java.nio.CharBuffer)11 BufferOverflowException (java.nio.BufferOverflowException)8 IOException (java.io.IOException)5 BufferUnderflowException (java.nio.BufferUnderflowException)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ServerDenseDoubleRow (com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)4 Test (org.junit.Test)4 InvalidMarkException (java.nio.InvalidMarkException)3 Random (java.util.Random)3 BytePointer (org.bytedeco.javacpp.BytePointer)3 DoublePointer (org.bytedeco.javacpp.DoublePointer)3 FloatPointer (org.bytedeco.javacpp.FloatPointer)3 IntPointer (org.bytedeco.javacpp.IntPointer)3