Homework 4
This commit is contained in:
parent
0afc86ceeb
commit
72cc3206c4
125 changed files with 4200 additions and 1636 deletions
12
javali_tests/HW4_nop90/Array/ErrArrayIndex.javali
Normal file
12
javali_tests/HW4_nop90/Array/ErrArrayIndex.javali
Normal file
|
@ -0,0 +1,12 @@
|
|||
/* Test accessing arrays with invalid index*/
|
||||
class Main {
|
||||
void main() {
|
||||
int[] x;
|
||||
x = new int[5];
|
||||
x[0] = 3;
|
||||
x[1] = 4;
|
||||
x[2] = 5;
|
||||
|
||||
x[5] = 5; //this should fail
|
||||
}
|
||||
}
|
9
javali_tests/HW4_nop90/Array/ErrArrayIndex2.javali
Normal file
9
javali_tests/HW4_nop90/Array/ErrArrayIndex2.javali
Normal file
|
@ -0,0 +1,9 @@
|
|||
/* Test accessing arrays with invalid index*/
|
||||
class Main {
|
||||
void main() {
|
||||
int[] x;
|
||||
x = new int[5];
|
||||
|
||||
x[8] = 5; //this should fail
|
||||
}
|
||||
}
|
9
javali_tests/HW4_nop90/Array/ErrArrayIndex3.javali
Normal file
9
javali_tests/HW4_nop90/Array/ErrArrayIndex3.javali
Normal file
|
@ -0,0 +1,9 @@
|
|||
/* Test accessing arrays with invalid index*/
|
||||
class Main {
|
||||
void main() {
|
||||
int[] x;
|
||||
x = new int[5];
|
||||
|
||||
x[-1] = 5; //this should fail
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
/* Test access an array on a null pointer */
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int[] x;
|
||||
x = null;
|
||||
|
||||
x[1] = 5; //this should throw null pointer exception
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
/* Test access an array on a null pointer */
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int[] x;
|
||||
|
||||
x[1] = 5; //this should throw null pointer exception
|
||||
}
|
||||
}
|
10
javali_tests/HW4_nop90/Array/ErrArraySize.javali
Normal file
10
javali_tests/HW4_nop90/Array/ErrArraySize.javali
Normal file
|
@ -0,0 +1,10 @@
|
|||
/* Test creating an array with negative length */
|
||||
class Main {
|
||||
void main() {
|
||||
int[] x;
|
||||
x = new int[-3];
|
||||
x[0] = 3;
|
||||
x[1] = 4;
|
||||
x[2] = 5;
|
||||
}
|
||||
}
|
16
javali_tests/HW4_nop90/Array/OkArrayAccess.javali
Normal file
16
javali_tests/HW4_nop90/Array/OkArrayAccess.javali
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* Test accessing arrays */
|
||||
class Main {
|
||||
void main() {
|
||||
int[] x;
|
||||
int i;
|
||||
x = new int[3];
|
||||
x[0] = 3;
|
||||
x[1] = 4;
|
||||
x[2] = 5;
|
||||
i = x[0] + x[1] + x[2];
|
||||
x[2]=55;
|
||||
write(i);
|
||||
writeln();
|
||||
}
|
||||
}
|
||||
|
15
javali_tests/HW4_nop90/Array/OkArrayAccess2.javali
Normal file
15
javali_tests/HW4_nop90/Array/OkArrayAccess2.javali
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* Test creating arrays of objects and accessing a null element*/
|
||||
|
||||
class A{}
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
A[] x;
|
||||
A a;
|
||||
x = new A[3];
|
||||
x[1] = new A();
|
||||
x[2] = a;
|
||||
|
||||
x[2] = new A();
|
||||
}
|
||||
}
|
8
javali_tests/HW4_nop90/Array/OkArraySizeIsZero.javali
Normal file
8
javali_tests/HW4_nop90/Array/OkArraySizeIsZero.javali
Normal file
|
@ -0,0 +1,8 @@
|
|||
/* Test array size=0 */
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int[] x;
|
||||
x = new int[0];
|
||||
}
|
||||
}
|
12
javali_tests/HW4_nop90/Array/OkFieldArray.javali
Normal file
12
javali_tests/HW4_nop90/Array/OkFieldArray.javali
Normal file
|
@ -0,0 +1,12 @@
|
|||
/* Test Arrays as Fields */
|
||||
|
||||
class Main {
|
||||
int[] x;
|
||||
void main() {
|
||||
int i;
|
||||
x = new int[3];
|
||||
x[0] = 3;
|
||||
x[1] = 4;
|
||||
x[2] = 5;
|
||||
}
|
||||
}
|
19
javali_tests/HW4_nop90/Array/OkInheritedArray.javali
Normal file
19
javali_tests/HW4_nop90/Array/OkInheritedArray.javali
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* Test inherited Array */
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
C1 c1;
|
||||
C2 c2;
|
||||
c1 = new C1();
|
||||
c2 = new C2();
|
||||
c1.x = new int[3];
|
||||
c2.x = new int[4];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class C1{
|
||||
int[] x;
|
||||
}
|
||||
|
||||
class C2 extends C1 {}
|
11
javali_tests/HW4_nop90/Array/OkObjectArray.javali
Normal file
11
javali_tests/HW4_nop90/Array/OkObjectArray.javali
Normal file
|
@ -0,0 +1,11 @@
|
|||
/* Test creating arrays of objects */
|
||||
|
||||
class A{}
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
A[] x;
|
||||
x = new A[2];
|
||||
x[0] = new A();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue