2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.harmony.nio.tests.java.nio;
20 import dalvik.annotation.TestLevel;
21 import dalvik.annotation.TestTargetNew;
22 import dalvik.annotation.TestTargetClass;
23 import dalvik.annotation.AndroidOnly;
25 import java.nio.BufferOverflowException;
26 import java.nio.BufferUnderflowException;
27 import java.nio.ByteBuffer;
28 import java.nio.ByteOrder;
29 import java.nio.DoubleBuffer;
30 import java.nio.InvalidMarkException;
33 * Tests java.nio.DoubleBuffer
35 @TestTargetClass(java.nio.DoubleBuffer.class)
36 public abstract class DoubleBufferTest extends AbstractBufferTest {
38 protected static final int SMALL_TEST_LENGTH = 5;
40 protected static final int BUFFER_LENGTH = 20;
42 protected DoubleBuffer buf;
44 protected void setUp() throws Exception {
45 capacity = BUFFER_LENGTH;
46 buf = DoubleBuffer.allocate(BUFFER_LENGTH);
51 protected void tearDown() throws Exception {
57 * test for method static DoubleBuffer allocate(int capacity) test covers
58 * following usecases: 1. case for check DoubleBuffer testBuf properties 2.
59 * case expected IllegalArgumentException
62 level = TestLevel.PARTIAL_COMPLETE,
67 public void test_AllocateI() {
68 // case: DoubleBuffer testBuf properties is satisfy the conditions
70 DoubleBuffer testBuf = DoubleBuffer.allocate(20);
71 assertEquals(0, testBuf.position());
72 assertNotNull(testBuf.array());
73 assertEquals(0, testBuf.arrayOffset());
74 assertEquals(20, testBuf.limit());
75 assertEquals(20, testBuf.capacity());
77 testBuf = DoubleBuffer.allocate(0);
78 assertEquals(0, testBuf.position());
79 assertNotNull(testBuf.array());
80 assertEquals(0, testBuf.arrayOffset());
81 assertEquals(0, testBuf.limit());
82 assertEquals(0, testBuf.capacity());
84 // case: expected IllegalArgumentException
86 testBuf = DoubleBuffer.allocate(-20);
87 fail("allocate method does not throws expected exception");
88 } catch (IllegalArgumentException e) {
94 * Test with bit sequences that represent the IEEE754 doubles Positive
95 * infinity, negative infinity, and NaN.
98 level = TestLevel.PARTIAL_COMPLETE,
99 notes = "Verifies boundary values.",
101 args = {double.class}
103 public void testNaNs() {
104 long[] nans = new long[] { 0x7ff0000000000000L, 0xfff0000000000000L,
105 0x7ff8000000000000L };
106 for (int i = 0; i < nans.length; i++) {
107 long longBitsIn = nans[i];
108 double dbl = Double.longBitsToDouble(longBitsIn);
109 long longBitsOut = Double.doubleToRawLongBits(dbl);
111 assertTrue(longBitsIn == longBitsOut);
113 // Store the double and retrieve it
114 ByteBuffer buffer = ByteBuffer.allocate(8);
115 buffer.putDouble(dbl);
116 double bufDoubleOut = buffer.getDouble(0);
118 // Check the bits sequence was not normalized
119 long bufLongOut = Double.doubleToRawLongBits(bufDoubleOut);
120 assertTrue(longBitsIn == bufLongOut);
125 level = TestLevel.PARTIAL_COMPLETE,
130 public void testArray() {
131 double array[] = buf.array();
132 assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
134 loadTestData1(array, buf.arrayOffset(), buf.capacity());
135 assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
137 loadTestData2(array, buf.arrayOffset(), buf.capacity());
138 assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
141 assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
144 assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
148 level = TestLevel.PARTIAL_COMPLETE,
150 method = "arrayOffset",
153 public void testArrayOffset() {
154 double array[] = buf.array();
155 for(int i = 0; i < buf.capacity(); i++) {
158 int offset = buf.arrayOffset();
159 assertContentEquals(buf, array, offset, buf.capacity());
161 DoubleBuffer wrapped = DoubleBuffer.wrap(array, 3, array.length - 3);
163 loadTestData1(array, wrapped.arrayOffset(), wrapped.capacity());
164 assertContentEquals(buf, array, offset, buf.capacity());
166 loadTestData2(array, wrapped.arrayOffset(), wrapped.capacity());
167 assertContentEquals(buf, array, offset, buf.capacity());
171 level = TestLevel.PARTIAL_COMPLETE,
173 method = "asReadOnlyBuffer",
176 public void testAsReadOnlyBuffer() {
179 buf.position(buf.limit());
181 // readonly's contents should be the same as buf
182 DoubleBuffer readonly = buf.asReadOnlyBuffer();
183 assertNotSame(buf, readonly);
184 assertTrue(readonly.isReadOnly());
185 assertEquals(buf.position(), readonly.position());
186 assertEquals(buf.limit(), readonly.limit());
187 assertEquals(buf.isDirect(), readonly.isDirect());
188 assertEquals(buf.order(), readonly.order());
189 assertContentEquals(buf, readonly);
191 // readonly's position, mark, and limit should be independent to buf
193 assertEquals(readonly.position(), 0);
195 assertEquals(buf.position(), buf.limit());
197 assertEquals(buf.position(), 0);
199 // BEGIN android-added
200 // copied from a newer version of Harmony
201 DoubleBuffer dbuffer1 = DoubleBuffer.wrap(new double[] { Double.NaN });
202 DoubleBuffer dbuffer2 = DoubleBuffer.wrap(new double[] { Double.NaN });
203 DoubleBuffer dbuffer3 = DoubleBuffer.wrap(new double[] { 42d });
205 assertEquals("Failed equal comparison with NaN entry", 0, dbuffer1
206 .compareTo(dbuffer2));
207 assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer3
208 .compareTo(dbuffer1));
209 assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer1
210 .compareTo(dbuffer3));
215 level = TestLevel.PARTIAL_COMPLETE,
220 @AndroidOnly("Fails on RI. See comment below")
221 public void testCompact() {
222 // case: buffer is full
226 DoubleBuffer ret = buf.compact();
227 assertSame(ret, buf);
228 assertEquals(buf.position(), buf.capacity());
229 assertEquals(buf.limit(), buf.capacity());
230 assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
233 fail("Should throw Exception");
234 } catch (InvalidMarkException e) {
238 // case: buffer is empty
243 assertSame(ret, buf);
244 assertEquals(buf.position(), 0);
245 assertEquals(buf.limit(), buf.capacity());
246 assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
248 // Fails on RI. Spec doesn't specify the behavior if
249 // actually nothing to be done by compact(). So RI doesn't reset
252 fail("Should throw Exception");
253 } catch (InvalidMarkException e) {
258 assertTrue(buf.capacity() > 5);
263 assertSame(ret, buf);
264 assertEquals(buf.position(), 4);
265 assertEquals(buf.limit(), buf.capacity());
266 assertContentLikeTestData1(buf, 0, 1.0, 4);
269 fail("Should throw Exception");
270 } catch (InvalidMarkException e) {
276 level = TestLevel.PARTIAL_COMPLETE,
278 method = "compareTo",
279 args = {java.nio.DoubleBuffer.class}
281 public void testCompareTo() {
282 DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());
283 loadTestData1(other);
284 assertEquals(0, buf.compareTo(other));
285 assertEquals(0, other.compareTo(buf));
287 assertTrue(buf.compareTo(other) > 0);
288 assertTrue(other.compareTo(buf) < 0);
290 assertTrue(buf.compareTo(other) < 0);
291 assertTrue(other.compareTo(buf) > 0);
294 assertTrue(buf.compareTo(other) > 0);
295 assertTrue(other.compareTo(buf) < 0);
297 DoubleBuffer dbuffer1 = DoubleBuffer.wrap(new double[] { Double.NaN });
298 DoubleBuffer dbuffer2 = DoubleBuffer.wrap(new double[] { Double.NaN });
299 DoubleBuffer dbuffer3 = DoubleBuffer.wrap(new double[] { 42d });
301 assertEquals("Failed equal comparison with NaN entry", 0, dbuffer1
302 .compareTo(dbuffer2));
303 assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer3
304 .compareTo(dbuffer1));
305 assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer1
306 .compareTo(dbuffer3));
310 level = TestLevel.PARTIAL_COMPLETE,
312 method = "duplicate",
315 public void testDuplicate() {
318 buf.position(buf.limit());
320 // duplicate's contents should be the same as buf
321 DoubleBuffer duplicate = buf.duplicate();
322 assertNotSame(buf, duplicate);
323 assertEquals(buf.position(), duplicate.position());
324 assertEquals(buf.limit(), duplicate.limit());
325 assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
326 assertEquals(buf.isDirect(), duplicate.isDirect());
327 assertEquals(buf.order(), duplicate.order());
328 assertContentEquals(buf, duplicate);
330 // duplicate's position, mark, and limit should be independent to buf
332 assertEquals(duplicate.position(), 0);
334 assertEquals(buf.position(), buf.limit());
336 assertEquals(buf.position(), 0);
338 // duplicate share the same content with buf
340 if (!duplicate.isReadOnly()) {
342 assertContentEquals(buf, duplicate);
343 loadTestData2(duplicate);
344 assertContentEquals(buf, duplicate);
349 level = TestLevel.PARTIAL_COMPLETE,
352 args = {java.lang.Object.class}
354 public void testEquals() {
356 assertTrue(buf.equals(buf));
357 DoubleBuffer readonly = buf.asReadOnlyBuffer();
358 assertTrue(buf.equals(readonly));
359 DoubleBuffer duplicate = buf.duplicate();
360 assertTrue(buf.equals(duplicate));
362 // always false, if type mismatch
363 assertFalse(buf.equals(Boolean.TRUE));
365 assertTrue(buf.capacity() > 5);
367 buf.limit(buf.capacity()).position(0);
368 readonly.limit(readonly.capacity()).position(1);
369 assertFalse(buf.equals(readonly));
371 buf.limit(buf.capacity() - 1).position(0);
372 duplicate.limit(duplicate.capacity()).position(0);
373 assertFalse(buf.equals(duplicate));
377 * Class under test for double get()
380 level = TestLevel.PARTIAL_COMPLETE,
385 public void testGet() {
387 for (int i = 0; i < buf.capacity(); i++) {
388 assertEquals(buf.position(), i);
389 assertEquals(buf.get(), buf.get(i), 0.01);
393 fail("Should throw Exception");
394 } catch (BufferUnderflowException e) {
400 * Class under test for java.nio.DoubleBuffer get(double[])
403 level = TestLevel.PARTIAL_COMPLETE,
406 args = {double[].class}
408 public void testGetdoubleArray() {
409 double array[] = new double[1];
411 for (int i = 0; i < buf.capacity(); i++) {
412 assertEquals(buf.position(), i);
413 DoubleBuffer ret = buf.get(array);
414 assertEquals(array[0], buf.get(i), 0.01);
415 assertSame(ret, buf);
418 buf.get(new double[0]);
422 fail("Should throw Exception");
423 } catch (BufferUnderflowException e) {
428 buf.get((double[])null);
429 fail("Should throw Exception");
430 } catch (NullPointerException e) {
436 * Class under test for java.nio.DoubleBuffer get(double[], int, int)
439 level = TestLevel.PARTIAL_COMPLETE,
442 args = {double[].class, int.class, int.class}
444 public void testGetdoubleArrayintint() {
446 double array[] = new double[buf.capacity()];
449 buf.get(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
450 fail("Should throw Exception");
451 } catch (BufferUnderflowException e) {
454 assertEquals(buf.position(), 0);
456 buf.get(array, -1, array.length);
457 fail("Should throw Exception");
458 } catch (IndexOutOfBoundsException e) {
461 buf.get(array, array.length, 0);
463 buf.get(array, array.length + 1, 1);
464 fail("Should throw Exception");
465 } catch (IndexOutOfBoundsException e) {
468 assertEquals(buf.position(), 0);
470 buf.get(array, 2, -1);
471 fail("Should throw Exception");
472 } catch (IndexOutOfBoundsException e) {
476 buf.get((double[])null, 0, -1);
477 fail("Should throw Exception");
478 } catch (NullPointerException e) {
482 buf.get(array, 2, array.length);
483 fail("Should throw Exception");
484 } catch (IndexOutOfBoundsException e) {
488 buf.get(array, 1, Integer.MAX_VALUE);
489 fail("Should throw Exception");
490 } catch (IndexOutOfBoundsException e) {
494 buf.get(array, Integer.MAX_VALUE, 1);
495 fail("Should throw Exception");
496 } catch (IndexOutOfBoundsException e) {
499 assertEquals(buf.position(), 0);
502 DoubleBuffer ret = buf.get(array, 0, array.length);
503 assertEquals(buf.position(), buf.capacity());
504 assertContentEquals(buf, array, 0, array.length);
505 assertSame(ret, buf);
509 * Class under test for double get(int)
512 level = TestLevel.PARTIAL_COMPLETE,
517 public void testGetint() {
519 for (int i = 0; i < buf.capacity(); i++) {
520 assertEquals(buf.position(), i);
521 assertEquals(buf.get(), buf.get(i), 0.01);
525 fail("Should throw Exception");
526 } catch (IndexOutOfBoundsException e) {
530 buf.get(buf.limit());
531 fail("Should throw Exception");
532 } catch (IndexOutOfBoundsException e) {
538 level = TestLevel.PARTIAL_COMPLETE,
543 public void testHasArray() {
544 if (buf.hasArray()) {
545 assertNotNull(buf.array());
549 fail("Should throw Exception");
550 } catch (UnsupportedOperationException e) {
552 // Note:can not tell when to catch
553 // UnsupportedOperationException or
554 // ReadOnlyBufferException, so catch all.
560 level = TestLevel.PARTIAL_COMPLETE,
565 public void testHashCode() {
567 DoubleBuffer readonly = buf.asReadOnlyBuffer();
568 DoubleBuffer duplicate = buf.duplicate();
569 assertTrue(buf.hashCode() == readonly.hashCode());
571 assertTrue(buf.capacity() > 5);
572 duplicate.position(buf.capacity() / 2);
573 assertTrue(buf.hashCode() != duplicate.hashCode());
577 level = TestLevel.PARTIAL_COMPLETE,
578 notes = "Doesn't verify direct buffer.",
582 public void testIsDirect() {
583 assertFalse(buf.isDirect());
587 level = TestLevel.PARTIAL_COMPLETE,
588 notes = "Abstract method.",
589 method = "isReadOnly",
592 public void testIsReadOnly() {
593 assertFalse(buf.isReadOnly());
597 level = TestLevel.PARTIAL_COMPLETE,
602 public void testOrder() {
603 assertEquals(ByteOrder.nativeOrder(), buf.order());
607 * Class under test for java.nio.DoubleBuffer put(double)
610 level = TestLevel.PARTIAL_COMPLETE,
611 notes = "Doesn't verify boundary values, and ReadOnlyBufferException.",
613 args = {double.class}
615 public void testPutdouble() {
618 for (int i = 0; i < buf.capacity(); i++) {
619 assertEquals(buf.position(), i);
620 DoubleBuffer ret = buf.put((double) i);
621 assertEquals(buf.get(i), (double) i, 0.0);
622 assertSame(ret, buf);
626 fail("Should throw Exception");
627 } catch (BufferOverflowException e) {
633 * Class under test for java.nio.DoubleBuffer put(double[])
636 level = TestLevel.PARTIAL_COMPLETE,
637 notes = "Doesn't verify ReadOnlyBufferException.",
639 args = {double[].class}
641 public void testPutdoubleArray() {
642 double array[] = new double[1];
645 for (int i = 0; i < buf.capacity(); i++) {
646 assertEquals(buf.position(), i);
647 array[0] = (double) i;
648 DoubleBuffer ret = buf.put(array);
649 assertEquals(buf.get(i), (double) i, 0.0);
650 assertSame(ret, buf);
654 fail("Should throw Exception");
655 } catch (BufferOverflowException e) {
661 * Class under test for java.nio.DoubleBuffer put(double[], int, int)
664 level = TestLevel.PARTIAL_COMPLETE,
665 notes = "Doesn't verify ReadOnlyBufferException.",
667 args = {double[].class, int.class, int.class}
669 public void testPutdoubleArrayintint() {
671 double array[] = new double[buf.capacity()];
674 buf.put(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
675 fail("Should throw Exception");
676 } catch (BufferOverflowException e) {
679 assertEquals(buf.position(), 0);
681 buf.put(array, -1, array.length);
682 fail("Should throw Exception");
683 } catch (IndexOutOfBoundsException e) {
687 buf.put(array, array.length + 1, 0);
688 fail("Should throw Exception");
689 } catch (IndexOutOfBoundsException e) {
692 buf.put(array, array.length, 0);
693 assertEquals(buf.position(), 0);
695 buf.put(array, 0, -1);
696 fail("Should throw Exception");
697 } catch (IndexOutOfBoundsException e) {
701 buf.put((double[])null, 0, -1);
702 fail("Should throw Exception");
703 } catch (NullPointerException e) {
707 buf.put(array, 2, array.length);
708 fail("Should throw Exception");
709 } catch (IndexOutOfBoundsException e) {
713 buf.put(array, Integer.MAX_VALUE, 1);
714 fail("Should throw Exception");
715 } catch (IndexOutOfBoundsException e) {
719 buf.put(array, 1, Integer.MAX_VALUE);
720 fail("Should throw Exception");
721 } catch (IndexOutOfBoundsException e) {
724 assertEquals(buf.position(), 0);
726 loadTestData2(array, 0, array.length);
727 DoubleBuffer ret = buf.put(array, 0, array.length);
728 assertEquals(buf.position(), buf.capacity());
729 assertContentEquals(buf, array, 0, array.length);
730 assertSame(ret, buf);
734 * Class under test for java.nio.DoubleBuffer put(java.nio.DoubleBuffer)
737 level = TestLevel.PARTIAL_COMPLETE,
738 notes = "Doesn't verify ReadOnlyBufferException.",
740 args = {java.nio.DoubleBuffer.class}
742 public void testPutDoubleBuffer() {
743 DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());
747 fail("Should throw Exception");
748 } catch (IllegalArgumentException e) {
752 buf.put(DoubleBuffer.allocate(buf.capacity() + 1));
753 fail("Should throw Exception");
754 } catch (BufferOverflowException e) {
758 loadTestData2(other);
761 DoubleBuffer ret = buf.put(other);
762 assertEquals(other.position(), other.capacity());
763 assertEquals(buf.position(), buf.capacity());
764 assertContentEquals(other, buf);
765 assertSame(ret, buf);
769 * Class under test for java.nio.DoubleBuffer put(int, double)
772 level = TestLevel.PARTIAL_COMPLETE,
773 notes = "Doesn't verify ReadOnlyBufferException.",
775 args = {int.class, double.class}
777 public void testPutintdouble() {
779 for (int i = 0; i < buf.capacity(); i++) {
780 assertEquals(buf.position(), 0);
781 DoubleBuffer ret = buf.put(i, (double) i);
782 assertEquals(buf.get(i), (double) i, 0.0);
783 assertSame(ret, buf);
787 fail("Should throw Exception");
788 } catch (IndexOutOfBoundsException e) {
792 buf.put(buf.limit(), 0);
793 fail("Should throw Exception");
794 } catch (IndexOutOfBoundsException e) {
800 level = TestLevel.PARTIAL_COMPLETE,
805 public void testSlice() {
806 assertTrue(buf.capacity() > 5);
808 buf.limit(buf.capacity() - 1);
810 DoubleBuffer slice = buf.slice();
811 assertEquals(buf.isReadOnly(), slice.isReadOnly());
812 assertEquals(buf.isDirect(), slice.isDirect());
813 assertEquals(buf.order(), slice.order());
814 assertEquals(slice.position(), 0);
815 assertEquals(slice.limit(), buf.remaining());
816 assertEquals(slice.capacity(), buf.remaining());
819 fail("Should throw Exception");
820 } catch (InvalidMarkException e) {
824 // slice share the same content with buf
826 if (!slice.isReadOnly()) {
827 loadTestData1(slice);
828 assertContentLikeTestData1(buf, 1, 0, slice.capacity());
830 assertEquals(slice.get(1), 500, 0.0);
835 level = TestLevel.PARTIAL_COMPLETE,
840 public void testToString() {
841 String str = buf.toString();
842 assertTrue(str.indexOf("Double") >= 0 || str.indexOf("double") >= 0);
843 assertTrue(str.indexOf("" + buf.position()) >= 0);
844 assertTrue(str.indexOf("" + buf.limit()) >= 0);
845 assertTrue(str.indexOf("" + buf.capacity()) >= 0);
849 * test for method static DoubleBuffer wrap(double[] array) test covers
850 * following usecases: 1. case for check DoubleBuffer buf2 properties 2.
851 * case for check equal between buf2 and double array[] 3. case for check a
852 * buf2 dependens to array[]
855 level = TestLevel.PARTIAL_COMPLETE,
858 args = {double[].class}
860 public void test_Wrap$D() {
861 double array[] = new double[BUFFER_LENGTH];
862 loadTestData1(array, 0, BUFFER_LENGTH);
863 DoubleBuffer buf2 = DoubleBuffer.wrap(array);
865 // case: DoubleBuffer buf2 properties is satisfy the conditions
867 assertEquals(buf2.capacity(), array.length);
868 assertEquals(buf2.limit(), array.length);
869 assertEquals(buf2.position(), 0);
871 // case: DoubleBuffer buf2 is equal to double array[]
872 assertContentEquals(buf2, array, 0, array.length);
874 // case: DoubleBuffer buf2 is depended to double array[]
875 loadTestData2(array, 0, buf.capacity());
876 assertContentEquals(buf2, array, 0, array.length);
880 * test for method static DoubleBuffer wrap(double[] array, int offset, int
881 * length) test covers following usecases: 1. case for check DoubleBuffer
882 * buf2 properties 2. case for check equal between buf2 and double array[]
883 * 3. case for check a buf2 dependens to array[] 4. case expected
884 * IndexOutOfBoundsException
887 level = TestLevel.PARTIAL_COMPLETE,
890 args = {double[].class, int.class, int.class}
892 public void test_Wrap$DII() {
893 double array[] = new double[BUFFER_LENGTH];
895 int length = BUFFER_LENGTH - offset;
896 loadTestData1(array, 0, BUFFER_LENGTH);
897 DoubleBuffer buf2 = DoubleBuffer.wrap(array, offset, length);
899 // case: DoubleBuffer buf2 properties is satisfy the conditions
901 assertEquals(buf2.capacity(), array.length);
902 assertEquals(buf2.position(), offset);
903 assertEquals(buf2.limit(), offset + length);
904 assertEquals(buf2.arrayOffset(), 0);
906 // case: DoubleBuffer buf2 is equal to double array[]
907 assertContentEquals(buf2, array, 0, array.length);
909 // case: DoubleBuffer buf2 is depended to double array[]
910 loadTestData2(array, 0, buf.capacity());
911 assertContentEquals(buf2, array, 0, array.length);
913 // case: expected IndexOutOfBoundsException
916 buf2 = DoubleBuffer.wrap(array, offset, length);
917 fail("wrap method does not throws expected exception");
918 } catch (IndexOutOfBoundsException e) {
923 void loadTestData1(double array[], int offset, int length) {
924 for (int i = 0; i < length; i++) {
925 array[offset + i] = (double) i;
929 void loadTestData2(double array[], int offset, int length) {
930 for (int i = 0; i < length; i++) {
931 array[offset + i] = (double) length - i;
935 void loadTestData1(DoubleBuffer buf) {
937 for (int i = 0; i < buf.capacity(); i++) {
938 buf.put(i, (double) i);
942 void loadTestData2(DoubleBuffer buf) {
944 for (int i = 0; i < buf.capacity(); i++) {
945 buf.put(i, (double) buf.capacity() - i);
949 private void assertContentEquals(DoubleBuffer buf, double array[],
950 int offset, int length) {
951 for (int i = 0; i < length; i++) {
952 assertEquals(buf.get(i), array[offset + i], 0.01);
956 private void assertContentEquals(DoubleBuffer buf, DoubleBuffer other) {
957 assertEquals(buf.capacity(), other.capacity());
958 for (int i = 0; i < buf.capacity(); i++) {
959 assertEquals(buf.get(i), other.get(i), 0.01);
963 private void assertContentLikeTestData1(DoubleBuffer buf, int startIndex,
964 double startValue, int length) {
965 double value = startValue;
966 for (int i = 0; i < length; i++) {
967 assertEquals(buf.get(startIndex + i), value, 0.01);