From 097df98b3dcafd225205e3c69e6dbb8545a1832b Mon Sep 17 00:00:00 2001 From: Stephen Bloch Date: Sun, 10 Jul 2011 08:56:43 -0400 Subject: [PATCH] Fixed some more error messages. (cherry picked from commit 904ef63ce20def1ed5ca140f5caad0a6ab453703) --- .../picturing-programs/private/map-image.rkt | 64 +++++++++---------- .../tests/map-image-bsl-tests.rkt | 62 +++++++++--------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/collects/picturing-programs/private/map-image.rkt b/collects/picturing-programs/private/map-image.rkt index 1a420107c1..c9dc2cae03 100644 --- a/collects/picturing-programs/private/map-image.rkt +++ b/collects/picturing-programs/private/map-image.rkt @@ -86,7 +86,7 @@ (define (name->color name) (unless (or (string? name) (symbol? name)) (error 'name->color - (format "expected a string or symbol, but found ~v" name))) + (format "Expected a string or symbol, but found ~v" name))) (let [[result (send the-color-database find-color (if (string? name) name @@ -101,7 +101,7 @@ (cond [(color? thing) thing] [(eqv? thing #f) transparent] [(image-color? thing) (name->color thing)] - [else (error 'colorize (format "expected a color, but found ~v" thing))])) + [else (error 'colorize (format "Expected a color, but found ~v" thing))])) ; colorize-func : (... -> broad-color) -> (... -> color) (define (colorize-func f) @@ -214,11 +214,11 @@ (define (build-image w h f) (unless (natural? w) (error 'build-image - (format "Expected natural number as first argument, but found ~v" w))) + (format "Expected a natural number as first argument, but found ~v" w))) (unless (natural? h) (error 'build-image - (format "Expected natural number as second argument, but found ~v" h))) - (check-procedure-arity f 2 'build-image "Expected function with contract num(x) num(y) -> color as third argument") + (format "Expected a natural number as second argument, but found ~v" h))) + (check-procedure-arity f 2 'build-image "Expected a function with contract num(x) num(y) -> color as third argument") (build-image-internal w h (colorize-func f))) ; build-image/extra : natural(width) natural(height) (nat nat any -> broad-color) any -> image @@ -227,11 +227,11 @@ (define (build-image/extra w h f extra) (unless (natural? w) (error 'build-image/extra - (format "Expected natural number as first argument, but found ~v" w))) + (format "Expected a natural number as first argument, but found ~v" w))) (unless (natural? h) (error 'build-image/extra - (format "Expected natural number as second argument, but found ~v" h))) - (check-procedure-arity f 3 'build-image/extra "Expected function with contract num(x) num(y) any -> color as third argument") + (format "Expected a natural number as second argument, but found ~v" h))) + (check-procedure-arity f 3 'build-image/extra "Expected a function with contract num(x) num(y) any -> color as third argument") (build-image-internal w h (colorize-func (lambda (x y) (f x y extra))))) @@ -240,13 +240,13 @@ (define (build3-image w h rfunc gfunc bfunc) (unless (natural? w) (error 'build3-image - (format "Expected natural number as first argument, but found ~v" w))) + (format "Expected a natural number as first argument, but found ~v" w))) (unless (natural? h) (error 'build3-image - (format "Expected natural number as second argument, but found ~v" h))) - (check-procedure-arity rfunc 2 'build3-image "Expected function with contract num(x) num(y) -> color as third argument") - (check-procedure-arity gfunc 2 'build3-image "Expected function with contract num(x) num(y) -> color as fourth argument") - (check-procedure-arity bfunc 2 'build3-image "Expected function with contract num(x) num(y) -> color as fifth argument") + (format "Expected a natural number as second argument, but found ~v" h))) + (check-procedure-arity rfunc 2 'build3-image "Expected a function with contract num(x) num(y) -> color as third argument") + (check-procedure-arity gfunc 2 'build3-image "Expected a function with contract num(x) num(y) -> color as fourth argument") + (check-procedure-arity bfunc 2 'build3-image "Expected a function with contract num(x) num(y) -> color as fifth argument") (build-image-internal w h (lambda (x y) (make-color (rfunc x y) (gfunc x y) (bfunc x y))))) @@ -256,14 +256,14 @@ (define (build4-image w h rfunc gfunc bfunc afunc) (unless (natural? w) (error 'build-image - (format "Expected natural number as first argument, but found ~v" w))) + (format "Expected a natural number as first argument, but found ~v" w))) (unless (natural? h) (error 'build-image - (format "Expected natural number as second argument, but found ~v" h))) - (check-procedure-arity rfunc 2 'build-image "Expected function with contract num(x) num(y) -> color as third argument") - (check-procedure-arity gfunc 2 'build-image "Expected function with contract num(x) num(y) -> color as fourth argument") - (check-procedure-arity bfunc 2 'build-image "Expected function with contract num(x) num(y) -> color as fifth argument") - (check-procedure-arity afunc 2 'build-image "Expected function with contract num(x) num(y) -> color as sixth argument") + (format "Expected a natural number as second argument, but found ~v" h))) + (check-procedure-arity rfunc 2 'build-image "Expected a function with contract num(x) num(y) -> color as third argument") + (check-procedure-arity gfunc 2 'build-image "Expected a function with contract num(x) num(y) -> color as fourth argument") + (check-procedure-arity bfunc 2 'build-image "Expected a function with contract num(x) num(y) -> color as fifth argument") + (check-procedure-arity afunc 2 'build-image "Expected a function with contract num(x) num(y) -> color as sixth argument") (build-image-internal w h (lambda (x y) (make-color (rfunc x y) (gfunc x y) (bfunc x y) (afunc x y))))) @@ -288,20 +288,20 @@ ; map-image : (int int color -> broad-color) image -> image (define (map-image f img) - (check-procedure-arity f 3 'map-image "Expected function with contract num(x) num(y) color -> color as first argument") + (check-procedure-arity f 3 'map-image "Expected a function with contract num(x) num(y) color -> color as first argument") (unless (image? img) (error 'map-image - (format "Expected image as second argument, but found ~v" img))) + (format "Expected an image as second argument, but found ~v" img))) (map-image-internal (colorize-func f) img)) ; map-image/extra : (nat nat color X -> broad-color) image X -> image ; Like map-image, but passes a fixed extra argument to every call of the function. ; For students who don't yet know function closures. (define (map-image/extra f img extra) - (check-procedure-arity f 4 'map-image/extra "Expected function with contract num(x) num(y) color other -> color as first argument") + (check-procedure-arity f 4 'map-image/extra "Expected a function with contract num(x) num(y) color other -> color as first argument") (unless (image? img) (error 'map-image/extra - (format "Expected image as second argument, but found ~v" img))) + (format "Expected an image as second argument, but found ~v" img))) (map-image-internal (colorize-func (lambda (x y c) (f x y c extra))) img)) @@ -315,12 +315,12 @@ ; image -> image ; Note: by default, preserves alpha values from old image. (define (map3-image rfunc gfunc bfunc pic) - (check-procedure-arity rfunc 5 'map3-image "Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(r) as first argument") - (check-procedure-arity gfunc 5 'map3-image "Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(g) as second argument") - (check-procedure-arity bfunc 5 'map3-image "Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(b) as third argument") + (check-procedure-arity rfunc 5 'map3-image "Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(r) as first argument") + (check-procedure-arity gfunc 5 'map3-image "Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(g) as second argument") + (check-procedure-arity bfunc 5 'map3-image "Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(b) as third argument") (unless (image? pic) (error 'map3-image - (format "Expected image as fourth argument, but found ~v" pic))) + (format "Expected an image as fourth argument, but found ~v" pic))) (map-image-internal (lambda (x y c) (make-color (rfunc x y (color-red c) (color-green c) (color-blue c)) @@ -336,13 +336,13 @@ ; (int(x) int(y) int(r) int(g) int(b) int(a) -> int(a)) ; image -> image (define (map4-image rfunc gfunc bfunc afunc pic) - (check-procedure-arity rfunc 6 'map4-image "Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(r) as first argument") - (check-procedure-arity gfunc 6 'map4-image "Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(g) as second argument") - (check-procedure-arity bfunc 6 'map4-image "Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(b) as third argument") - (check-procedure-arity afunc 6 'map4-image "Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(alpha) as fourth argument") + (check-procedure-arity rfunc 6 'map4-image "Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(r) as first argument") + (check-procedure-arity gfunc 6 'map4-image "Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(g) as second argument") + (check-procedure-arity bfunc 6 'map4-image "Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(b) as third argument") + (check-procedure-arity afunc 6 'map4-image "Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(alpha) as fourth argument") (unless (image? pic) (error 'map4-image - "Expected image as fifth argument, but found ~v" pic)) + "Expected an image as fifth argument, but found ~v" pic)) (map-image-internal (lambda (x y c) (make-color (rfunc x y (color-red c) (color-green c) (color-blue c) (color-alpha c)) diff --git a/collects/picturing-programs/tests/map-image-bsl-tests.rkt b/collects/picturing-programs/tests/map-image-bsl-tests.rkt index 07d3721c8c..ec270cf90c 100644 --- a/collects/picturing-programs/tests/map-image-bsl-tests.rkt +++ b/collects/picturing-programs/tests/map-image-bsl-tests.rkt @@ -24,7 +24,7 @@ (check-expect (name->color "black") (make-color 0 0 0)) (check-expect (name->color "blue") (make-color 0 0 255)) (check-expect (name->color "plaid") false) -(check-error (name->color 7) "name->color: expected a string or symbol, but found 7") +(check-error (name->color 7) "name->color: Expected a string or symbol, but found 7") (check-expect (color=? (make-color 5 10 15) (make-color 5 10 15)) true) (check-expect (color=? (make-color 5 10 15) (make-color 5 15 10)) false) @@ -36,26 +36,26 @@ (check-expect (color=? (make-color 5 10 15 255) (make-color 5 10 15)) true) (check-expect (color=? (make-color 5 10 15 0) false) true) (check-expect (color=? (make-color 5 10 15 20) false) false) -(check-error (color=? "white" 3) "colorize: expected a color, but found 3") +(check-error (color=? "white" 3) "colorize: Expected a color, but found 3") (check-error (color=? "plaid" "white") "color=?: Expected a color or color name as first argument, but found \"plaid\"") (check-error (color=? "white" "plaid") "color=?: Expected a color or color name as second argument, but found \"plaid\"") ; Test cases for map3-image: ;(check-error (map3-image 5 + + pic:bloch) -; "map3-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(r) as first argument") +; "map3-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(r) as first argument") ; Actually, the above is caught by Check Syntax, before map3-image has a chance to check anything. (check-error (map3-image sqrt + + pic:bloch) - "map3-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(r) as first argument") + "map3-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(r) as first argument") ;(check-error (map3-image + 5 + pic:bloch) -; "map3-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(g) as second argument") +; "map3-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(g) as second argument") (check-error (map3-image + sqrt + pic:bloch) - "map3-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(g) as second argument") + "map3-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(g) as second argument") ;(check-error (map3-image + + 5 pic:bloch) -; "map3-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(b) as third argument") +; "map3-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(b) as third argument") (check-error (map3-image + + sqrt pic:bloch) - "map3-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(b) as third argument") + "map3-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(b) as third argument") (check-error (map3-image + + + 5) - "map3-image: Expected image as fourth argument, but found 5") + "map3-image: Expected an image as fourth argument, but found 5") ; red-id : x y r g b -> num (define (red-id x y r g b) r) @@ -98,23 +98,23 @@ "Test cases for map4-image:" ;(check-error (map4-image 5 + + + pic:bloch) -; "map4-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) -> num(r) as first argument") +; "map4-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) -> num(r) as first argument") (check-error (map4-image sqrt + + + pic:bloch) - "map4-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(r) as first argument") + "map4-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(r) as first argument") ;(check-error (map4-image + 5 + + pic:bloch) -; "map4-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(g) as second argument") +; "map4-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(g) as second argument") (check-error (map4-image + sqrt + + pic:bloch) - "map4-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(g) as second argument") + "map4-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(g) as second argument") ;(check-error (map4-image + + 5 + pic:bloch) -; "map4-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(b) as third argument") +; "map4-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(b) as third argument") (check-error (map4-image + + sqrt + pic:bloch) - "map4-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(b) as third argument") + "map4-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(b) as third argument") ;(check-error (map4-image + + + 5 pic:bloch) -; "map4-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(a) as fourth argument") +; "map4-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(a) as fourth argument") (check-error (map4-image + + + sqrt pic:bloch) - "map4-image: Expected function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(alpha) as fourth argument") + "map4-image: Expected a function with contract num(x) num(y) num(r) num(g) num(b) num(alpha) -> num(alpha) as fourth argument") (check-error (map4-image + + + + 5) - "map4-image: Expected image as fifth argument, but found 5") + "map4-image: Expected an image as fifth argument, but found 5") ; red-id6 : x y r g b a -> num (define (red-id6 x y r g b a) r) ; green-id6 : x y r g b a -> num @@ -150,11 +150,11 @@ ; Test cases for map-image: ;(check-error (map-image 5 pic:bloch) -; "map-image: Expected function with contract num(x) num(y) color -> color as first argument") +; "map-image: Expected a function with contract num(x) num(y) color -> color as first argument") (check-error (map-image sqrt pic:bloch) - "map-image: Expected function with contract num(x) num(y) color -> color as first argument") + "map-image: Expected a function with contract num(x) num(y) color -> color as first argument") (check-error (map-image + 5) - "map-image: Expected image as second argument, but found 5") + "map-image: Expected an image as second argument, but found 5") ; color-id : x y color -> color (define (color-id x y c) @@ -187,7 +187,7 @@ (define ex6 (map-image kill-red bloch)) ex6 (define (return-5 x y c) 5) -(check-error (map-image return-5 bloch) "colorize: expected a color, but found 5") +(check-error (map-image return-5 bloch) "colorize: Expected a color, but found 5") "Test cases for build3-image:" (define (x-gradient-2 x y) (min 255 (* 4 x))) @@ -196,19 +196,19 @@ "(build3-image 60 40 zero-2-args x-gradient-2 y-gradient-2) should be a 60x40 rectangle with no red, green increasing from left to right, and blue increasing from top to bottom:" (build3-image 60 40 zero-2-args x-gradient-2 y-gradient-2) (check-error (build3-image "hello" true sqrt sqrt sqrt) - "build3-image: Expected natural number as first argument, but found \"hello\"") + "build3-image: Expected a natural number as first argument, but found \"hello\"") (check-error (build3-image 17 true sqrt sqrt sqrt) - "build3-image: Expected natural number as second argument, but found true") + "build3-image: Expected a natural number as second argument, but found true") (check-error (build3-image 17 24 sqrt sqrt sqrt) - "build3-image: Expected function with contract num(x) num(y) -> color as third argument") + "build3-image: Expected a function with contract num(x) num(y) -> color as third argument") (check-error (build3-image 17 24 x-gradient-2 sqrt sqrt) - "build3-image: Expected function with contract num(x) num(y) -> color as fourth argument") + "build3-image: Expected a function with contract num(x) num(y) -> color as fourth argument") (check-error (build3-image 17 24 x-gradient-2 y-gradient-2 sqrt) - "build3-image: Expected function with contract num(x) num(y) -> color as fifth argument") + "build3-image: Expected a function with contract num(x) num(y) -> color as fifth argument") (define (return-minus-5 x y) -5) (check-error (build3-image 17 24 x-gradient-2 y-gradient-2 return-minus-5) - "make-color: expected an integer between 0 and 255 as third argument, given: -5") + "make-color: Expected an integer between 0 and 255 as third argument, given: -5") "Test cases for build4-image:" "(build4-image 50 50 x-gradient-2 x-gradient-2 zero-2-args y-gradient-2) should be a square, increasingly yellow from left to right and increasingly alpha from top to bottom. On a blue background." @@ -225,9 +225,9 @@ "(build-image 100 100 (lambda (x y) (make-color (* x 2.5) (* y 2.5) 0))):" (build-image 100 100 a-gradient) "should be a 100x100 square with a color gradient increasing in red from left to right, and in green from top to bottom" -(check-error (build-image 3.2 100 a-gradient) "build-image: Expected natural number as first argument, but found 3.2") -(check-error (build-image 100 -2 a-gradient) "build-image: Expected natural number as second argument, but found -2") -(check-error (build-image 100 100 sqrt) "build-image: Expected function with contract num(x) num(y) -> color as third argument") +(check-error (build-image 3.2 100 a-gradient) "build-image: Expected a natural number as first argument, but found 3.2") +(check-error (build-image 100 -2 a-gradient) "build-image: Expected a natural number as second argument, but found -2") +(check-error (build-image 100 100 sqrt) "build-image: Expected a function with contract num(x) num(y) -> color as third argument")