Back Summary

Session #8

Multiple choice: 15/15 correct ยท Short answer: 5/5 answered · completed Sep 6, 2026

Answers

What is the first major step of the HtDF recipe?

✓ Signature, purpose, and stub

What should a good purpose statement do?

✓ Describe the relationship between the consumed data and produced result

Why is a stub useful before the real function body is written?

✓ It lets tests call the function and run

With a correct stub and meaningful tests for an unfinished function, what is the usual desirable result?

✓ Tests run and fail rather than error

What should guide the choice of test expectations?

✓ The specification and purpose

What is the purpose of a function template in early HtDF?

✓ To show the structural outline and available inputs

Which is the better signature when a function always produces a non-negative whole number?

✓ Image -> Natural

What does it mean that the HtDF recipe is not a waterfall process?

✓ The steps can be revisited when later work reveals a better design

A function tall? has a test only for a tall image. What important problem remains?

✓ The false branch may be untested

If a test fails after the body is implemented, what should you check before changing correct-looking code?

✓ Whether the expected value in the test matches the specification

The specification says a rating is poor when it is less than 4.0. What should happen at exactly 4.0?

✓ It belongs to the next category, not the < 4.0 category

Why are verbose expectations such as (* 2 4.2) sometimes useful?

✓ They document the intended computation, not just the final literal result

What does the Racket naming convention tall? communicate?

✓ The function is expected to produce a Boolean

Which test set best examines a boundary at 25 where values below 25 and values at/above 25 behave differently?

✓ 24.9, 25, and a value just above 25

Why is changing a correct implementation just to satisfy an incorrect test dangerous?

✓ It makes the function conform to a mistaken expectation instead of the specification

Why is a stub written before the examples/tests in the HtDF recipe, and what should normally happen when meaningful tests are run against an unfinished stub?

Stubs are written to the tests have something to call. This makes it so you can make tests before writing out the entire body of the function.

not graded

Accepted answer

The stub gives the function the correct name and parameters so the tests can run. Meaningful tests should normally run and fail because the stub does not yet implement the correct behavior; they should not produce an error.

Write a signature, purpose statement, and stub for a function named double that consumes a Number and produces twice that Number. The stub should produce a valid Number but should not implement the real calculation yet.

; Number -> Number
; take a number and returns double that value (number)
(define (double n) 10))

not graded

Accepted answer

; Number -> Number
; produce twice the given number
(define (double n) 0)

Write a Racket function named passing? that consumes a Number score and produces true when the score is at least 60 and false otherwise.

; Number -> Boolean
; Takes a test score (number) and returns whether it is at least 60
(define (passing? n) (>= n 60))
not graded

Accepted answer

(define (passing? score)
(>= score 60))

A function named cheap? should produce true when a price is strictly less than 100. Write three check-expect tests that test the boundary: one value below 100, exactly 100, and one value above 100.

(check-expect (cheap? 99) true)
(check-expect (cheap? 100) false)
(check-expect (cheap? 105) false)
not graded

Accepted answer

(check-expect (cheap? 99) true)
(check-expect (cheap? 100) false)
(check-expect (cheap? 101) false)

The purpose of area is to produce the area of a square whose side length is n. The function is (define (area n) (* n n)), but a test says (check-expect (area 3) 3) and fails. What should you change, and why?

The test should be

(check-expect (area 3) 9)

or

(check-expect (area 3) (* 3 3))
not graded

Accepted answer

Change the expected value in the test from 3 to 9: (check-expect (area 3) 9). The function correctly follows the purpose; the test expectation is wrong.