(module advanced-tests mzscheme (require (lib "profj-testing.ss" "profj")) (prepare-for-tests "Advanced") ;;Execution tests without errors (interact-test 'advanced '("null.m()") '(error) "Calling a method on null") (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(); ////////<<<<<<<