Committing modifications to test cases;

committing small modification to grammar spec;

Committing change to docpos to add new profj language manual

svn: r7081
This commit is contained in:
Kathy Gray 2007-08-11 11:42:21 +00:00
parent e304444620
commit 8a3a887857
7 changed files with 107 additions and 49 deletions

View File

@ -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))

View File

@ -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")]

View File

@ -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")
)

View File

@ -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\";
}
}
}
}
"

View File

@ -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");
}
}
}

View File

@ -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

View File

@ -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");
}
}