Skip to main content

CSC 151.01, Class 08: Testing your procedures

Overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Discuss quiz
    • Questions
  • Lab
  • Debrief

News / Etc.

  • New places/partners!
  • Quizzes returned.
  • HW2 returned (I hope). Labs returned.
  • I’m still working on catching up. Sorry.

Upcoming Work

Extra credit (Academic)

  • CS Table, Tuesday, noon: Machine Ethics. (Info on Friday’s eboard.)

Extra credit (Peer)

  • Men’s Soccer vs. Buena Vista, Sept. 17 at 2:00 p.m.

Extra Credit (Misc)

  • Time Management Workshop, Tuesday, 11am, JRC 226.
  • Host a prospie

Other Good Things

  • ???

Quiz 2

  • Wide distribution of scores, not correlated with prior experience.
  • Some struggling with syntax. Some struglling with so many things at so many different levels.

Notes on definitions

#lang racket
(require csc151/all)
; cat is a procedure that multiplies its parameter by 2
(define cat (section * <> 2))
; mouse is a procedure that increments then doubles.
(define mouse (o cat increment))
; The section adds 5 so moose adds 5 and takes sqrt
(define moose (o sqrt (section + <> 5)))
; squirrel is 11
(define squirrel 11)

Notes on execution

> squirrel
11
> (mouse 5)
12
> (moose squirrel)
4
> ((section - <> 2) 5) ; The section give "subtract 2"
3
> (map cat (iota 6)) ; Make the list '(0 1 2 3 4 5) and double each.
'(0 2 4 6 8 10)
> 

Part 2: The key idea is to use string-append.

(define greet
  (lambda (name)
    (string-append "Hello " 
                   name
                   ". How was your day?")))

Important issues

  • Use string-append
  • Strings need to be in quotation marks
  • The thing that’s a parameter needs not to be in quotation marks.
  • The parameter should not be in parenthesis. Parenthesis mean “This is a procedure”
(define greet
  (section string-append "Hello" <> ". How was your day?"))

or

(define greet
  (o (section string-append <> ". How was your day?")
     (section string-append "Hello " <>)))

Questions

Can you put multiple diamonds in section?
Yes
Should we document each procedure we write?
Yes, at least the first four P’s.
What does “skewedness” mean?
It’s a term I invented for “the sum of the geometric mean of the differences from the min and the geometric mean of the differences from the max”.
How do we convert between numbers and letters
char->integer and integer->char
You may have to switch your number to this scale by adding or subtracting or rounding or dividing or some combination thereof.
We have a list of lists. We want a single list.
If we have two lists and want a single list, we use append
If we have a list of values and want to do the same thing to neighboring pairs, we use reduce
So …
> (define lol (list (list 0 1 2) (list 0 1 2) (list 0 1 2) (list 0 1 2) (list 2 3 4)))
> lol
'((0 1 2) (0 1 2) (0 1 2) (0 1 2) (2 3 4))
> (reduce append lol)
'(0 1 2 0 1 2 0 1 2 0 1 2 2 3 4)
Doesn’t lol stand for laugh out loud?
Not in my class. list-of-lists.
Will you tell us how to do the extra credit?
No.
Do we have to build the cycle with map if we build it without map?
Yes.

Lab

Why do we have the strange i-z-1?
See the whiteboard.
We’ve dropped z+1 elements from the list, so the indices decrease by z+1. i-(z+1) = i-z-1.
Could you explain the epsilon a bit more?
When we compute with inexact numbers, we approximate. Hence, a computation may give something near the desired value, but not exactly the same. The epsilon tells us how close is close enough.
We include the epsilon because different scales of numbers and different computations may have different notions of exactness. If I”m working with numbers larger than one billion, I might be okay if they are within 5 of each other. If I’m working with numbers closer to one-billionth (that is, 1/1,000,000,000, at least in the US), within 5 is guranteed.
Why are we using an epsilon of zero?
We want the result to match exactly.
Why did you make us write 13 (epsilon of 2) different explanations in
3d?
Past experience suggests that students don’t think carefully enough about the range of things they might test. Past experience also suggests that if I only ask you to talk through it, you’ll think you get it, but won’t. This one painful exercise is intended to help you think more carefully.

Debrief

Things Sam hopes you took away from today’s class.

  • Writing some simple tests is not much harder than just doing experiments,
    • You can write checks even without a test suite.
  • On the other hand, writing a comprehensive test suite is hard. You need to think about lots of things that can go wrong.
    • I still write test suites that miss some of the strange things in the code of the folks I am testing.
  • That thinking is often helpful, as it lets you reflect more on what the procedure is supposed to do independent of the code you’ve written.
    • Consider writing tests before code.
    • You do so mentally, anyway. “What should my procedure output on an input of 3?”