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 28, 2016 @ 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 5th, 2016 @ 11:59pm

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 deconstructor template

;; A Grade is a NonNegReal within the range [0,100]

(define-struct student (name id grade))
;; Constructor Template:
;; A Student is (make-student String PosInt Grade)
;; 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))
;; Constructor Template:
;; 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))
;; Constructor Template:
;; 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?))
;; Constructor Template:
;; 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

One of our pre-defined data definitions is Posn. Here is its data definition

 
(define-struct posn (x y))
;; Constructor Template:
;; A Posn is (make-posn Real Real)
;; INTERP: represents a Cartesian Coordinate (x,y)

;; Deconstructor Template: 
#; (define (posn-fn point)
     ... (posn-x point) ...
     ... (posn-y point) ...)

                
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 NonNegInteger

;; Cents is a NonNegInteger in the range [0,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

A Professor from another department asked for your help in order to write a program that will manipulate techincal publications.

A publication can be one of

  • Conference. These are paper that have been published at a conference. We would like to capture the following information for conference publications.
    • Title: this is the paper's title.
    • Author: the author's name. There can only be one author.
    • Conference Name: the name of the conference.
    • Location: the location of the conference, typically a city and country, e.g. "Seattle, USA"
    • Month: the first three letters of the month, e.g., Oct
    • Year: the 4-digit calendar year.
  • Journal. These are papers that have been published to a Journal. We would like to capture the following information for journal publications.
    • Title: this is the paper's title.
    • Author: the author's name. There can only be one author.
    • Journal Name: the name of the Journal.
    • Issue: the issue number of the Journal, typically a number, e.g., 26
    • Month: the first three letters of the month, e.g., Oct
    • Year: the 4-digit calendar year.
  • Technical Report. These are papers that have been published as technical reports. We would like to capture the following information for technical report publications.
    • Title: this is the paper's title.
    • Author: the author's name. There can only be one author.
    • TR-ID: an identifier for this technical report, typically a number, e.g., 3425
    • Institution: the name of the institution publishing the technical report.
    • Year: the 4-digit calendar year.

Author names come in two flavours. An author's name is one of

  • Full Name: consists of the author's first and last name.
  • Official Name: consists of the author's first, middle, last names and title.

Another student has started working on a program but they had to abandon the project. You are asked to pick up from where they left off. Here is the incomplete code

 

;;; Data Definitions 
(define-struct official (first middle last title))
;; Constructor Template:
;; An OfficialName is (make-official String String String String)
;; INTERP: represents a person's official name with first, middle, last name
;;         and title.

;; Deconstructor Template: 

;;; Data Examples
(define JOHN-OFFICIAL (make-official "John" "D." "Doe" "PhD"))



(define-struct full (first last))
;; A FullName is a (make-full String String)
;; INTERP: represents a person's name with first and last name. 

;; Deconstructor Template: 

;;; Data Examples
(define JOHN-FULL (make-full "John" "Doe"))

;; An Author is one of
;; - OfficialName
;; - FullName
;; INTERP: represents the name of an author for a publication as either
;;         a full name (first and last) or an offical name (first, middle, last
;;         and title)

;; Deconstructor Template:


;; A Year is a PosInt with 4 digits, e.g., 1999
;; INTERP: represents a calendar year. 

;; A Month is one of
;; - 'Jan
;; - 'Feb
;; - 'Mar
;; - 'Apr
;; - 'May
;; - 'Jun
;; - 'Jul
;; - 'Aug
;; - 'Sep
;; - 'Oct
;; - 'Nov
;; - 'Dec
;; INTERP: represents a month in a calendar year. 

;; Deconstructor Template:


(define-struct conference (title author cname location month year))
;; Constructor Template:
;; A Conference is (make-conference String Author String String Month Year)
;; INTERP: represents a conference paper with title, author, conference name,
;;         conference location, month and year

;;; Data Examples
(define JOHN-FULL-CONF (make-conference "Anatomy of a mouse"
                                        JOHN-FULL
                                        "Animal Anatomy"
                                        "London, UK"
                                        'Jul
                                        2003))
(define JOHN-OFFICIAL-CONF (make-conference "Anatomy of a mouse"
                                            JOHN-OFFICIAL
                                            "Animal Anatomy"
                                            "London, UK"
                                            'Jul
                                            2003))


;; Deconstructor Template:

;; An Issue is a PosInt
;; INTERP: represents a journal's issue number

(define-struct journal (title author jname issue month year))
;; Constructor Template:
;; A Journal is (make-journal String Author String Issue Month Year)
;; INTERP: represents a journal paper with title, author, journal name,
;;         month and year.

;;; Data Examples
(define JOHN-FULL-JOURNAL  (make-journal "Anatomy of a mouse"
                                         JOHN-FULL
                                         "Mouse Journal"
                                         23
                                         'Feb
                                         2002))

(define JOHN-OFFICIAL-JOURNAL  (make-journal "Anatomy of a mouse"
                                             JOHN-OFFICIAL
                                             "Mouse Journal"
                                             23
                                             'Feb
                                             2002))

;; Deconstructor Template:


(define-struct techreport (title author tr-id institution year))
;; Constructor Template:
;; A TechnicalReport is (make-techreport String Author PosInt String Year)
;; INTERP: represents a technical report with title, author,
;;         technical report id, institution name, month and year.


;;; Data Examples

(define JOHN-FULL-TR (make-techreport "Anatomy of a mouse"
                                      JOHN-FULL
                                      1234
                                      "Mouse University"
                                      2001))


(define JOHN-OFFICIAL-TR (make-techreport "Anatomy of a mouse"
                                          JOHN-OFFICIAL
                                          1234
                                          "Mouse University"
                                          2001))


;; Deconstructor Template

;; A Publication is one of
;; - Conference
;; - Journal
;; - TechnicalReport
;; INTERP: represents a publication as either a confrence, journal or
;;         technical report. 

;; Deconstructor Template:

You are asked to

  1. Fill in the missing parts of the Data Definitions
  2. Design a function called tr->journal that will consume
    1. a technical report
    2. a journal's name
    3. a journal's issue
    4. the month
    5. the year
    and should return a new journal publication that has the same title and author as the technical report and the same journal issue, month and year as the values passed as arguments.
  3. Design a function called publication->image that consumes a publication and returns a formatted text image (see text/font and beside). All text in the images must have
    • font size 20
    • color black
    • font face #false
    • font family modern
    • not underlined
    • there must be a space after each period or comma
    Here are the specific formatting rules for each publication. The list is in the order that the corresponding information is to be printed out. See the examples at the end of the problem statement.
    • Conference Paper
      • The title must be enclosed in double quotes and followed by a period.
      • The author's name followed by a period.
      • The conference name in italics followed by a comma.
      • The conference location in italics followed by a period.
      • The three character month in bold followed by a comma.
      • The 4-digit year in bold followed by a period.
    • Journal Paper
      • The title must be enclosed in double quotes and followed by a period.
      • The author's name followed by a period.
      • The journal's name in italics followed by a comma.
      • The journal's issue in italics followed by a period.
      • The three character month in bold followed by a comma.
      • The 4-digit year in bold followed by a period.
    • Technical Report
      • The title must be enclosed in double quotes and followed by a period.
      • The author's name followed by a period.
      • The institution's name in italics followed by a comma.
      • The technical reports id number in italics followed by a period.
      • The 4-digit year in bold followed by a period.
    For the author's name, here are the specific formatting rules.
    • Full Name first name followed by a space followed by the last name
    • Official Name title followed by a space, followed by the first name followed by a space followed by the middle name followed by a space followed by the last name
    Here are some formatted samples.
    > (publication->image JOHN-FULL-CONF)
    john-full-conf
    > (publication->image JOHN-OFFICIAL-CONF)
    john-official-conf
  4. > (publication->image JOHN-FULL-JOURNAL)
    john-full-journal
    > (publication->image JOHN-OFFICIAL-JOURNAL)
    john-official-journal
    > (publication->image JOHN-FULL-TR)
    john-full-TR
    > (publication->image JOHN-OFFICIAL-TR)
    john-official-tr