Skip to main content

CSC 151.01, Class 13: Testing Your Procedures, Continued

Overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Questions
  • Pair programming
  • Key ideas in testing
  • Careful postconditions
  • Lab / Exercise

News / Etc.

  • New partners! You know the drill.
  • Tuesday is Valentine’s day. I am likely to be off email starting at about 5:30 p.m. If you have exam questions, get them to me before then.
  • Warning! Friday the 13th falls on Monday this month.
    • That’s probably why I don’t yet have grades from the graders.

Prospie visit

  • Bio 150: Biological responses to stress. Follow the sketchy guy in the grey hat. He’s …, which should make it less creepy.
  • Electronic music at 2pm in the basement of Bucksbaum.

Reminders

  • Ask questions via email! I’m always happy to (try to) answer questions via email. There is no need to apologize when sending me questions. If I take too long to answer, send another email (or even text, if it’s a reasonable hour).
  • Visit me in my office! I’m always happy to see students during my office hours. I prefer that you book me at https://rebelsky.youcanbook.me, but you can also just show up during office hours and hope that I’m not busy.
  • Use our tutors! We have tutors available Sunday through Thursday evening from 7-10 p.m. in Science 3813/15.
  • Visit mentor sessions! We have mentor sessions on Wednesday and Thursday evenings from 8:00-9:00 p.m. in the CS Commons. Wednesdays will be more Q&A, Thursdays will include sample quizzes.
  • Visit review sessions! I run review sessions on Thursdays at 9am in this room.
  • We have individual tutors!
    We have individual tutors available for those who take advantage of the above and find that it’s not enough.
  • Visit our store! We have office supplies in the commons. Price is free will donation.
  • Get news! Feel free to ask me to sign you up for the department mailing list.
  • Suggest extra credit! Send me extra credit ideas and opportunities.

Upcoming Work

  • Exam 1 due Tuesday at 10:30 p.m.
  • Epilogue due Wednesday at 10:30 p.m.
  • No lab writeup!
  • Reading: Drawings as Values due tomorrow.

Extra credit (Academic/Artistic)

  • CS Table, Tuesday at noon, 14 Feb 2017. On Technology, Slots, and Whales. Reading packets should be available outside Curtsinger’s office or Orsera’s office.
  • Thursday extras, Thursday, 16 Feb 2017, 4:15 p.m., Science 3821: 4-1 joint BA/MSC program with UIowa.

Extra credit (Peer)

  • Friday-Saturday-Sunday, 17th-19th, Swimming and diving conference championships. (You can only get credit for two of the three days; staying for an hour counts.)
  • Saturday the 18th, Symphony Concert. 2-4 p.m. Sound painting and more! In Sebring-Lewis.

Good things to do

  • Women’s basketball (Senior day) next Saturday at 1pm.
  • Men’s basketball (Senior day) next Saturday at 3pm.

Code formatting

What I’d often receive.

(define irgb-weighted-average
  (lambda (weight color)
    (irgb(/(+(*(irgb-red color)weight)(irgb-green color)(irgb-blue color))(+ weight 2))
    (/(+(*(irgb-green color) weight)(irgb-red color)(irgb-blue color))(+ weight 2))
    (/(+(*(irgb-blue color) weight)(irgb-green color)(irgb-red color))(+ weight 2)))))

What I’d like

(define irgb-weighted-average
  (lambda (weight color)
    (irgb (/ (+ (* (irgb-red color) weight) (irgb-green color) (irgb-blue color)) 
             (+ weight 2))
          (/ (+ (* (irgb-green color) weight) (irgb-red color) (irgb-blue color)) 
             (+ weight 2))
          (/ (+ (* (irgb-blue color) weight) (irgb-green color) (irgb-red color)) 
             (+ weight 2)))))

Citing formulae

We cite that you can trace ideas.

Sam goes off on storytelling tangents. But at least they are relevant.

Questions

Questions on the exam

