Fixed some more error messages.
This commit is contained in:
parent
5a10ef7550
commit
52527d8a95
|
@ -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 received ~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 received ~v" thing))]))
|
||||
|
||||
; colorize-func : (... -> broad-color) -> (... -> color)
|
||||
(define (colorize-func f)
|
||||
|
@ -119,10 +119,10 @@
|
|||
[rc2 (colorize c2)]]
|
||||
(unless (color? rc1)
|
||||
(error 'color=?
|
||||
(format "Expected a color or color name as first argument, but found ~v" c1)))
|
||||
(format "Expected a color or color name as first argument, but received ~v" c1)))
|
||||
(unless (color? rc2)
|
||||
(error 'color=?
|
||||
(format "Expected a color or color name as second argument, but found ~v" c2)))
|
||||
(format "Expected a color or color name as second argument, but received ~v" c2)))
|
||||
(and (= (color-alpha rc1) (color-alpha rc2)) ; Both alphas MUST be equal.
|
||||
(or (= (color-alpha rc1) 0) ; If both are transparent, ignore rgb.
|
||||
(and (= (color-red rc1) (color-red rc2))
|
||||
|
@ -214,10 +214,10 @@
|
|||
(define (build-image w h f)
|
||||
(unless (natural? w)
|
||||
(error 'build-image
|
||||
(format "Expected a natural number as first argument, but found ~v" w)))
|
||||
(format "Expected a natural number as first argument, but received ~v" w)))
|
||||
(unless (natural? h)
|
||||
(error 'build-image
|
||||
(format "Expected a natural number as second argument, but found ~v" h)))
|
||||
(format "Expected a natural number as second argument, but received ~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)))
|
||||
|
||||
|
@ -227,10 +227,10 @@
|
|||
(define (build-image/extra w h f extra)
|
||||
(unless (natural? w)
|
||||
(error 'build-image/extra
|
||||
(format "Expected a natural number as first argument, but found ~v" w)))
|
||||
(format "Expected a natural number as first argument, but received ~v" w)))
|
||||
(unless (natural? h)
|
||||
(error 'build-image/extra
|
||||
(format "Expected a natural number as second argument, but found ~v" h)))
|
||||
(format "Expected a natural number as second argument, but received ~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,10 +240,10 @@
|
|||
(define (build3-image w h rfunc gfunc bfunc)
|
||||
(unless (natural? w)
|
||||
(error 'build3-image
|
||||
(format "Expected a natural number as first argument, but found ~v" w)))
|
||||
(format "Expected a natural number as first argument, but received ~v" w)))
|
||||
(unless (natural? h)
|
||||
(error 'build3-image
|
||||
(format "Expected a natural number as second argument, but found ~v" h)))
|
||||
(format "Expected a natural number as second argument, but received ~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")
|
||||
|
@ -256,10 +256,10 @@
|
|||
(define (build4-image w h rfunc gfunc bfunc afunc)
|
||||
(unless (natural? w)
|
||||
(error 'build-image
|
||||
(format "Expected a natural number as first argument, but found ~v" w)))
|
||||
(format "Expected a natural number as first argument, but received ~v" w)))
|
||||
(unless (natural? h)
|
||||
(error 'build-image
|
||||
(format "Expected a natural number as second argument, but found ~v" h)))
|
||||
(format "Expected a natural number as second argument, but received ~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")
|
||||
|
@ -291,7 +291,7 @@
|
|||
(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 an image as second argument, but found ~v" img)))
|
||||
(format "Expected an image as second argument, but received ~v" img)))
|
||||
(map-image-internal (colorize-func f) img))
|
||||
|
||||
; map-image/extra : (nat nat color X -> broad-color) image X -> image
|
||||
|
@ -301,7 +301,7 @@
|
|||
(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 an image as second argument, but found ~v" img)))
|
||||
(format "Expected an image as second argument, but received ~v" img)))
|
||||
(map-image-internal (colorize-func (lambda (x y c) (f x y c extra))) img))
|
||||
|
||||
|
||||
|
@ -320,7 +320,7 @@
|
|||
(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 an image as fourth argument, but found ~v" pic)))
|
||||
(format "Expected an image as fourth argument, but received ~v" pic)))
|
||||
(map-image-internal
|
||||
(lambda (x y c)
|
||||
(make-color (rfunc x y (color-red c) (color-green c) (color-blue c))
|
||||
|
@ -342,7 +342,7 @@
|
|||
(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 an image as fifth argument, but found ~v" pic))
|
||||
"Expected an image as fifth argument, but received ~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))
|
||||
|
|
|
@ -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 received 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,9 +36,9 @@
|
|||
(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=? "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\"")
|
||||
(check-error (color=? "white" 3) "colorize: Expected a color, but received 3")
|
||||
(check-error (color=? "plaid" "white") "color=?: Expected a color or color name as first argument, but received \"plaid\"")
|
||||
(check-error (color=? "white" "plaid") "color=?: Expected a color or color name as second argument, but received \"plaid\"")
|
||||
|
||||
; Test cases for map3-image:
|
||||
;(check-error (map3-image 5 + + pic:bloch)
|
||||
|
@ -55,7 +55,7 @@
|
|||
(check-error (map3-image + + sqrt pic:bloch)
|
||||
"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 an image as fourth argument, but found 5")
|
||||
"map3-image: Expected an image as fourth argument, but received 5")
|
||||
|
||||
; red-id : x y r g b -> num
|
||||
(define (red-id x y r g b) r)
|
||||
|
@ -114,7 +114,7 @@
|
|||
(check-error (map4-image + + + sqrt pic:bloch)
|
||||
"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 an image as fifth argument, but found 5")
|
||||
"map4-image: Expected an image as fifth argument, but received 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
|
||||
|
@ -154,7 +154,7 @@
|
|||
(check-error (map-image sqrt pic:bloch)
|
||||
"map-image: Expected a function with contract num(x) num(y) color -> color as first argument")
|
||||
(check-error (map-image + 5)
|
||||
"map-image: Expected an image as second argument, but found 5")
|
||||
"map-image: Expected an image as second argument, but received 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 received 5")
|
||||
|
||||
"Test cases for build3-image:"
|
||||
(define (x-gradient-2 x y) (min 255 (* 4 x)))
|
||||
|
@ -196,9 +196,9 @@
|
|||
"(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 a natural number as first argument, but found \"hello\"")
|
||||
"build3-image: Expected a natural number as first argument, but received \"hello\"")
|
||||
(check-error (build3-image 17 true sqrt sqrt sqrt)
|
||||
"build3-image: Expected a natural number as second argument, but found true")
|
||||
"build3-image: Expected a natural number as second argument, but received true")
|
||||
(check-error (build3-image 17 24 sqrt sqrt sqrt)
|
||||
"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)
|
||||
|
@ -225,8 +225,8 @@
|
|||
"(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 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 3.2 100 a-gradient) "build-image: Expected a natural number as first argument, but received 3.2")
|
||||
(check-error (build-image 100 -2 a-gradient) "build-image: Expected a natural number as second argument, but received -2")
|
||||
(check-error (build-image 100 100 sqrt) "build-image: Expected a function with contract num(x) num(y) -> color as third argument")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user