// zweic - test program for term typing checks
// M. Ganguin, J. Ruffin 2005
// Ident
class foo {
Int y;
Null bar() {
Int x = 0;
y; // 1/1 failure of clause 1
x; // success
}
}
// Select
class bar {
Int h;
Null foo() {
foo f = new foo(1);
k.h; // 1/2 failure of clauses 1 and 2 (nonexistent ident)
bar h = new bar(1); // success of recursive class definition
f.x; // 2/2 failure of clause 3
f.y; // success
}
}
// Call
class bof extends bar {
}
class baz {
Int x;
Null works(Int a, bar c) {}
Null foo() {
bof b = new bof(1);
foo h = new foo(1);
baz z = new baz(1);
k.foo(); // 1/4 failure of clauses 1 and 2 (nonexistent ident)
h.gneuh(); // 2/4 failure of clause 3 (nonexistent method)
z.works(1); // 3/4 failure of clause 3 (wrong number of arguments)
z.works(1, h); // 4/4 failure of clause 4 (parameter not subtype of bof)
z.works(2, b); // success
}
}
// New
class testnew {
Int x;
Null foo() {
new unknown(); // 1/3 failure of clause 1 (nonexistent class)
bar b = new bar(); // 2/3 failure of clauses 2 and 3 (wrong number of arguments)
bar c = new bar(bof); // 3/3 failure of clauses 2 and 3 (argument not subtype of Int)
foo f = new foo(1); // success
}
}
// IntLit : untestable
// NullLit : untestable
// UnOp
class UnOpTest {
Null foo() {
Int x = 2;
Null z = null;
-y; // 1/2 failure of clause 1 (nonexistent ident)
-z; // 2/2 failure of clause 1 (ident not of type Int)
-x; // success
!x; // success
}
}
// Binop
class BinOpTest {
Null foo() {
Int x1 = 2;
Int x2 = 3;
Null z = null;
k + x2; // 1/4 failure of clause 1 (nonexistent ident)
x1 + l; // 2/4 failure of clause 2 (nonexistent ident)
z + x2; // 3/4 failure of clause 1 (type of ident not Int)
x1 + z; // 4/4 failure of clause 2 (type of ident not Int)
x1 + x2; // success
}
}
// ObjComp
class ObjCompTest {
Null foo() {
bar b = new bar(1);
bof z = new bof(1);
foo f = new foo(2);
f + b; // 1/5 failure of clause 1 (binop not == or !=)
k == b; // 2/5 failure of clause 2 (nonexistent ident)
b == l; // 3/5 failure of clause 2 (nonexistent ident)
f == b; // 4/5 failure of clause 3 (subtype mismatch)
b == f; // 5/5 failure of clause 3 (subtype mismatch)
z == b; // success
}
}
// ReadInt : untestable
// ReadChar : untestable
// If
class IfTest {
Null foo() {
Int t = 0;
Null n = null;
bar b = new bar(2);
bof z = new bof(3);
if(k) {} else {}; // 1/7 failure of clause 1 (nonexistent condition)
if(n) {} else {}; // 2/7 failure of clause 1 (condition not Int)
if(t) {gorh g = null;return g} else 2; // 3/7 failure of clause 2 (unknown type)
if(t) 2 else {gorh g = null;return g }; // 4/7 failure of clause 2 (unknown type)
if(t) {foo f = new foo(1);return f} else 2; // 5/7 failure of clause 3 (LUB not found)
if(t) 2 else {foo f = new foo(2);return f}; // 6/7 failure of clause 3 (LUB not found)
bof y = if (t) b else z; // 7/7 failure of clause 3 (return type mismatch)
if(t) 2 else 3; // success
if(t) b else z; // success
}
}
// Block
class BlockTest {
Null foo() {
{
Int x = null; // 1/2 failure of clause 1 (incorrectly typed statement in block)
return x
};
{
Int x = 2;
return y // 2/2 failure of clause 2 (expression not in block scope)
};
{
Int x = 2;
return x // success
};
}
}
0