Functional Problem Solving (CSC 151 2016S) : EBoards

CSC151.02 2016S, Class 17: Boolean Values and Predicate Procedures


Overview

Preliminaries

Admin

Reminders

Upcoming Work:

Extra Credit

Academic

Peer

Regular Peer

No Extra Credit, But Still Good

Questions

Numbers vs. Images

Testing

We'll work on some simple tests for smaller-neighbor.

As a procedure.

(define check-right-neighbor
  (lambda (drawing neighbor)
    (check-= (drawing-right drawing)
             (drawing-left neighbor)
             .00001
             "next to each other")
    (check-= (drawing-top drawing)
             (drawing-top neighbor)
             .00001
             "tops aligned")
    (check-equal? (drawing-color drawing)
                  (drawing-color neighbor)
                  "same colors")
    (check-equal? (drawing-type drawing)
                  (drawing-type neighbor)
                  "same shape")
    (check-= (* 3/4 (drawing-width drawing))
             (drawing-width neighbor)
             .00001
             "proportional width")
    (check-= (* 3/4 (drawing-height drawing))
             (drawing-height neighbor)
             .00001
             "proportional height")))

Here's what we saw (more or less).

Welcome to DrRacket, version 6.1 [3m].
Language: racket [custom]; memory limit: 128 MB.
; Manually build a rectangle and its neighbor
> (define rect1 (rectangle "red" 50 30 20 20))
> (define rect2 (rectangle "red" 65 30 15 15))
> (check-right-neighbor rect1 rect2)
--------------------
FAILURE
name:       check-=
location:   (#<path:/home/rebelsky/Desktop/class17.rkt> 109 4 3110 124)
expression: (check-= (drawing-right drawing) (drawing-left neighbor) 1e-05)
params:     (70 65 1e-05)
message:    "next to each other"

. . Check failure
--------------------
; Okay, the left edge of rect2 was in the wrong place.  Fix it.
> (define rect2 (rectangle "red" 70 30 15 15))
> (check-right-neighbor rect1 rect2)
; Now we get no errors.  What happens if we recolor?
> (define rect2 (rectangle "grey" 70 30 15 15))
> (check-right-neighbor rect1 rect2)
--------------------
FAILURE
actual:     16711680
expected:   8421504
name:       check-equal?
location:   (#<path:/home/rebelsky/Desktop/class17.rkt> 117 4 3359 113)
expression: (check-equal? (drawing-color drawing) (drawing-color neighbor))
message:    "same colors"

. . Check failure
--------------------
; As expected, it tells us that the colors are not the same.
; Let's check the wrong shape.
> (define rect2 (ellipse "red" 70 30 15 15))
> (check-right-neighbor rect1 rect2)
--------------------
FAILURE
actual:     rectangle
expected:   ellipse
name:       check-equal?
location:   (#<path:/home/rebelsky/Desktop/class17.rkt> 120 4 3477 110)
expression: (check-equal? (drawing-type drawing) (drawing-type neighbor))
message:    "same shape"

. . Check failure
--------------------
; Now, let's see whether our smaller-neighbor procedure works.
> (check-right-neighbor rect1 (smaller-neighbor rect1))
--------------------
FAILURE
name:       check-=
location:   (#<path:/home/rebelsky/Desktop/class17.rkt> 109 4 3110 124)
expression: (check-= (drawing-right drawing) (drawing-left neighbor) 1e-05)
params:     (70 115/2 1e-05)
message:    "next to each other"

. . Check failure
--------------------
--------------------
FAILURE
name:       check-=
location:   (#<path:/home/rebelsky/Desktop/class17.rkt> 113 4 3239 115)
expression: (check-= (drawing-top drawing) (drawing-top neighbor) 1e-05)
params:     (30 45/2 1e-05)
message:    "tops aligned"

. . Check failure
--------------------
; Two failures!  The right and left edges don't match (way off) and
; the tops don't match (also off).

Lab

Writeup: 1c.