Added tests
svn: r1357
This commit is contained in:
parent
b38ba4d10d
commit
3aeeac1fbe
|
@ -3,6 +3,225 @@
|
|||
|
||||
(prepare-for-tests "Advanced")
|
||||
|
||||
;;Execution tests without errors
|
||||
|
||||
(execute-test
|
||||
"public class Something {
|
||||
private int x;
|
||||
public boolean equals( Object o ) {
|
||||
return (o instanceof Something) && x == ((Something) o).x;
|
||||
}
|
||||
}"
|
||||
'advanced
|
||||
#f
|
||||
"Correct overriding of equals")
|
||||
|
||||
(execute-test
|
||||
"public interface F {
|
||||
int f();
|
||||
}
|
||||
public class P implements F {
|
||||
private int g;
|
||||
public int f() { return g; }
|
||||
}" 'advanced #f "Correct implementing of public interface")
|
||||
|
||||
(execute-test
|
||||
"public class Statics {
|
||||
public static int[] a;
|
||||
public static boolean b;
|
||||
private static boolean c;
|
||||
|
||||
public static void main( String[] args) {
|
||||
return;
|
||||
}
|
||||
public static int getA( int pos) {
|
||||
return a[pos];
|
||||
}
|
||||
}" 'advanced #f "Class containing several static members")
|
||||
|
||||
(execute-test
|
||||
"public class Inits {
|
||||
private int f;
|
||||
private boolean condition;
|
||||
|
||||
public Inits() { }
|
||||
|
||||
{ if (condition)
|
||||
f = 4;
|
||||
else
|
||||
f = 3;
|
||||
}
|
||||
}"
|
||||
'advanced #f "Class containing inits")
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
final int x() { return 4; }
|
||||
}"
|
||||
'advanced #f "Class with final method")
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
int x() { return 3; }
|
||||
int x( int y ) { return y; }
|
||||
}" 'advanced #f "Class with overloaded methods")
|
||||
|
||||
;;Execution tests with errors
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
final int x = 4;
|
||||
}" 'advanced #t "Class with final field")
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
final int x() { return 3; }
|
||||
}
|
||||
class Y extends X {
|
||||
int x() { return 3 ; }
|
||||
}" 'advanced #t "Attempt to override a final method")
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
public int x () { return 3 ; }
|
||||
}
|
||||
class Y extends X {
|
||||
int x() { return super.x() + 3; }
|
||||
}" 'advanced #t "Attempt to weaken access privlege")
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
{ x = 3;
|
||||
int x; }
|
||||
}" 'advanced #t "Attempt to set before named, init")
|
||||
|
||||
(execute-test
|
||||
"class X { X() { this(1); }
|
||||
X(int i) { this(); }}"
|
||||
'advanced #t "Cyclic calls to this")
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
int x() { return 3; }
|
||||
int x( int x ) { return 35; }
|
||||
int y() { return x(3,5); }
|
||||
}" 'advanced #t "Miss overload call")
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
int x() { return 3; }
|
||||
int x( int y, int z ) { return y; }
|
||||
int y() { return x(y()); }
|
||||
}" 'advanced #t "Miss overload call the other way")
|
||||
|
||||
(execute-test
|
||||
"class X {
|
||||
int x() { return 3; }
|
||||
boolean x(int y) { return true; }
|
||||
int f() { return x(3); }
|
||||
}" 'advanced #t "Miss overloading")
|
||||
|
||||
(execute-test
|
||||
"public class StatInits {
|
||||
private static int x;
|
||||
static { x = 45; }
|
||||
}" 'advanced #t "Class containing static inits")
|
||||
|
||||
(execute-test
|
||||
"public class F {
|
||||
public f() { return 3; }
|
||||
}"
|
||||
'advanced #t "Forgotten return type after public")
|
||||
|
||||
(execute-test
|
||||
"pulic class F { }"
|
||||
'advanced #t "Parse error, misspelled public")
|
||||
|
||||
(execute-test
|
||||
"class TestClass{
|
||||
ALoObj iterFilter(){
|
||||
for (;false;){}
|
||||
}
|
||||
}/end SameAuthor"
|
||||
'advanced
|
||||
#t "Parse error check")
|
||||
|
||||
(execute-test
|
||||
"class Today{
|
||||
|
||||
int dayNumber;
|
||||
boolean meetings;
|
||||
String QoD;
|
||||
|
||||
Today(int dayNumber, boolean meetings, String QoD)
|
||||
{
|
||||
this.dayNumber = dayNumber;
|
||||
this.meetings = meetings;
|
||||
this.QoD = QoD;
|
||||
}
|
||||
|
||||
int getDayNumber()
|
||||
{
|
||||
return dayNumber;
|
||||
}
|
||||
|
||||
boolean getMeetings()
|
||||
{
|
||||
return meetings;
|
||||
}
|
||||
|
||||
void setMeetings()
|
||||
{
|
||||
this.meetings = true;
|
||||
}
|
||||
|
||||
String getQoD()
|
||||
{
|
||||
return QoD;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class WeeklyPlanner{
|
||||
|
||||
Today[] weeklyPlanner;
|
||||
int totalDays = 7;
|
||||
|
||||
WeeklyPlanner()
|
||||
{
|
||||
|
||||
weeklyPlanner = new Today[totalDays];
|
||||
|
||||
for(int i = 0; i < totalDays; i++)
|
||||
{
|
||||
weeklyPlanner[i] = new Today(i, False, \"\");
|
||||
}
|
||||
}
|
||||
|
||||
void addMeeting(int dayNumber)
|
||||
{
|
||||
weeklyPlanner[dayNumber].setMeetings(); ////////<<<<<<<<Expected assignment, found ., which is not valid for a statement
|
||||
}
|
||||
|
||||
int howManyMeetings()
|
||||
{
|
||||
int numberMeetings = 0;
|
||||
|
||||
for(int i = 0; i < totalDays; i++)
|
||||
{
|
||||
if (weeklyPlanner[i].getMeetings())
|
||||
numberMeetings++;
|
||||
}
|
||||
|
||||
return numberMeetings;
|
||||
}
|
||||
as
|
||||
}
|
||||
" 'advanced #t "Parsing test from student program. Should mention {")
|
||||
|
||||
;;Interaction tests, mix of right and error
|
||||
|
||||
(interact-test 'advanced
|
||||
(list "new int[3] instanceof int[] && true"
|
||||
"((int[]) new int[3])[1]" "3/2")
|
||||
|
@ -26,14 +245,30 @@
|
|||
(list null #;0)
|
||||
"multi-dimension array - not all intialized")
|
||||
|
||||
(execute-test
|
||||
"class TestClass{
|
||||
ALoObj iterFilter(){
|
||||
for (;false;){}
|
||||
}
|
||||
}/end SameAuthor"
|
||||
(interact-test
|
||||
'advanced
|
||||
#t "Parse error check")
|
||||
(list "int[] x = new int[10];" "for( int i = 0; i< x.length; i++) x[i]=i;" "x.length" "x[5]")
|
||||
(list '(void) '(void) 10 5)
|
||||
"Array & for loop")
|
||||
|
||||
(interact-test
|
||||
'advanced
|
||||
(list "int[3] x;" "int[] x = new int();" "x[][1]")
|
||||
(list 'error 'error 'error)
|
||||
"Array parse errors")
|
||||
|
||||
(interact-test
|
||||
'advanced
|
||||
(list "int[] x = { 1, 3, 4, 5};" "x[4]" "x[-1]" "x[0]=true;" "x[0]=0.01;")
|
||||
(list '(void) 'error 'error 'error 'error)
|
||||
"Array access and set errors")
|
||||
|
||||
(interact-test
|
||||
'advanced
|
||||
(list "int[] x = new int[2];" "boolean[] y = new boolean[2];" "char[] z = new char[2];"
|
||||
"Object[] o = new Object[2];" "x[0]" "y[0]" "z[0]" "o[0]")
|
||||
(list '(void) '(void) '(void) '(void) 0 #f #\null null)
|
||||
"Array initialization checks")
|
||||
|
||||
(report-test-results)
|
||||
|
||||
|
|
|
@ -3,6 +3,18 @@
|
|||
|
||||
(prepare-for-tests "Full")
|
||||
|
||||
(interact-test
|
||||
"class A {
|
||||
class B {
|
||||
A m = A.this;
|
||||
}
|
||||
B b = new B();
|
||||
}"
|
||||
'full
|
||||
(list "A a = new A();" "A.B b = a.new B();" "a.new B().m")
|
||||
(list '(void) '(void) 'a~f)
|
||||
"Inner class creation")
|
||||
|
||||
(execute-test "/* empty */"
|
||||
'full
|
||||
#f
|
||||
|
|
Loading…
Reference in New Issue
Block a user