From 8a3a8878571463c04832133db12488503944226c Mon Sep 17 00:00:00 2001 From: Kathy Gray Date: Sat, 11 Aug 2007 11:42:21 +0000 Subject: [PATCH] Committing modifications to test cases; committing small modification to grammar spec; Committing change to docpos to add new profj language manual svn: r7081 --- collects/help/private/docpos.ss | 3 +- collects/profj/comb-parsers/parser-units.scm | 4 +- collects/tests/profj/all-tests.ss | 1 + collects/tests/profj/beginner-tests.ss | 58 +++++++++++++++----- collects/tests/profj/beginnerTest.java | 26 +++++---- collects/tests/profj/intermediate-tests.ss | 39 +++++++++---- collects/tests/profj/intermediateTest.java | 25 +++++---- 7 files changed, 107 insertions(+), 49 deletions(-) diff --git a/collects/help/private/docpos.ss b/collects/help/private/docpos.ss index eb2dcfdaa0..364ad70e67 100644 --- a/collects/help/private/docpos.ss +++ b/collects/help/private/docpos.ss @@ -55,7 +55,8 @@ ("profj-beginner" "ProfessorJ Beginner Language" 210) ("profj-intermediate" "ProfessorJ Intermediate Language" 211) - ("profj-advanced" "ProfessorJ Advanced Language" 212))) + ("profj-intermediate-access" "ProfessorJ Intermediate + access Language" 212) + ("profj-advanced" "ProfessorJ Advanced Language" 213))) (define known-docs (map (lambda (x) (cons (string->path (car x)) (cadr x))) docs-and-positions)) diff --git a/collects/profj/comb-parsers/parser-units.scm b/collects/profj/comb-parsers/parser-units.scm index 172c5b2d80..c968c51acb 100644 --- a/collects/profj/comb-parsers/parser-units.scm +++ b/collects/profj/comb-parsers/parser-units.scm @@ -606,9 +606,11 @@ ;Note -- should enfore name to be identifier.identifier instead of name (define import-dec + (let ([name (sequence (identifier (repeat-greedy (sequence (PERIOD identifier) id "import name"))) + id "import name")]) (choose ((sequence (import name PERIOD TIMES SEMI_COLON) id) - (sequence (import name SEMI_COLON) id)) "import declaration")) + (sequence (import name SEMI_COLON) id)) "import declaration"))) (define (make-program package import body) (let ([p&i (sequence (package import body) id "program")] diff --git a/collects/tests/profj/all-tests.ss b/collects/tests/profj/all-tests.ss index 55c8d7158e..66add527b4 100644 --- a/collects/tests/profj/all-tests.ss +++ b/collects/tests/profj/all-tests.ss @@ -1,6 +1,7 @@ (module all-tests mzscheme (require "full-tests.ss") (require "advanced-tests.ss") + (require "intermediate-access-tests.scm") (require "intermediate-tests.ss") (require "beginner-tests.ss") ) \ No newline at end of file diff --git a/collects/tests/profj/beginner-tests.ss b/collects/tests/profj/beginner-tests.ss index b2eea91032..bb075c7186 100644 --- a/collects/tests/profj/beginner-tests.ss +++ b/collects/tests/profj/beginner-tests.ss @@ -32,7 +32,7 @@ boolean t9 = check new MyClass(\"\").field expect \"\"; boolean t10 = check new MyClass(\"\").method() expect new MyClass(\"\"); - CorrectChecks() { this.t= check 1 expect 4; } + CorrectChecks(boolean t) { this.t= t; } }" language #f "Class with many different style of checks within it") @@ -100,10 +100,11 @@ this.x = x; } int lessThan( int y) { - if (y < this.x) + if (y < this.x) { return -1; - else + } else { return 1; + } } }" language #f "Class & interface, containing if statement") @@ -125,11 +126,11 @@ (execute-test "class A { B var; - A() { this.var = new B(); } + A(B var) { this.var = var; } } class B { A var; - B() { this.var = new A(); } + B( A var) { this.var = var; } }" language #f "Two classes with cycles: cannot be instantiated") (execute-test @@ -143,6 +144,30 @@ ;;Execution tests that should produce errors + (execute-test + "class UseNoSet { + Object x; + Object y = this.x; + UseNoSet(Object x) { this.x = x; } + }" language #t "using fields before setting them") + + (execute-test + "class DoubleSet { + int x; + DoubleSet(int x, int y) { + this.x = x; + this.x = y; + } + }" language #t "Setting a field twice, in the constructor") + + (execute-test + "class DoubleSet2 { + int x = 3; + DoubleSet2(int x) { + this.x = x; + } + }" language #t "Setting a field twice, init and ctor") + (execute-test "class CorrectChecks { @@ -159,7 +184,7 @@ () - CorrectChecks() { this.t= check 1 expect 4; } + CorrectChecks(boolean t) { this.t= t; } }" language #t "Correct checks, followed by a parse error: should mention (") @@ -180,14 +205,14 @@ Z y; A(int z) { this.z = z; - this.y = new B(); + this.y = y;//new B(); } } class B implements Z { B() { } int x() { return 3; } - int oX() { if (this.x() == 3) return 5; else return 6; } + int oX() { if (this.x() == 3) { return 5; } else { return 6; } } } foo" language #t "Parse-error test, mentioning foo") @@ -279,7 +304,7 @@ (execute-test "class F1 { F1(int x) { - x = 4; + x = x; } }" 'beginner #t "Set non-field") @@ -288,7 +313,7 @@ "class F2 { int f; F2() { - this.f = this.f; + this.f = f; } }" 'beginner #t "Set with field") @@ -355,12 +380,15 @@ this.numPages = numPages; } String level() { - if ( this.numPages < 10 ) + if ( this.numPages < 10 ) { return \"Apprentice\"; - else if (this.numPages < 100) - return \"Journeyman\"; - else - return \"Master\"; + } else { + if (this.numPages < 100) { + return \"Journeyman\"; + } else { + return \"Master\"; + } + } } } " diff --git a/collects/tests/profj/beginnerTest.java b/collects/tests/profj/beginnerTest.java index 2453753a83..31079999ec 100644 --- a/collects/tests/profj/beginnerTest.java +++ b/collects/tests/profj/beginnerTest.java @@ -37,12 +37,15 @@ class Car implements Automobile { } double price(int year) { - if ((2006 - year) == 0) + if ((2006 - year) == 0) { return this.basePrice; - else if ((2006 - year) > 0) - return this.basePrice - (this.basePrice / (2006 - year)); - else - return this.basePrice + (this.basePrice / (year - 2006)); + } else { + if ((2006 - year) > 0) { + return this.basePrice - (this.basePrice / (2006 - year)); + } else { + return this.basePrice + (this.basePrice / (year - 2006)); + } + } } } @@ -91,10 +94,11 @@ class Truck implements Automobile { int milesTraveled() { return this.miles; } String makeAndModel() { - if (this.extendedBed) + if (this.extendedBed) { return this.make.concat("Extended"); - else + } else { return this.make.concat(String.valueOf(this.numDoors)); + } } Automobile travel(int miles) { return new Truck(this.make, this.miles + miles, this.numDoors, this.extendedBed, this.basePrice); @@ -102,10 +106,11 @@ class Truck implements Automobile { double price( int year ) { // Uncomment to test runtime error behavior //return this.basePrice - (2 * (this.basePrice / (2006 -year))); - if (year == 2006) + if (year == 2006) { return this.basePrice; - else + } else { return this.basePrice - (2 * (this.basePrice / (2006 - year))); + } } } @@ -132,5 +137,6 @@ class TruckExamples { return (check this.oneTruck.makeAndModel() expect "Toyota2") && (check this.twoTruck.makeAndModel() expect "FordExtended"); } + +} -} \ No newline at end of file diff --git a/collects/tests/profj/intermediate-tests.ss b/collects/tests/profj/intermediate-tests.ss index 3727886aa1..45847fc58b 100644 --- a/collects/tests/profj/intermediate-tests.ss +++ b/collects/tests/profj/intermediate-tests.ss @@ -327,6 +327,14 @@ ;;Execute tests with errors + (execute-test + " +interface I {} + +interface J extends I {} + +abstract class implements J {}" 'intermediate #t "Parser error, class identifier") + (execute-test "class CheckError { void foo() { } @@ -433,11 +441,12 @@ //in the original list that are longer than the given number. List longer(int n){ - if (n <= this.first.length) + if (n <= this.first.length) { rest.longer(n); - else + } else { rest.longer(n) return this.first; + } } }" 'intermediate #t "Incorrect statement- parse error") @@ -522,10 +531,11 @@ (interact-test "import draw.*; + import colors.*; class BlockWorld extends World { int WIDTH = 100; int HEIGHT = 100; - Color BACKGROUND = new Red(); + AColor BACKGROUND = new Red(); DrpBlock block; BlockWorld(DrpBlock block) { this. block = block; @@ -575,24 +585,29 @@ class DrpBlock { return w.theCanvas.drawRect(new Posn(this.right,this.down),this.HEIGHT,this.WIDTH,w.BACKGROUND); } boolean hasLanded(BlockWorld w) { - if (this. down + this. HEIGHT >= w.HEIGHT) + if (this. down + this. HEIGHT >= w.HEIGHT) { return true; - else + } else { return false; + } } DrpBlock steer(String ke) { - if (ke.equals(\"left\")) + if (ke.equals(\"left\")) { return new DrpBlock(this. down,this. right - this. deltaX); - else if (ke.equals(\"right\")) - return new DrpBlock(this. down,this. right + this. deltaX); - else - return this; + } else { + if (ke.equals(\"right\")) { + return new DrpBlock(this. down,this. right + this. deltaX); + } else { + return this; + } + } } boolean toStop(BlockWorld w, int down) { - if (this. down + this. HEIGHT >= down) + if (this. down + this. HEIGHT >= down) { return true; - else + } else { return false; + } } }" 'intermediate diff --git a/collects/tests/profj/intermediateTest.java b/collects/tests/profj/intermediateTest.java index 5ad16e3bb1..ccf0976318 100644 --- a/collects/tests/profj/intermediateTest.java +++ b/collects/tests/profj/intermediateTest.java @@ -26,12 +26,15 @@ class Car extends Auto { } double price(int year) { - if ((2006 - year) == 0) + if ((2006 - year) == 0) { return this.basePrice; - else if ((2006 - year) > 0) - return this.basePrice - (this.basePrice / (2006 - year)); - else - return this.basePrice + (this.basePrice / (year - 2006)); + } else { + if ((2006 - year) > 0) { + return this.basePrice - (this.basePrice / (2006 - year)); + } else { + return this.basePrice + (this.basePrice / (year - 2006)); + } + } } } @@ -77,18 +80,20 @@ class Truck extends Auto { } String makeAndModel() { - if (this.extendedBed) + if (this.extendedBed) { return this.make.concat("Extended"); - else + } else { return this.make.concat(String.valueOf(this.numDoors)); + } } double price( int year ) { // Uncomment to test runtime error behavior //return this.basePrice - (2 * (this.basePrice / (2006 -year))); - if (year == 2006) + if (year == 2006) { return this.basePrice; - else + } else { return this.basePrice - (2 * (this.basePrice / (2006 - year))); + } } } @@ -116,5 +121,5 @@ class TruckExamples { return (check this.oneTruck.makeAndModel() expect "Toyota2") && (check this.twoTruck.makeAndModel() expect "FordExtended"); } - + } \ No newline at end of file