public virtual void TestPutDoubleBuffer() { DoubleBuffer other = DoubleBuffer.Allocate(buf.Capacity); try { buf.Put(buf); fail("Should throw Exception"); //$NON-NLS-1$ } catch (ArgumentException e) { // expected } try { buf.Put(DoubleBuffer.Allocate(buf.Capacity + 1)); fail("Should throw Exception"); //$NON-NLS-1$ } 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); }
public override void SetUp() { base.SetUp(); buf = DoubleBuffer.Allocate(BUFFER_LENGTH); loadTestData1(buf); baseBuf = buf; }
public override void TestPutDoubleBuffer() { DoubleBuffer other = DoubleBuffer.Allocate(1); try { buf.Put(other); fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$ } catch (ReadOnlyBufferException e) { // expected } try { buf.Put((DoubleBuffer)null); fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$ } catch (ReadOnlyBufferException e) { // expected } try { buf.Put(buf); fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$ } catch (ReadOnlyBufferException e) { // expected } }
public virtual void TestCompareTo() { DoubleBuffer other = DoubleBuffer.Allocate(buf.Capacity); loadTestData1(other); assertEquals(0, buf.CompareTo(other)); assertEquals(0, other.CompareTo(buf)); buf.Position = (1); assertTrue(buf.CompareTo(other) > 0); assertTrue(other.CompareTo(buf) < 0); other.Position = (2); assertTrue(buf.CompareTo(other) < 0); assertTrue(other.CompareTo(buf) > 0); buf.Position = (2); other.Limit = (5); assertTrue(buf.CompareTo(other) > 0); assertTrue(other.CompareTo(buf) < 0); DoubleBuffer dbuffer1 = DoubleBuffer.Wrap(new double[] { double.NaN }); DoubleBuffer dbuffer2 = DoubleBuffer.Wrap(new double[] { double.NaN }); DoubleBuffer dbuffer3 = DoubleBuffer.Wrap(new double[] { 42d }); assertEquals("Failed equal comparison with NaN entry", 0, dbuffer1 .CompareTo(dbuffer2)); assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer3 .CompareTo(dbuffer1)); assertEquals("Failed less than comparison with NaN entry", -1, dbuffer1 // J2N: Corrected this (Harmony) test to match JDK 7, which expects NaN to be symmetric. This also matches .NET double.CompareTo(). .CompareTo(dbuffer3)); // J2N: Cover null for .NET. See: https://stackoverflow.com/a/4852537 assertEquals(1, buf.CompareTo(null)); }
private static void testAllocate() { // An IllegalArgumentException will be thrown for negative capacities. tryCatch((Buffer)null, typeof(ArgumentException), () => { DoubleBuffer.Allocate(-1); }); }
public static void Test() { testAllocate(); test(0, DoubleBuffer.Allocate(7 * 1024), false); test(0, DoubleBuffer.Wrap(new double[7 * 1024], 0, 7 * 1024), false); test(new double[1024]); callReset(DoubleBuffer.Allocate(10)); putBuffer(); }
public void TestAllocatedDoubleBuffer_IllegalArg() { try { DoubleBuffer.Allocate(-1); fail("Should throw Exception"); //$NON-NLS-1$ } catch (ArgumentException e) { // expected } }
private static void bulkPutBuffer(DoubleBuffer b) { int n = b.Capacity; b.Clear(); DoubleBuffer c = DoubleBuffer.Allocate(n + 7); c.Position = (7); for (int i = 0; i < n; i++) { c.Put((double)Ic(i)); } c.Flip(); c.Position = (7); b.Put(c); b.Flip(); }
public static void test(int level, DoubleBuffer b, bool direct) { Show(level, b); //if (direct != b.IsDirect) // J2N: IsDirect not supported // fail("Wrong direction", b); // Gets and puts relPut(b); relGet(b); absGet(b); bulkGet(b); absPut(b); relGet(b); absGet(b); bulkGet(b); bulkPutArray(b); relGet(b); bulkPutBuffer(b); relGet(b); // Compact relPut(b); b.Position = (13); b.Compact(); b.Flip(); relGet(b, 13); // Exceptions relPut(b); b.Limit = (b.Capacity / 2); b.Position = (b.Limit); tryCatch(b, typeof(BufferUnderflowException), () => { b.Get(); }); tryCatch(b, typeof(BufferOverflowException), () => { b.Put((double)42); }); // The index must be non-negative and lesss than the buffer's limit. tryCatch(b, typeof(ArgumentOutOfRangeException), () => { b.Get(b.Limit); }); tryCatch(b, typeof(ArgumentOutOfRangeException), () => { b.Get(-1); }); tryCatch(b, typeof(ArgumentOutOfRangeException), () => { b.Put(b.Limit, (double)42); }); tryCatch(b, typeof(InvalidMarkException), () => { b.Position = (0); b.Mark(); b.Compact(); b.Reset(); }); // Values b.Clear(); b.Put((double)0); b.Put((double)-1); b.Put((double)1); b.Put(double.MaxValue); b.Put(double.MinValue); b.Put(-double.MaxValue); b.Put(-double.MinValue); b.Put(double.NegativeInfinity); b.Put(double.PositiveInfinity); b.Put(double.NaN); b.Put(0.5121609353879392); // Changes value if incorrectly swapped double v; b.Flip(); ck(b, b.Get(), 0); ck(b, b.Get(), (double)-1); ck(b, b.Get(), 1); ck(b, b.Get(), double.MaxValue); ck(b, b.Get(), double.MinValue); ck(b, b.Get(), -double.MaxValue); ck(b, b.Get(), -double.MinValue); ck(b, b.Get(), double.NegativeInfinity); ck(b, b.Get(), double.PositiveInfinity); if (BitConversion.DoubleToRawInt64Bits(v = b.Get()) != BitConversion.DoubleToRawInt64Bits(double.NaN)) { fail(b, unchecked ((long)double.NaN), (long)v); } ck(b, b.Get(), 0.5121609353879392); // Comparison b.Rewind(); DoubleBuffer b2 = DoubleBuffer.Allocate(b.Capacity); b2.Put(b); b2.Flip(); b.Position = (2); b2.Position = (2); if (!b.Equals(b2)) { for (int i = 2; i < b.Limit; i++) { double x = b.Get(i); double y = b2.Get(i); if (x != y || x.CompareTo(y) != 0) { output.WriteLine("[" + i + "] " + x + " != " + y); } } fail("Identical buffers not equal", b, b2); } if (b.CompareTo(b2) != 0) { fail("Comparison to identical buffer != 0", b, b2); } b.Limit = (b.Limit + 1); b.Position = (b.Limit - 1); b.Put((double)99); b.Rewind(); b2.Rewind(); if (b.Equals(b2)) { fail("Non-identical buffers equal", b, b2); } if (b.CompareTo(b2) <= 0) { fail("Comparison to shorter buffer <= 0", b, b2); } b.Limit = (b.Limit - 1); b.Put(2, (double)42); if (b.Equals(b2)) { fail("Non-identical buffers equal", b, b2); } if (b.CompareTo(b2) <= 0) { fail("Comparison to lesser buffer <= 0", b, b2); } // Check equals and compareTo with interesting values foreach (double x in VALUES) { DoubleBuffer xb = DoubleBuffer.Wrap(new double[] { x }); if (xb.CompareTo(xb) != 0) { fail("compareTo not reflexive", xb, xb, x, x); } if (!xb.Equals(xb)) { fail("equals not reflexive", xb, xb, x, x); } foreach (double y in VALUES) { DoubleBuffer yb = DoubleBuffer.Wrap(new double[] { y }); if (xb.CompareTo(yb) != -yb.CompareTo(xb)) { fail("compareTo not anti-symmetric", xb, yb, x, y); } if ((xb.CompareTo(yb) == 0) != xb.Equals(yb)) { fail("compareTo inconsistent with equals", xb, yb, x, y); } if (xb.CompareTo(yb) != x.CompareTo(y)) { if (x == 0.0 && y == 0.0) { continue; } fail("Incorrect results for DoubleBuffer.compareTo", xb, yb, x, y); } if (xb.Equals(yb) != ((x == y) || (double.IsNaN(x) && double.IsNaN(y)))) { fail("Incorrect results for DoubleBuffer.equals", xb, yb, x, y); } } } // Sub, dup relPut(b); relGet(b.Duplicate()); b.Position = (13); relGet(b.Duplicate(), 13); relGet(b.Duplicate().Slice(), 13); relGet(b.Slice(), 13); relGet(b.Slice().Duplicate(), 13); // Slice b.Position = (5); DoubleBuffer sb = b.Slice(); checkSlice(b, sb); b.Position = (0); DoubleBuffer sb2 = sb.Slice(); checkSlice(sb, sb2); if (!sb.Equals(sb2)) { fail("Sliced slices do not match", sb, sb2); } if ((sb.HasArray) && (sb.ArrayOffset != sb2.ArrayOffset)) { fail("Array offsets do not match: " + sb.ArrayOffset + " != " + sb2.ArrayOffset, sb, sb2); } // Read-only views b.Rewind(); DoubleBuffer rb = b.AsReadOnlyBuffer(); if (!b.Equals(rb)) { fail("Buffer not equal to read-only view", b, rb); } Show(level + 1, rb); tryCatch(b, typeof(ReadOnlyBufferException), () => { relPut(rb); }); tryCatch(b, typeof(ReadOnlyBufferException), () => { absPut(rb); }); tryCatch(b, typeof(ReadOnlyBufferException), () => { bulkPutArray(rb); }); tryCatch(b, typeof(ReadOnlyBufferException), () => { bulkPutBuffer(rb); }); tryCatch(b, typeof(ReadOnlyBufferException), () => { rb.Compact(); }); if (rb.GetType().Name.StartsWith("Heap", StringComparison.Ordinal)) { tryCatch(b, typeof(ReadOnlyBufferException), () => { var _ = rb.Array; }); tryCatch(b, typeof(ReadOnlyBufferException), () => { var _ = rb.ArrayOffset; }); if (rb.HasArray) { fail("Read-only heap buffer's backing array is accessible", rb); } } // Bulk puts from read-only buffers b.Clear(); rb.Rewind(); b.Put(rb); relPut(b); // Required by testViews }