Skip to main content

CSC 151.01, Class 08: Testing your procedures

Overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Questions
  • Walk-through of exam 1
  • Lab
  • Debrief

Preliminaries

News / Etc.

  • New partners!
  • Please ask questions early! (Particularly on the exam.)
  • Except on the exam, please help your classmates.

Upcoming work

  • Quiz Friday!
    • Writing procedures with lambda, section, and composition
    • Documenting procedures
  • Exam 1 due Tuesday at 10:30 pm.
    • Prologue due Friday night.
    • Exam due Tuesday night in electronic form.
    • Cover sheet due in class on Wednesday
  • Reading due before class Friday
  • No lab writeup!
  • Flash cards for week 3 due TONIGHT at 5pm.

Extra credit (Academic/Artistic)

  • CS Extra, 4:15 p.m. Thursday, Science 3821: The design of CSC 151
    • Drinks and snacks at 4:00 p.m. in the CS Commons
  • Rosenfield Symposium on Environmental Degradation and Conflict
    • Particularly Scholars’ Convocation Thursday at 11am.
    • Or anything else.
  • Saturday at 11am: MET broadcast of L’Elisir D’Amore.
  • Visit the two exhibits at the Faulconer Gallery.

Extra credit (Peer)

  • Listen to KDIC Wednesdays at 6pm - Witty banter with co-host and Indian, Arabic, and Farsi music. (Up to two units of extra credit.)
  • Friday at 8pm, Contra Club Dance in Younker Lounge 1st
  • Peer editing with SS. Talk to SS about the details.
  • Wednesday (February 14th), the Langan CAs will be co-hosting an event with SHIC about sex positivity and SHIC resources. The event will most likely take place 8:30-9:30pm in Langan first lounge.

Extra credit (Misc)

Other good things

Questions

Can we talk about why max gives an inexact number?

  • Sure. Here’s the start of an example.
(define newmax
 (lambda (x y)
   (if (>= x y)
       x
       y)))

(define large 1152921504606846976)

> large
1152921504606846976
> (newmax (+ large 2) (+ large 3.0))
1152921504606846978
> (+ large 3.0)
1.152921504606847e+18
> (inexact->exact (+ large 3.0))
1152921504606846976
> (max (+ large 2) (+ large 3.0))
1.152921504606847e+18
> (inexact->exact (max (+ large 2) (+ large 3.0)))
1152921504606846976

Moral: Once we’re in the approximate domain, we should stay in that domain. Otherwise, things are even stranger.

I forgot my password. What should I do?

  • Visit with our SysAdmin.

How do we deal with large numbers?

  • Accept approximations.
  • Deal only with exact numbers.

How do we conceptually think about writing tests?

  • Write some really simple tests. (simple for the procedure.) For example, if i’m testing my increment procedure, I’d try it on 0, 1, -1.
  • Expand to things that are a bit harder and that better reveal complexities. Try exact and ineact. Real, rational, complex.
  • Adversarial lawyer mode: “Can I break it?” (expt 2 80).

OKay, but I have to write code for this class. What does the code look like?

  • At the individual test level. This is a group of things that have some commonality. “My simple tests”
(test-case "my simple tests"
           (check-equal? (increment 1) 2)
           (check-equal? (increment 0) 1)
           (check-equal? (increment -1) 0))
  • Another group, inexact numbers
(test-case "inexact-numbers"
           (check-= (increment 1.0) 2.0 .000000001)
           (check-= (increment 0.0) 1.0 .000000001)
           (check-= (increment -1.0) 0.0 .000000001))
  • Finally, I’ll group them into a test suite
(define increment-tests 
  (test-suite 
    (test-case ...) 
    (test-case ...) 
    (test-case ...)))
  • Now I can run them
> (run-tests increment-tests)

What’s the difference between check-= and check-equal??

  • check-= is for numbers (inexact and exact)
  • check-equal? is for more or less everything else (strings, lists, Boolean values, symbols, etc.)
  • I used check-equal? above because it will work for exact numbers, and I wanted to get through the example first. I’d use the following in practice.
(test-case "my simple tests"
           (check-= (increment 1) 2 0)
           (check-= (increment 0) 1 0)
           (check-= (increment -1) 0 0))

When would we ever want to use check-not-equal?

  • If I had not done an early-class demonstration, I would probably have an answer to that question.

Exam 1

  • [Sam has trouble with his Web site and complains loudly.]
  • Make sure to copy the starter code.
  • Don’t talk to others.
  • Bring questions!

Lab

  • Use (require csc151) rather than (require csc151/all).
  • Why did you use an epsilon of 0 for inexact numbers? I’m not sure. Fixed.
  • No writeup!