Fixed error messages, added tests for type errors.
This commit is contained in:
parent
3bfce02bd6
commit
753dfa3cb2
|
@ -81,18 +81,28 @@
|
|||
(rotate 45 (flip-vertical (rotate -45 picture))))
|
||||
|
||||
; synonyms
|
||||
(define (flip-main picture) (reflect-main-diag picture))
|
||||
(define (flip-other picture) (reflect-other-diag picture))
|
||||
(define (flip-main picture)
|
||||
(check-image 'flip-main picture "first")
|
||||
(reflect-main-diag picture))
|
||||
(define (flip-other picture)
|
||||
(check-image 'flip-other picture "first")
|
||||
(reflect-other-diag picture))
|
||||
|
||||
; natural-number? anything -> boolean
|
||||
(define (natural-number? x)
|
||||
(and (integer? x) (>= x 0)))
|
||||
|
||||
; natural-bounded? natural anything -> boolean
|
||||
(define (natural-bounded? max x)
|
||||
(and (natural-number? x) (<= x max)))
|
||||
|
||||
; crop-left : image natural-number -> image
|
||||
; deletes that many pixels from left edge of image
|
||||
(define (crop-left picture pixels)
|
||||
(check-image 'crop-left picture "first")
|
||||
(check-arg 'crop-left (natural-number? pixels) "natural number" "second" pixels)
|
||||
(check-arg 'crop-left (natural-bounded? (image-width picture) pixels)
|
||||
(format "natural number <= ~a" (image-width picture))
|
||||
"second" pixels)
|
||||
(crop pixels 0
|
||||
(- (image-width picture) pixels) (image-height picture)
|
||||
picture))
|
||||
|
@ -101,7 +111,9 @@
|
|||
; deletes that many pixels from top edge of image
|
||||
(define (crop-top picture pixels)
|
||||
(check-image 'crop-top picture "first")
|
||||
(check-arg 'crop-top (natural-number? pixels) "natural number" "second" pixels)
|
||||
(check-arg 'crop-top (natural-bounded? (image-height picture) pixels)
|
||||
(format "natural number <= ~a" (image-height picture))
|
||||
"second" pixels)
|
||||
(crop 0 pixels
|
||||
(image-width picture) (- (image-height picture) pixels)
|
||||
picture))
|
||||
|
@ -110,7 +122,9 @@
|
|||
; deletes that many pixels from right edge of image
|
||||
(define (crop-right picture pixels)
|
||||
(check-image 'crop-right picture "first")
|
||||
(check-arg 'crop-right (natural-number? pixels) "natural number" "second" pixels)
|
||||
(check-arg 'crop-right (natural-bounded? (image-width picture) pixels)
|
||||
(format "natural number <= ~a" (image-width picture))
|
||||
"second" pixels)
|
||||
(crop 0 0
|
||||
(- (image-width picture) pixels)
|
||||
(image-height picture)
|
||||
|
@ -120,7 +134,9 @@
|
|||
; deletes that many pixels from bottom edge of image
|
||||
(define (crop-bottom picture pixels)
|
||||
(check-image 'crop-bottom picture "first")
|
||||
(check-arg 'crop-bottom (natural-number? pixels) "natural number" "second" pixels)
|
||||
(check-arg 'crop-bottom (natural-bounded? (image-height picture) pixels)
|
||||
(format "natural number <= ~a" (image-height picture))
|
||||
"second" pixels)
|
||||
(crop 0 0
|
||||
(image-width picture)
|
||||
(- (image-height picture) pixels)
|
||||
|
|
37
collects/picturing-programs/tests/tiles-error-tests.rkt
Normal file
37
collects/picturing-programs/tests/tiles-error-tests.rkt
Normal file
|
@ -0,0 +1,37 @@
|
|||
;; The first three lines of this file were inserted by DrRacket. They record metadata
|
||||
;; about the language level of this file in a form that our tools can easily process.
|
||||
#reader(lib "htdp-beginner-reader.ss" "lang")((modname tiles-error-tests) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
|
||||
(require picturing-programs)
|
||||
|
||||
(check-error (reflect-horiz 17)
|
||||
"reflect-horiz: expected <image> as first argument, given: 17")
|
||||
(check-error (reflect-vert "hello")
|
||||
"reflect-vert: expected <image> as first argument, given: \"hello\"")
|
||||
(check-error (reflect-main-diag true)
|
||||
"reflect-main-diag: expected <image> as first argument, given: true")
|
||||
(check-error (reflect-other-diag false)
|
||||
"reflect-other-diag: expected <image> as first argument, given: false")
|
||||
(check-error (flip-main 'blue)
|
||||
"flip-main: expected <image> as first argument, given: 'blue")
|
||||
(check-error (flip-other "snark")
|
||||
"flip-other: expected <image> as first argument, given: \"snark\"")
|
||||
(check-error (crop-left pic:hacker 50)
|
||||
"crop-left: expected <natural number <= 48> as second argument, given: 50")
|
||||
(check-error (crop-right pic:bloch 100)
|
||||
"crop-right: expected <natural number <= 93> as second argument, given: 100")
|
||||
(check-error (crop-top pic:book 56)
|
||||
"crop-top: expected <natural number <= 39> as second argument, given: 56")
|
||||
(check-error (crop-bottom pic:hacker 56)
|
||||
"crop-bottom: expected <natural number <= 48> as second argument, given: 56")
|
||||
(check-error (crop-left pic:hacker -3)
|
||||
"crop-left: expected <natural number <= 48> as second argument, given: -3")
|
||||
(check-error (crop-top pic:book 3.2)
|
||||
"crop-top: expected <natural number <= 39> as second argument, given: 3.2")
|
||||
(check-error (crop-bottom pic:book pic:book)
|
||||
"crop-bottom: expected <natural number <= 39> as second argument, given: #<image>")
|
||||
(check-error (rotate-cw 17)
|
||||
"rotate-cw: expected <image> as first argument, given: 17")
|
||||
(check-error (rotate-ccw true)
|
||||
"rotate-ccw: expected <image> as first argument, given: true")
|
||||
(check-error (rotate-180 "goodbye")
|
||||
"rotate-180: expected <image> as first argument, given: \"goodbye\"")
|
Loading…
Reference in New Issue
Block a user