Homework 2
Last updated: Fri, 20 Sep 2024 13:01:12 -0400
Out: Mon Sep 16, 2024, 12pm (noon) EST
Due: Mon Sep 23, 2024, 12pm (noon) EST
Overview
This assignment introduces The Design Recipe, a systematic way to write programs that are both correct and readable.
This hw will be graded accordingly:
correctness (9 pts)
design recipe (20 pts)
style (5 pts)
README (1 pt)
Setup
Create a new repository for this assignment by going to the CS450 Fall 2024 GitHub Organization and clicking "New".
Note: The CS450 Fall 2024 GitHub Organization must be the owner of the repository. Do not create the repository in your own account.
Name the repository hw<X>-<LASTNAME>-<FIRSTNAME> where <X> is the current homework number.
For example, I would name my hw2 repository hw2-Chang-Stephen.
Mark the repository as Private.
Check "Add a README file".
Select the Racket template for the .gitignore.
Choose whatever you wish for the license.
When done click "Create repository".
Tasks
Reading
Read Chapter 3 of the Textbook (where reading means working through the examples and exercises interactively).
Begin to read the The Design Recipe section of the course website (topics that will be covered in future lectures are marked as such).
NOTE: Starting with this assignment, language features may only be used in the correct scenarios, as called for by The Design Recipe. For example, set! and other "imperative" features are not allowed ever. In this assignment, conditionals such as if and cond are not allowed either, since they are only to be used with Data Definitions that we have not covered yet.
All code you write must now follow the The Design Recipe. (Just submitting code is no longer sufficient.) Signatures should use define/contract and the predicates defined in the Data Design Recipe step.
For Examples and Tests, do not use check-expect from the Beginning Student Language (even though the textbook says to). Instead, use check-equal? or other testing forms from rackunit.
Examples for a function definition should be right after the define. But Tests should be put into the test-suite in tests.rkt. Try to think about corner cases and code coverage. (I may run your test suite against the code of other students and award bonus points for bugs found.)
In this assignment, each function should have at minimum one Example, and one more Test than Examples (so two minimum tests).
Programming
In this assignment we’ll create a big-bang interactive program that could maybe eventually resemble a "Guitar Hero"-like game.
Here is an online demo that approximates the behavior of the program.
Tests should go in a tests.rkt file, as described in lecture and the hw2 starter code, and the rest of the code should go in a file named hw2.rkt.
NOTE: The submitted program must be only a series of defines (both constants and function definitions are allowed). It should not run any code. Not following this this will result in GradeScope errors.
NOTE: You may look at the code from lecture03 to help you but BE CAREFUL. DO NOT JUST COPY THE CODE AND TRY TO MODIFY IT. Your program will be wrong (because most of the design recipe steps will be wrong) and will receive a low score. Instead, you should write the code for this homework from scratch using The Design Recipe.
Create a big-bang program that is a 200\times 200 pixel scene where a 40\times 80 (width \times height) green outline solid rectangle moves across the screen from left to right at a rate of 2 pixels per tick. The "y" coordinate of the rectangle should be centered in the scene.
When a part of the rectangle goes out of the scene on the right, that part should appear to wrap around and re-appear on the screen on the left.
The scene should also have a gray vertical line in the middle that does not move. When the rectangle and line intersect, the rectangle should appear to be on top.
NOTE (2024-09-17): added additional provide requirements
A Data Definition named WorldState that represents the world state values of your big-bang program
A WorldState? predicate that returns true when given a value that is a valid WorldState
a function next-worldstate with signature WorldState -> WorldState
a function render with signature WorldState -> Image, where Image is a built-in basic data definition from 2htdp/image. (image? i) evaluates to true for i that are valid instances of Image.
a constant INIT-WORLDSTATE where (WorldState? INIT-WORLDSTATE) evaluates to true.
a function main that takes no arguments and starts the big-bang interactive loop
Before Submitting
Testing
Do not submit until all code has been thoroughly tested (by you).
Assignments may or may not use a GradeScope Autograder, but either way, an Autograder is not a software development tool so do not use it as one. Code must be tested independent of any Autograder.
If you submit and get an Autograder error, this means the code you wrote is not complete and/or not correct and it’s up to you to figure out why.
Of course, the course staff is here and eager to help, but cannot do so if a student does not explain what they’ve tried first (e.g., "why is the Autograder giving an error?" is not something we can help with). At the very least you should report what error you are seeing and which part of the error message you do not understand.
The Autograder test suite is subject to change. This means that the visible grade seen during submission is not the final grade.
Style
All code should follow proper Racket Style.
Also, the repository itself must follow proper style. Specifically, it must have appropriate commit messages. See How to Write a Git Commit Message if you are unsure how to write a commit message.
Files
A submission must have the following files in the repository root:
hw2.rkt: Contains the hw solution code.
All defines should use the name specified in the exercise (ask if you are unsure) and should be provided.
The easiest (but not always the most readable) way to ensure all necessary definitions are provided is to (initially) put as the second line in the file:
This automatically provides all definitions in the file. (The first line should be #lang racket)
tests.rkt: This file should require hw2.rkt and define tests for it.
Specifically, it should define a rackunit test-suite which contains sufficient rackunit test cases (e.g., check-equal?, etc.) for each defined function.
README.md: Contains the required README information, including the GitHub repo url.
Submitting
When you are done, submit your work to Gradescope hw2. You must use the "GitHub" Submission Method and select your hw<X>-<LASTNAME>-<FIRSTNAME> repository.
Note that this is the only acceptable way to submit homework in this course. (Do not manually upload files and do not email files to the course staff. Homework submitted via any unapproved methods will not be graded.)