Homework 4

This commit is contained in:
Carlos Galindo 2020-01-15 22:34:57 +01:00
parent 0afc86ceeb
commit 72cc3206c4
Signed by: kauron
GPG key ID: 83E68706DEE119A3
125 changed files with 4200 additions and 1636 deletions

View 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
}
}

View 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
}
}

View 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
}
}

View file

@ -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
}
}

View file

@ -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
}
}

View 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;
}
}

View 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();
}
}

View 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();
}
}

View file

@ -0,0 +1,8 @@
/* Test array size=0 */
class Main {
void main() {
int[] x;
x = new int[0];
}
}

View 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;
}
}

View 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 {}

View 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();
}
}