/* *Trybadrangevalues,32bitget/put.
*/ staticvoid checkRange32(int[] ints, int[] empty, int negVal1, int negVal2) {
System.out.println("Array.checkRange32"); int i = 0;
Main.assertTrue(ints.length == 5);
try {
i = ints[5]; // exact bound
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
ints[5] = i; // exact bound
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
i = ints[6]; // one past
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
i = ints[negVal1]; // -1
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
ints[negVal1] = i; // -1
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
i = ints[negVal2]; // min int
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
}
try {
i = empty[1];
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
}
}
/* *Trybadrangevalues,64bitget/put.
*/ staticvoid checkRange64(long[] longs, int negVal1, int negVal2) {
System.out.println("Array.checkRange64"); long l = 0L;
Main.assertTrue(longs.length == 5);
try {
l = longs[5]; // exact bound
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
longs[5] = l; // exact bound
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
l = longs[6]; // one past
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
l = longs[negVal1]; // -1
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
longs[negVal1] = l; // -1
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
} try {
l = longs[negVal2]; // min int
Main.assertTrue(false);
} catch (ArrayIndexOutOfBoundsException aioobe) { // good
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.