Published using Google Docs
Lecture 02: 1/25
Updated automatically every 5 minutes

Real talk: Come to class (but if you can’t, let us know, and it’s lecture captured). There will be Reef polling!

Come see guest speakers. These people are awesome and there will be coffee.

Last time: The weaknesses of testing

Today: We want to sort records of the form {first :: String, last :: String}

Turn ‘n Talk: What tests would you write for an algorithm that sorted records of this form?

Turn ‘n Talk: Think about another situation where this comes up.

Hint: It involves a data structure you’ve all seen in your previous classes.

Strategy: Step back and write down the types (e.g add1 :: num → num). In our case,

What’s a reasonable test? For sorting [{Tim, Nelson}, {Andrew, Wagner}, {Chantal, Toupin}, {Sol,

Zitter}]

Question: How fast should our validator (runtest) need to be? Aren’t we redoing a lot of the work of the thing that we’re testing?

Idea: Use computers to generate inputs! We won’t focus much on randomizing inputs, but if you’re interested see QuickCheck.

Problem: Integer factorization. “Easy” to generate random inputs (just random numbers).

Turn ‘n Talk: Why might validation for integer factorization be a problem?

Problem: Sudoku. “Easy” to validate (just follow the rules). Hard: generating inputs, since there needs to be a unique solution.

Idea 1: Sometimes algorithms are nondeterministic so we use validator functions to test properties about the algorithm.

Idea 2: Use computers to generate (random) inputs.

Idea 1 + Idea 2 = Oracle