In this module we introduce and apply the Design Recipe to a series of example problems. The examples introduce new kinds of data definitions, scalars and itemizations, and demonstrate how to use rackunit to develop tests for BSL functions.

  1. Use rackunit to write tests.
  2. Use rackunit to debug a function.
  3. List the four goals of testing.
  4. Explain the four goals of testing.
  5. Use the syntactical conventions for function definitions.
  6. Write a code example of scalar data.
  7. Define the term itemization.
  8. Use a bulleted list for an itemization data definition.
  9. Write the interpretation for simple data.
  10. List the six steps of the design recipe in order.
  11. Explain what each step of the Design Recipe does.
  12. Given a solution, label each step of the design recipe.
  13. Given a signature, write down its inputs.
  14. Given a signature, write down its outputs.
  15. Append predicate function names with the question mark character.
  16. Use the arrow to separate input and output in function signatures.

  • DUE DATE: September 25, 2017 @ 11:59pm

Instructions

All problems must be solved using the Design Recipe and you must show all your work for every step in the Design Recipe. You code must also follow the class' coding style.

Problem 1

Design a function called logical-xor that consumes two booleans and has the same behaviour as the logical exclusive or connective

Problem 2

A friend of yours came up with the following data definition


;; A MaybeNumber is one of 
;; - Number 
;; - 'undefined 
 
  1. The data definition is incomplete. Please complete it.
  2. Design a function that performs addition on MaybeNumbers. Your function should return a MaybeNumber. If the two inputs are not the symbol 'undefined the function should retrun the sum of the two numbers. Else the function should return 'undefined.

Problem 3

Design a function that consumes the current time as 2 numbers, the first number denotes hours and the second number denotes minutes. Your function should add 1 minute to the current time and return the update time as a string, e.g., "12:44". The value for hours should be between 0 to 23. The value for minutes should be between 0 and 59.

Problem 4

Design a function that given a letter grade returns your GPA. Use Northeastern's mapping from letter grade to GPA.

Problem 5

Design a function that consumes a file size and its units as a symbol and returns the total number of bytes. For example when the function is given 10 and 'MB returns 10485760 (1 MB = 1,048,576). You can use this table for your conversions. Use the Traditional Units table.

  • DUE DATE: October 2nd, 2017 @ 11:59pm

Instructions

  • All solutions must follow the Design Recipe
  • You are not allowed to use the built-in functions
    1. eq?
    2. equal?
    3. eqv?

Problem 1

For each of the following structure definitions provide

  1. Signatures for all selectors
  2. Signature for the constructor
  3. Signature for the predicate
  4. A template

(define-struct student [name id grade])
;; A Student is (make-student String PosInt NonNegInteger)
;; WHERE: 0 <= grade <= 100
;; INTER: represents a student with the student's name 
;;        the student's id and the student's grade. 

(define-struct container [width height depth capacity label])
;; A Container is (make-container PosInt PosInt PosInt PosInt Symbol)
;; WHERE: capacity = width * height * depth
;; INTERP: represents a container with its width, height, depth 
;;         in centimeters, it's capacity in cubic centimeters and 
;;         it's label


(define-struct sweater [material size producer])
;; A Sweater is (make-sweater Symbol PosInt String)
;; INTERP: represents a sweater with the sweater's material 
;;         it's size and the name of the manufacturer

(define-struct game [name min-ram min-graphics-ram online?])
;; A Game is (make-game String PosInt PosInt Boolean
;; INTERP: represents a game with it's name, the minimum ram 
;;         capacity needed , the minimum graphics 
;;         card memory needed and whether it is an online game or not

Problem 2

Design a program that consumes two Cartesian coordinates as Posn s and returns the distance between the two coordinates.

Distance between two points explains how to calculate the distance between two Cartesian coordinates.

Problem 3

You started working for a small company that produces cash registers. The company is currently designing their new model and one of your colleagues has provided you with the following data definitions



;; Dollars is a PosInt

;; Cents is a NonNegInteger 
;; WHERE: Cents is greater or equal to 0 
;;        and less or equal to 99

(define-struct amount [dollars cents])
;; An Amount is (make-amount Dollars Cents)
;; INTERP: represents total amount in dollars and cents. 

You have been tasked to design the add-to-amount function that will consume the current amount, amt, the number of dollars, dollars, to add and the number of cents, cents, to add. Your function should return the total amount after adding dollar and cents to amt.

Problem 4

You are given the following data definition


;; A Style is one of 
;; - 'outline
;; - 'solid

(define-struct disk [radius style location])
;; A Disk is (make-disk PosInt Style Posn)
;; WHERE (and (< (+ radius (posn-x location)) 500)
;;            (>= (- (posn-x location) radius) 0)
;;            (< (+ radius (posn-y location)) 500)
;;            (>= (- (posn-y location) radius) 0))
;; INTERP: represents a disk with its radius, its style 
;;         and its location as an (x,y) coordinate

Design the function connect-disks that consumes two disks and draws the two disks and a red line from starting at the center of one disk and ending at the center of the second disk on an empty 500x500 canvas.

For example, evaluating


(connect-disks (make-disk 50 'outline (make-posn 100 100))
               (make-disk 50 'outline (make-posn 300 400)))

produces,

Connected Disks

Note: for functions that return Images you are allowed to not have tests using check-expect. You should still test these functions manually using the interactions window.