Added more test cases; started updating documentation.

This commit is contained in:
Stephen Bloch 2010-12-28 23:59:03 -05:00
parent 437ea70080
commit 73ef1d6c14
5 changed files with 97 additions and 3172 deletions

View File

@ -37,29 +37,8 @@ It's intended to be used with the textbook
@hyperlink["http://www.picturingprograms.com" "Picturing Programs"]. @hyperlink["http://www.picturingprograms.com" "Picturing Programs"].
@section{Installation} @section{Installation}
If you're reading this, you've probably already installed the teachpack successfully, This package should be bundled with DrRacket version 5.1 and later, so there should be
but if you need to install it on a different machine, ... no installation procedure.
@itemize[#:style 'ordered
@item{start DrScheme}
@item{switch languages to ``Use the language declared in the
source'' and click ``Run''}
@item{in the Interactions pane, type
@racketblock[(require (planet sbloch/picturing-programs:2))]}
@item{after a few seconds, you should see the message
@racketoutput{Wrote file ``picturing-programs.rkt'' to installed-teachpacks directory.}}
@item{switch languages back to one of the HtDP languages, like Beginning Student}
@item{either
@itemize{
@item{in the Definitions pane, type
@racketblock[(require installed-teachpacks/picturing-programs)]
or}
@item{from the Language menu, choose "Add
Teachpack..." and select "picturing-programs.rkt"}
}
}
@item{click "Run"}
]
@section{Functions from image.rkt and universe.rkt} @section{Functions from image.rkt and universe.rkt}

View File

@ -1,4 +0,0 @@
;; 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 dummy) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(require "main.rkt")

View File

@ -26,6 +26,7 @@
(provide-primitives real->int (provide-primitives real->int
; maybe-color? ; maybe-color?
name->color name->color
colorize
get-pixel-color get-pixel-color
;pixel-visible? ;pixel-visible?
; change-to-color ; change-to-color
@ -80,13 +81,6 @@
(color%->color result) (color%->color result)
#f))) #f)))
;; lookup-if-nec : maybe-color -> maybe-color
;(define (lookup-if-nec c)
; (cond [(color? c)) c]
; [(or (string? c) (symbol? c)) (name->color c)]
; [(eqv? c #f) transparent]
; [else (error 'lookup-if-nec "Unrecognized type")]))
; colorize : broad-color -> color -- returns #f for unrecognized names ; colorize : broad-color -> color -- returns #f for unrecognized names
(define (colorize thing) (define (colorize thing)

View File

@ -1,9 +1,7 @@
;; The first three lines of this file were inserted by DrRacket. They record metadata ;; 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. ;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname map-image-bsl-tests) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) #reader(lib "htdp-beginner-reader.ss" "lang")((modname map-image-bsl-tests) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(require picturing-programs/book-pictures) (require picturing-programs)
(require picturing-programs/map-image)
(require 2htdp/image)
; Test cases for primitives: ; Test cases for primitives:
(check-expect (real->int 3.2) 3) (check-expect (real->int 3.2) 3)
@ -53,10 +51,11 @@
(define (zero-5-args x y r g b) 0) (define (zero-5-args x y r g b) 0)
(define tri (triangle 60 "solid" "orange")) (define tri (triangle 60 "solid" "orange"))
; (define hieroglyphics pic:hieroglyphics) (define hieroglyphics pic:hieroglyphics)
; (define scheme-logo pic:scheme-logo) (define scheme-logo pic:scheme-logo)
; (define bloch pic:bloch) (define bloch pic:bloch)
"Test cases for map3-image:"
"tri:" tri "tri:" tri
"(map3-image red-id green-id blue-id tri) should be tri:" "(map3-image red-id green-id blue-id tri) should be tri:"
(map3-image red-id green-id blue-id tri) (map3-image red-id green-id blue-id tri)
@ -74,14 +73,14 @@
(map3-image zero-5-args x-gradient-5 y-gradient-5 tri) (map3-image zero-5-args x-gradient-5 y-gradient-5 tri)
"The same thing with some red:" "The same thing with some red:"
(map3-image red-id x-gradient-5 y-gradient-5 tri) (map3-image red-id x-gradient-5 y-gradient-5 tri)
"And now let's try it on bloch. Should get a rectangular 2-dimensional color gradient:" "And now let's try it on bloch. Should get a rectangular 2-dimensional color gradient, no bloch:"
(map3-image zero-5-args x-gradient-5 y-gradient-5 bloch) (map3-image zero-5-args x-gradient-5 y-gradient-5 bloch)
"The same thing preserving the red:" "The same thing preserving the red:"
(map3-image red-id x-gradient-5 y-gradient-5 bloch) (map3-image red-id x-gradient-5 y-gradient-5 bloch)
"Rotating colors r->g->b->r:" "Rotating colors r->g->b->r:"
(map3-image blue-id red-id green-id bloch) (map3-image blue-id red-id green-id bloch)
; Test cases for map4-image: "Test cases for map4-image:"
; red-id6 : x y r g b a -> num ; red-id6 : x y r g b a -> num
(define (red-id6 x y r g b a) r) (define (red-id6 x y r g b a) r)
; green-id6 : x y r g b a -> num ; green-id6 : x y r g b a -> num
@ -94,7 +93,6 @@
(define (zero-6-args x y r g b a) 0) (define (zero-6-args x y r g b a) 0)
; ;
"tri:" tri
"(map4-image red-id6 green-id6 blue-id6 alpha-id6 tri) should be tri:" "(map4-image red-id6 green-id6 blue-id6 alpha-id6 tri) should be tri:"
(map4-image red-id6 green-id6 blue-id6 alpha-id6 tri) (map4-image red-id6 green-id6 blue-id6 alpha-id6 tri)
"(map4-image zero-6-args green-id6 blue-id6 alpha-id6 tri) should be a green triangle:" "(map4-image zero-6-args green-id6 blue-id6 alpha-id6 tri) should be a green triangle:"
@ -150,7 +148,7 @@
(check-error (map-image return-5 bloch) "colorize: Unrecognized type") (check-error (map-image return-5 bloch) "colorize: Unrecognized type")
; Test cases for build3-image: "Test cases for build3-image:"
(define (x-gradient-2 x y) (min 255 (* 4 x))) (define (x-gradient-2 x y) (min 255 (* 4 x)))
(define (y-gradient-2 x y) (min 255 (* 4 y))) (define (y-gradient-2 x y) (min 255 (* 4 y)))
(define (zero-2-args x y) 0) (define (zero-2-args x y) 0)
@ -171,9 +169,11 @@
(check-error (build3-image 17 24 x-gradient-2 y-gradient-2 return-minus-5) (check-error (build3-image 17 24 x-gradient-2 y-gradient-2 return-minus-5)
"make-color: expected <integer between 0 and 255> as third argument, given: -5") "make-color: expected <integer between 0 and 255> as third argument, given: -5")
; Test cases for build4-image: "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."
(overlay (build4-image 50 50 x-gradient-2 x-gradient-2 zero-2-args y-gradient-2) bluebox)
; Test cases for build-image: "Test cases for build-image:"
(define (always-red x y) (name->color "red")) (define (always-red x y) (name->color "red"))
"(build-image 50 35 (lambda (x y) red)):" "(build-image 50 35 (lambda (x y) red)):"
(build-image 50 35 always-red) (build-image 50 35 always-red)

File diff suppressed because it is too large Load Diff