Homework 3
This commit is contained in:
parent
bf60a078d7
commit
0afc86ceeb
129 changed files with 3163 additions and 4316 deletions
|
@ -0,0 +1,9 @@
|
|||
// The arguments of a BinaryOp (except == and !=) must be of the type specified by the operator
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int a;
|
||||
boolean b;
|
||||
write( a + b );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// Error: both sides of a BinaryOp (except == and !=) must be of the same type
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int a, b, c;
|
||||
boolean d, e;
|
||||
a = a + b;
|
||||
d = a <= b;
|
||||
d = b && c;
|
||||
}
|
||||
}
|
25
javali_tests/HW3_nop90/OperatorTests/ErrorEquals.javali
Normal file
25
javali_tests/HW3_nop90/OperatorTests/ErrorEquals.javali
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Test the equal/not equal operations
|
||||
// this test should trigger an TYPE ERROR
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
C1 a;
|
||||
C3 d;
|
||||
D1 f;
|
||||
boolean x,y,z;
|
||||
a = new C1();
|
||||
d = new C3();
|
||||
f = new D1();
|
||||
|
||||
y = f == d;
|
||||
x = a != f;
|
||||
}
|
||||
}
|
||||
|
||||
class C1 {}
|
||||
|
||||
class C2 extends C1{}
|
||||
|
||||
class C3 extends C2{}
|
||||
|
||||
class D1 {}
|
19
javali_tests/HW3_nop90/OperatorTests/ErrorUnaryOp.javali
Normal file
19
javali_tests/HW3_nop90/OperatorTests/ErrorUnaryOp.javali
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Test type errors with unary operator
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int x,y,z;
|
||||
boolean a;
|
||||
x = -100;
|
||||
y = 5;
|
||||
|
||||
a = -true;
|
||||
z = -y;
|
||||
x = +x;
|
||||
write(x);
|
||||
writeln();
|
||||
write(z);
|
||||
writeln();
|
||||
write(-a);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// Test boolean && and || operators
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
boolean a, b, c;
|
||||
a = b && c || a;
|
||||
}
|
||||
}
|
31
javali_tests/HW3_nop90/OperatorTests/OkEquals.javali
Normal file
31
javali_tests/HW3_nop90/OperatorTests/OkEquals.javali
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Test the equal/not equal operations, one of the types must be a subtype of the other
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
C1 c1;
|
||||
C2 c2;
|
||||
C3 c3;
|
||||
Object o1, o2;
|
||||
boolean s;
|
||||
|
||||
o1 = new Object();
|
||||
o2 = new Object();
|
||||
c1 = new C1();
|
||||
c2 = new C2();
|
||||
c3 = new C3();
|
||||
|
||||
s = o1 == o2;
|
||||
s = c1 != c2;
|
||||
s = c3 == c1;
|
||||
s = o2 != o1;
|
||||
s = null == c2;
|
||||
s = o1 == c2;
|
||||
s = null == o;
|
||||
}
|
||||
}
|
||||
|
||||
class C1 {}
|
||||
|
||||
class C2 extends C1{}
|
||||
|
||||
class C3 extends C2{}
|
36
javali_tests/HW3_nop90/OperatorTests/OkNot.javali
Normal file
36
javali_tests/HW3_nop90/OperatorTests/OkNot.javali
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Test '!' operator
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
boolean a,b,c,d;
|
||||
int x,y;
|
||||
|
||||
a = true;
|
||||
c = !false;
|
||||
b = !a;
|
||||
x = 100;
|
||||
y = 5;
|
||||
|
||||
if (a) {
|
||||
write(1);}
|
||||
writeln();
|
||||
|
||||
if (!b){
|
||||
write(2);
|
||||
}
|
||||
writeln();
|
||||
|
||||
while(c){
|
||||
write(3);
|
||||
c = false;
|
||||
}
|
||||
writeln();
|
||||
|
||||
// !x < 2 * y --> !x type error
|
||||
// !(x < 2 * y) --> correct syntax
|
||||
while(!(x<2*y)){
|
||||
write(y);
|
||||
y = y*2;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue