Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; =================
- ;; Data definitions:
- ;; Light is one of:
- ;; - "red"
- ;; - "yellow"
- ;; - "green"
- ;; interp. the current color of the light
- ;; <examples are redundant for enumerations>
- #;
- (define (fn-for-light l)
- (cond [(string=? l "red") (...)]
- [(string=? l "yellow") (...)]
- [(string=? l "green") (...)]))
- ;; Template rules used:
- ;; one of: 3 cases
- ;; atomic distinct: "red"
- ;; atomic distinct: "yellow"
- ;; atomic distinct: "green"
- ;; =================
- ;; Functions:
- ;; Light -> Light
- ;; called to run the animation; start with (main "red")
- ;; no tests for main function
- (define (main l)
- (big-bang l
- (on-tick next-color 1) ; Light -> Light
- (to-draw render-light))) ; Light -> Image
- ;; Light -> Light
- ;; produce next color of light
- (check-expect (next-color "red") "green")
- (check-expect (next-color "yellow") "red")
- (check-expect (next-color "green") "yellow")
- #;
- (define (next-color l) ; stub
- "red")
- ;<template from Light>
- (define (next-color l)
- (cond [(string=? l "red") "green"]
- [(string=? l "yellow") "red"]
- [(string=? l "green") "yellow"]))
- ;; Light -> Image
- ;; produce appropriate image for light color
- (check-expect (render-light "red") RON)
- (check-expect (render-light "yellow") YON)
- (check-expect (render-light "green") GON)
- #;
- (define (render-light l)
- BACKGROUND)
- ;<template from Light>
- (define (render-light l)
- (cond [(string=? l "red") RON]
- [(string=? l "yellow") YON]
- [(string=? l "green") GON]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement