Homework 7
Last updated: Tue, 22 Oct 2024 14:42:31 -0400
Out: Mon Oct 21, 2024, 12pm (noon) EST
Due: Mon Oct 28, 2024, 12pm (noon) EST
Overview
In this assignment, you will need to create a big-bang program, using the The Design Recipe, from start to finish, from scratch.
This hw will be graded accordingly:
correctness (10 pts)
design recipe (20 pts)
style (10 pts)
README (2 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 hw7 repository hw7-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
Review the The Design Recipe section of the course website (topics that will be covered in future lectures are marked as such).
Notes and Reminders
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. You may need more more sophisticated contract constructors such as listof for this assignment.
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 come 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.
Also, remember that Racket Style and The Design Recipe reserves certain language features only for specific scenarios. For example, set! and other "imperative" features are not allowed ever. Conditionals such as cond should only be used with enumeration or itemization Data Definitions.
The submitted program must be only a series of defines (both constants and function definitions are allowed) and tests/examples. Do not run any other code, i.e., do not automatically start big-bang! Not following this this will result in GradeScope errors and point deductions.
You may look at prior code and examples to help you but BE CAREFUL. A "COPY-AND-MODIFY" PROGRAMMING STRATEGY WILL NOT WORK IN THIS COURSE (nor in the real world). Your program will be wrong (partially 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.
NEW You may find the "Syntactic Test Coverage" feature in DrRacket useful. At minimum, one-hundred percent of your code should be run (if not tested) before submission.
Programming
For this assignment, imagine Google has hired you to implement a one-line text box to be used in their products, e.g., the URL bar in a web browser.
Here is an online demo that approximates what the program might look like.
The main code should go in a file named hw7.rkt and tests should go in a tests.rkt file of the appropriate format.
In this assignment, each function should have at minimum of one (meaningful) Example and two Tests (that are not the same as the example).
In this assignment, your "World State" should be a TextBox data definition. You may design the data definition however you wish. But as a hint, two lists of single-character strings may be a convenient choice.
(If you do go with the suggested approach, you may find it convenient to define helper functions for converting between strings and lists of characters. Note that a "character" and a length-1 string are different data types so make sure to understand the difference (and ask questions if you do not) before attempting this assignment.)
- You will also need to design and implement the following functions:
create-TextBox : takes two string arguments and returns a TextBox instance. When the TextBox is rendered (see below), the strings should appear in the text box, separated by a "cursor". The cursor should be a CURSOR-WIDTH by FONT-SIZE pixel solid black rectangle.
TextBox? : returns true if given a TextBox instance
TextBox-pre : takes a TextBox instance and returns the contents before the cursor, as a string
TextBox-post : takes a TextBox instance and returns the contents after the cursor, as a string
render : used with big-bang to-draw clause.
Takes an instance of TextBox, and renders the text (using text with FONT-SIZE and FONT-COLOR font) and cursor, and places it into a TEXTBOX-WIDTH by TEXTBOX-HEIGHT pixel black outline rectangle. Leave INITIAL-SPACE number of pixels between the textbox left side and the start of the text.
For now, you may assume the text width is smaller than the textbox and you do not need to handle characters going out of the max textbox width.
key-handler : used with big-bang on-key clause.
This function should react to standard keyboard keys. More specifically, if the pressed key is "left", "right", "backspace", or "delete", the TextBox should be updated appropriately. The "enter" and "tab" keys may be ignored. Otherwise, all other "length 1" characters should be inserted into the TextBox in the expected way.
In addition, you should implement the following functions (which should should be a hint about how to approximately how to split your key-handler function into smaller functions/tasks):textbox-delete : consumes a TextBox and removes the character right after the cursor.
textbox-backspace : consumes a TextBox and removes the character right before the cursor.
textbox-insert : consumes a TextBox and a length-1 string and inserts that string where the cursor is and moves the cursor to the right of that character.
textbox-left : consumes a TextBox and moves the cursor one character to the left.
textbox-right : consumes a TextBox and moves the cursor one character to the right.
remove-char : signature will depend on your TextBox data definition
shift-char : signature will depend on your TextBox data definition
Note that all these functions should be very short and should process only one kind of data (probably a TextBox). If you find yourself writing a function more than 2-3 lines long, you may be on the wrong track.
If you follow the design recipe and have properly structured code—
one function does one task with only one kind of data— then this assignment will be easy. If you try to just "get the code working" or employ other unprincipled programming habits, then it will be more difficult to complete the assignment. As a reminder, here are some of the constants you should define and provide the following:
Constants
FONT-SIZE = 32
FONT-COLOR = "black"
CURSOR-WIDTH = 2
TEXTBOX-WIDTH = 512
TEXTBOX-HEIGHT = 40
INITIAL-SPACE = 4
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:
hw7.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 hw7.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 hw7. 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.)