Project 1:
Using Polya’s approach:
Here is the problem that I am trying to solve.
; clarify-color : color -> color
; Make alpha 0 for colors with r+g+b > 650, leave other colors as-is
;
; !!! create two (check-expect ...) expressions for clarify-color
; insert them before the definition
(define (clarify-color c)
(make-color
(color-red c)
(color-green c)
(color-blue c)
(cond
[(> (+ (color-red c) (color-green c) (color-blue c)) 650) 0]
[else (color-alpha c)])))
Understanding the problem:
I have to create two check-expects for this expression of clarify-color. I understand that if the values for r g and b add up to more than 650, alpha should be changed to 0. If they are less than 650 than alpha can stay as is.
Devising a plan:
I need to create 2 check expects. The goal of my check expects is to give a couple of examples of how this function is supposed to work. I know that I am trying to input colours instead of retrieve them.
Carrying out the plan:
(check-expect (clarify-color (make-color 220 220 220 220))
(make-color 220 220 220 0))
(check-expect (clarify-color (make-color 20 15 25 10))
(make-color 20 15 25 10))
Looking back:
I can prove that it is correct. Example 1 is saying that we want to produce a color that is made of up 4 numbers (r g b a). On the next line, it is making a color of r g b a, but first it is checking to see if the 1st make-color of r g b is greater than 650. If it is, than alpha is changed to 0, if it is not greater, than alpha is kept the same. So in example #1 r g and b add up to greater than 650 therefore alpha is 0, but in example 2, r g and b do not add up to 650 which is why alpha stays the same.
I originally made a mistake...
(check-expect (clarify-color c)
(make-color
(color-red c)
(color-green c)
(color-blue c)
I found out that what I had done retrieves the colours instead of inputting them. (make-color 220 200 200 200) takes a colour and makes a colour with the given values (r g b a).
No comments:
Post a Comment