Approximate overview
lambda on the same line as your define.(+(- 2)3) or anything like that.#t and #f.
(if TEST #t #f) is a long way to write TEST(equal? TEST #t) is also a long way to write TESTand and or instead of if and condExample
(define non-integer-number?
(lambda (x)
(cond
[(integer? x)
#f]
[(number? x)
#t]
[else
#f])))
(define non-integer-number?
(lambda (x)
(and (number? x)
(not (integer? x)))))
Does the order in which you run tests matter?
Yes. You need to make sure that something is a number before using
exact?and you need to make sure that something is an integer before usingeven?.
; The cond approach
(define median-of-three
(lambda (x y z)
(cond
[(or (<= x y z) (<= z y x))]
y]
[(or (<= x z y) (<= y z x))]
z]
[(or (<= y x z) (<= z x y))]
x]
[else
(error "math makes no sense")])))
; The nested-if approach
(define median-of-three
(lambda (x y z)
(if (<= x y)
(if (<= y z)
y
(if (<= x z)
z
x))
(if (<= x z)
x
(if (<= y z)
z
y)))))
; The mathy approach
(define median-of-three
(lambda (x y z)
(- (+ x y z)
(min x y z)
(max x y z))))
; The minmax approach
(define median-of-three
(lambda (x y z)
(min (max x y) (max x z) (max y z))))
Sam’s tests
(test-equal? "in order" (median-of-three 1 2 3) 2)
(test-equal? "in reverse order" (median-of-three 10 3 1) 3)
(test-equal? "median first, largest last" (median-of-three 4 2 5) 4)
(test-equal? "median first, largest second " (median-of-three 5 8 1) 5)
(test-equal? "median last, largest first" (median-of-three 11 5 6) 6)
(test-equal? "median last, largest second" (median-of-three 1 11 7) 7)
(test-equal? "all equal" (median-of-three 8 8 8) 8)
(test-equal? "first two equal, third larger" (median-of-three 9 9 10) 9)
(test-equal? "first two equal, third smaller" (median-of-three 0 0 40) 0)
(test-equal? "last two equal, first larger" (median-of-three 3 1 1) 1)
(test-equal? "last two equal, first smaller" (median-of-three 0 2 2) 2)
(test-equal? "outside equal, first larger" (median-of-three 3 5 3) 3)
(test-equal? "outside equal, first smaller" (median-of-three 4 2 4) 4)
(test-equal? "fractions" (median-of-three 1 2 3/2) 3/2)
(test-equal? "includes negatives" (median-of-three 3 -4 11) 3)
(test-equal? "all negative" (median-of-three -3 -5 -4) -4)
TPS is: “Think Pair Share”
TLA is “Three Letter Acronym”
Which do you prefer? Why? (TPS)
What hasn’t Sam tested? (TPS)
Questions
Why use the test technique?
The computer is better than we are at comparisons.
We’re more likely to see failures if they are the only things we see.
Utilize boolean expressions and values in a program to produce conditional behavior.
As you know, we often associate words with students’ standing in college. At Smileyville College, Those who have completed fewer than four terms are “freshlings”, those who have completed between four and seven terms (inclusive) are “wise fools”, those who have completed between eight and eleven terms (inclusive) are “subordinates”, and those who have completed at least twelve terms are “elders”.
Write a procedure, (status terms), that, given the number of
terms a student has completed as input, produces a string that
describes the student using the terms above.
There weren’t many questions on these readings.
Are you one of those professors that allows us to leave group members’ names off of projects if their contributions were unsatisfactory? Or do you prefer to move around group members?
Your primary group projects will be labs. They are small enough that I don’t think it’s an issue.
Our bigger worry is partners who plow ahead without making sure that their partner contributes / understands.
In both cases, you should talk to me (or a mentor).
What happens if our lab partners are unwilling to meet outside of class to finish a lab?
You can finish the lab separately. But I’ll try to make sure that most labs are finished in class.
If I’m sitting at a lab with a partner, and have no clue what I am doing how should I work to be useful, while also being involved with the lab?
Ask questions.
Obligatory story.
Who writes the autograders?
I do. I’m rewriting all of them this semester.
How long does it take you?
It varies. Usually about an hour for a lab and longer for a mini-project. In most cases, I also do (or re-do) the lab or mini-project, which adds additional time. The MP2 autograder + answers + fixing took me about three hours.
Discuss with your partner and be ready to answer.