(module advanced-tests mzscheme (require "profj-testing.ss") (require profj/libs/java/lang/String) (prepare-for-tests "Advanced") ;;Execution tests without errors (execute-test "interface mustbepublic { int a(); int b(); } class musthavepublic implements mustbepublic { public int a() { return 3; } public int b() { return 5; } }" 'advanced #f "public implementation of an interface" ) (execute-test "class OneC { } class TwoC extends OneC { } class ThreeC extends TwoC { } class Overload { int num(OneC o) { return 1; } int num(TwoC o) { return 2; } int t() { return num(new ThreeC()); } } " 'advanced #f "Overloading resolution") (execute-test "class Checkclass { } class ExampleCheck { boolean t1 = check new Checkclass[10] expect new Checkclass[10]; boolean t2 = check (new int[3])[1] expect 0; }" 'advanced #f "check expressions") (execute-test "class Blah { Blah () {} int addUp (int top) { int answer = 0; int counter = 1; while (counter <= top) { answer += counter; ++counter; } return answer; } }" 'advanced #f "while loop with statements after") (execute-test "interface Abs { int a( int x); } abstract class Babs implements Abs { } " 'advanced #f "abs. class with interface not all impl., with args") (execute-test "public class Xprivate { private int x() { return 3; } }" 'advanced #f "Class with private method") (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 Xfinal { final int x() { return 4; } }" 'advanced #f "Class with final method") (execute-test "class Xoverload { int x() { return 3; } int x( int y ) { return y; } }" 'advanced #f "Class with overloaded methods") (execute-test "class Ret { boolean rets() { if (true) return true; return false; } }" 'advanced #f "If with no else, reachable return") ;;Execution tests with errors (execute-test "interface a { int a(); } class b implements a{ int a() { return 3; } }" 'advanced #t "Interface implement without public" ) (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 Xth { Xth() { this(1); } Xth(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(); ////////<<<<<<<