#lang racket
(require gigls/unsafe)
(require rackunit)
(require rackunit/text-ui)

;;; File:
;;;   makeup1.rkt
;;; Authors:
;;;   The student currently referred to as 000000
;;;   Samuel A. Rebelsky
;;; Contents:
;;;   Code and solutions for Makeup exam 1 2015F.
;;; Citations:
;;;

; +---------+--------------------------------------------------------
; | Grading |
; +---------+

; This section is for the grader's use.

; Problem 1: 
; Problem 2:
; Problem 3:
; Problem 4:
; Problem 5:
; Problem 6:
; Problem 7:
;           ----
;     Total:

;    Scaled:
;    Errors:
;     Times:
;          :
;          :
;          :
;           ----
;     Total:


; +-----------+------------------------------------------------------
; | Problem 1 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   irgb-crrc
;;; Parameters:
;;;
;;; Purpose:
;;;
;;; Produces:
;;;
;;; Preconditions:
;;;
;;; Postconditions:
;;;

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 2 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

(define irgb-clear-dominated
  (lambda (color)
    color))

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 3 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Name:
;;;   irgb-add-tests
;;; Type:
;;;   test suite
;;; Contents:
;;;   Tests for the irgb-add procedure.
(define irgb-add-tests
  (test-suite
   "Test of irgb-add"
   (test-case "simple cases"
    (check-equal? (irgb-add (irgb 128 0 0) (irgb 0 0 128)) 
                  (irgb 128 0 128)
                  "medium red plus medium blue = medium purple"))))

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 4 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   component-add-wrap
;;; Parameters:
;;;   component1, an integer
;;;   component2, an integer
;;; Purpose:
;;;   Add component1 and component2, "wrapping around" when the
;;;   sum is greater than 255.
;;; Produces:
;;;   wsum, an integer
;;; Preconditions:
;;;   0 <= component1 <= 255
;;;   0 <= component2 <= 255
;;; Postconditions:
;;;   0 < wsum <= 255.
;;;   If component1 + component2 <= 255, 
;;;     wsum = component1 + component2
;;;   Otherwise, 
;;;     wsum = component1 + component2 - 256
(define component-add-wrap
  (lambda (component1 component2)
    0)) ; STUB

;;; Procedure:
;;;   component-sub-wrap
;;; Parameters:
;;;   component1, an integer
;;;   component2, an integer
;;; Purpose:
;;;   Subtract component2 and component1, "wrapping around" when the
;;;   difference is less than 0.
;;; Produces:
;;;   diff , an integer
;;; Preconditions:
;;;   0 <= component1 <= 255
;;;   0 <= component2 <= 255
;;; Postconditions:
;;;   If component1 - component2 >= 0,
;;;     diff = component1 - component2
;;;   Otherwise, 
;;;     diff = (component1 - component2) + 256
(define component-sub-wrap
  (lambda (component1 component2)
    0)) ; STUB

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 5 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 6 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   irgb-weighted-average
;;; Parameters:
;;;   color1, an integer-encoded RGB color
;;;   color2, an integer-encoded RGB color
;;;   weight, a real number
;;; Purpose:
;;;   Compute a weighted average of two colors.
;;; Produces:
;;;   new-color, an integer-encoded RGB color
;;; Preconditions:
;;;   0 *lt;= weight <= 1
;;; Postconditions:
;;;   Let r1, g1, and b1 be the components of color1.
;;;   Let r2, g2, and b2 be the components of color2.
;;;   Let r = weight*r1 + (1-weight)*r2
;;;   Let g = weight*g1 + (1-weight)*g2
;;;   Let b = weight*b1 + (1-weight)*b2
;;;     (floor r) <= (irgb-red new-color) <= (ceiling r)
;;;     (floor g) <= (irgb-green new-color) <= (ceiling g)
;;;     (floor b) <= (irgb-blue new-color) <= (ceiling b)
(define irgb-weighted-average
  (lambda (color1 color2 weight)
    color1))

(define image-tint
  (lambda (image)
    (image-variant image (lambda (x) x))))

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 7 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   
;;; Parameters:
;;;
;;; Purpose:
;;;
;;; Produces:
;;;
;;; Preconditions:
;;;
;;; Postconditions:
;;;
(define f (lambda (a b c) (min (max (min a b) c) (max (min b c) a))))

; Examples/Tests:


; ===================================================================

; BEFORE PRINTING, PLEASE MAKE A *SEPARATE* COPY OF YOUR CODE AND
; REMOVE EVERYTHING BELOW THIS LINE.

; PLEASE DO NOT ADD ANYTHING BELOW THIS POINT.

;;; Procedure:
;;;   irgb-add-wrap
;;; Parameters:
;;;   color1, an integer-encoded RGB color
;;;   color2, an integer-encoded RGB color
;;; Purpose:
;;;   Add color1 and color2 component-wise, wrapping around if any
;;;   sum gets too large.
;;; Produces:
;;;   color, an integer-encoded RGB color
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   If (irgb-red color1) + (irgb-red color2) <= 255, 
;;;     (irgb-red color) = (irgb-red color1) + (irgb-red color2)
;;;   Otherwise, 
;;;     (irgb-red color) = (irgb-red color1) + (irgb-red color2) - 256
(define irgb-add-wrap
  (lambda (color1 color2)
    (irgb (component-add-wrap (irgb-red color1) (irgb-red color2))
          (component-add-wrap (irgb-green color1) (irgb-green color2))
          (component-add-wrap (irgb-blue color1) (irgb-blue color2)))))

;;; Procedure:
;;;   irgb-sub-wrap
;;; Parameters:
;;;   color1, an integer-encoded RGB color
;;;   color2, an integer-encoded RGB color
;;; Purpose:
;;;   Subtract color2 from color1 component-wise, wrapping around if any
;;;   difference gets too large.
;;; Produces:
;;;   color, an integer-encoded RGB color
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   If (irgb-red color1) - (irgb-red color2) >= 0,
;;;     (irgb-red color) = (irgb-red color1) - (irgb-red color2)
;;;   Otherwise, 
;;;     (irgb-red color) = ((irgb-red color1) - (irgb-red color2)) + 256
(define irgb-sub-wrap
  (lambda (color1 color2)
    (irgb (component-sub-wrap (irgb-red color1) (irgb-red color2))
          (component-sub-wrap (irgb-green color1) (irgb-green color2))
          (component-sub-wrap (irgb-blue color1) (irgb-blue color2)))))
