Lesson 1 · Unit 04
Properties, not examples
State what must always hold, and let the computer pick the inputs
What you practise
- Invariants that hold for every input (sorting keeps length and order), round-trips, testing against a slow obvious version, random inputs with a seed
Try a question from this lesson
Pick one
You cannot write down the right output of a sort for every possible list. Which check is still true for every input, with no answers worked out by hand?
Correct answer
The output has the same length as the input
Why
A statement that holds for every input is called a property. You can check it on a thousand random lists without knowing a single expected result in advance.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Properties
An example test checks one input against one known answer.
A property is a statement that must hold for every input. For a sort: the output is in order, it has the same items as the input, and sorting it again changes nothing.
A property test generates many inputs and checks the statement on each one. It finds the cases you did not think of, which is where bugs live.
10 more exercises in the app
- 2× type the answer
- 1× fill the blanks
- 4× multiple choice
- 1× true or false
- 1× order the lines
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.