Why is my solution working in some situations but not others?
I don’t know. You didn’t send me your code nor examples of when it works and doesn’t work. I realize that you attribute superhuman intuition to me, but that intuition is limited.
I’ve spent four hours on this problem and haven’t made progress. What
should I do differently?
Ask questions after fifteen minutes.
I’m having trouble finding time to ask you questions in person. Can I
send a question via email?
YES! Please do.
Will you be this snarky when you reply to my email?
Probably.
Why am I not getting the right answer for problem 3 when I use 1.2 4.2 3.2.
I expect 3.2, I get 3.199999999994.
Decimals are inexact. That means we’ll get rounding errors in some computations involving them.
Where is that code file for the exam?
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC151/2017S/code/exam1.rkt
What happens if we didn’t read the instructions and didn’t create a time log?
You won’t get the bonus points. You’ll know better next time.
Why are there citations both in the individual problems and at the top of
the exam?
To remind you of the importance of citing. Also: Some general resources, some specific. At the top: “I used the class Web site”. In an individual problem: “I worked with student 000000 on a related problem and copied code from that solution.”
Do we need to use APA-style citations?
No, not for working with a partner.
Do we need to know our former partner’s number?
No.
What’s the difference between a test and an example?
A test is done using rackunit. An example is just that: You show the input and output.
Do we need to do both tests and examples?
No. You didn’t know about testing when you got the exam. I assume that you mostly knew only about examples.
For problem 5, can we assume that both minutes and seconds are exact
integers?
Yes.
For problem 3, what should our explanation of how it computes the result
look like?
I’m fine with an explanation of why the formula gives the expected result. “It gives three times the largest value because (max ...) is te largest value, (max (min ...) ...) is still the largest value, and …”
Step-by-step explanations are fine, too.

Questions on unit testing

Why is there a third parameter in (check-= val1 val2 epsilon)?
The margin of error. We probably are okay with inexact values if they are within .000000001, but it depends on the situation.

Questions on pair programming

Testing vs. examples

Suppose we have designed a procedure, irgb-darker, with the postconditions that the luma of the result is less than the luma of the original, unless the original is pure black.

Example

> (define c1 (irgb 100 40 23))
> (irgb-luma c1)
52 ; This is an estimate, it was not generated by program
> (irgb-luma (irgb-darker c1))
36 ; Look, it's smaller!

Test

> (define c1 (irgb 100 40 23))
> (check-true (< (irgb-luma (irgb-darker c1)) (irgb-darker c1)))

Pair programming

Take three minutes with your partner and answer the following questions.

  • What do you see as the primary reasons people do pair programming in general?
    • When you program by yourself, you are monofocused. Someone else can help you think more broadly and catch dangerous issues.
    • Lets you connect ideas and bounce ideas off people.
    • Two heads contain more knowledge than one head.
    • You learn from other people.
    • You learn from other people, particularly practices of the local community.
    • Different roles means that both can work more efficiently.
    • Peer pressure.
    • Switching is important, because your two heads start to merge into one.
  • Are they different at all in this class? That is, which of the ones you just listed apply in this class and which don’t? Are there other reasons to pair program in this class?
    • Sometimes you get stuck with two mockers, both of whom want to get the work done as quickly as possible.
      • “Are you mods or rockers?”
    • When you program by yourself, you are monofocused. Someone else can help you think more broadly and catch dangerous issues.
    • Let’s you connect ideas and bounce ideas off people.
    • Two heads contain more knowledge than one head.
    • You learn from other people.
    • Meet really awesome people who you might not otherwise meet.
    • Practice for the real world.
    • Switching is important, because you start to think the same.
  • What are the roles of the driver and navigator?
    • Driver: The person at the keyboard.
    • Navigator: Explains what they want the driver to write.
    • Driver: Takes the lead in writing the solution.
    • Navigator: Stops the driver from crashing into walls and provides reference (“The nearest rest stop is two miles ahead”; “You don’t have a question mark for check-true”). Provides alternatives.
  • What’s wrong with “code and fix”?
    • Testing might be expensive. Thinking through implications first can be important.
    • Write some code without a lot of thought, try it, and then keep changing things until it works.
    • As contrasted with “think carefully through what you are doing; if it doesn’t work, step back and think globally.”

Key ideas in testing

;;; Procedure:
;;;   irgb-lighter
;;; Parameters:
;;;   color, an integer-encoded RGB color
;;; Purpose:
;;;   Compute a lighter version of that color
;;; Produces:
;;;   lighter, an integer-encoded RGB color
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   The components are larger than in the original color,
;;;     unless they were already 255.
;;;   (irgb-red lighter) > (irgb-red original)
;;;   (irgb-green lighter) > (irgb-green original)
;;;   (irgb-blue lighter) > (irgb-blue original)