Search in sources :

Example 81 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

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 82 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

the class DoubleBufferTest method testHashCode.

public void testHashCode() {
    buf.clear();
    DoubleBuffer readonly = buf.asReadOnlyBuffer();
    DoubleBuffer duplicate = buf.duplicate();
    assertTrue(buf.hashCode() == readonly.hashCode());
    assertTrue(buf.capacity() > 5);
    duplicate.position(buf.capacity() / 2);
    assertTrue(buf.hashCode() != duplicate.hashCode());
}
Also used : DoubleBuffer(java.nio.DoubleBuffer)

Example 83 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

the class DoubleBufferTest method testCompareTo_positiveAndNegativeZero.

public void testCompareTo_positiveAndNegativeZero() {
    double negativeZero = Double.parseDouble("-0");
    double positiveZero = Double.parseDouble("+0");
    DoubleBuffer negativeZeroBuffer = DoubleBuffer.wrap(new double[] { negativeZero });
    DoubleBuffer positiveZeroBuffer = DoubleBuffer.wrap(new double[] { positiveZero });
    // sanity check
    assertTrue(Double.compare(negativeZero, positiveZero) < 0);
    // Unlike Double.compare(), DoubleBuffer.compareTo() considers -0 == +0
    assertEquals(0, negativeZeroBuffer.compareTo(positiveZeroBuffer));
}
Also used : DoubleBuffer(java.nio.DoubleBuffer)

Example 84 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

the class DoubleBufferTest method testPutintdouble.

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

Example 85 with DoubleBuffer

use of java.nio.DoubleBuffer in project j2objc by google.

the class DoubleBufferTest method testGetdoubleArrayintint.

/*
     * Class under test for java.nio.DoubleBuffer get(double[], int, int)
     */
public void testGetdoubleArrayintint() {
    buf.clear();
    double[] array = new double[buf.capacity()];
    try {
        buf.get(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    try {
        buf.get(array, -1, array.length);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    buf.get(array, array.length, 0);
    try {
        buf.get(array, array.length + 1, 1);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    try {
        buf.get(array, 2, -1);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.get((double[]) null, 0, -1);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        buf.get(array, 2, array.length);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.get(array, 1, Integer.MAX_VALUE);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException expected) {
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        buf.get(array, Integer.MAX_VALUE, 1);
        // $NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    buf.clear();
    DoubleBuffer ret = buf.get(array, 0, array.length);
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, array, 0, array.length);
    assertSame(ret, buf);
}
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