Unit 21: Testing, Debugging, and Version Control
The habits that catch a bug before a user does, and the safety net that lets you undo a change or work alongside someone else.
5 topics · 16 questions
Each topic is a path, not a menu: work down it in order and every question builds on the one above. Click any of them to watch the answer draw itself.
Writing a Unit Test
- How it worksHow does a unit test call a function with a known input and automatically compare the result to the expected answer?
- Worked exampleTrace a test asserting that add(2, 3) == 5 and find what happens if add is buggy and returns 6.
- Common mistakeWhy doesn't a test suite that passes completely guarantee a program has no bugs left in it?
- Going furtherWhat happens to a test suite's usefulness once every test only checks the happy path with no edge cases?
Your turn1 of 2
A test suite includes 142 separate unit tests, each calling a function with a known input and comparing the result to an expected answer. If 6 of the n tests fail because the function is buggy, how many of the n tests pass?Edge Cases: Empty Input, One Element, and Boundary Values
- How it worksHow does testing an empty input, a one-element input, and the largest allowed input catch bugs a typical case never would?
- Worked exampleTrace what a function assuming at least two elements does when called on an empty list or a one-element list.
- Going furtherWhat happens to a binary search implementation once it's tested against a list containing just one element?
Your turn1 of 2
A function is tested against 14 edge cases in addition to its 33 ordinary typical-case tests. How many total test cases, edge plus typical, does this testing cover?Debugging by Stepping Through a Program
- How it worksHow does a debugger let you pause a program at a breakpoint and inspect every variable's current value?
- Worked exampleTrace stepping through a loop meant to sum a list but returns 0, watching total's value freeze at each line.
- Common mistakeWhy isn't adding a single print statement always the fastest way to find where a bug actually is?
Your turn1 of 2
A programmer steps through a loop meant to sum 140 numbers one line at a time using a debugger, watching the total variable at each of the n iterations. How many times does the programmer observe the total variable's value during this stepping process?Git Commits and a Repository's History
- How it worksHow does each git commit save a snapshot of the whole project, letting you step back to any earlier point?
- Worked exampleTrace a repository's history after three commits and find what checking out the first commit's hash restores.
- Common mistakeWhy isn't a commit the same thing as just saving a file?
Your turn1 of 2
A repository has 697 commits in its history, each saving a complete snapshot of the whole project. How many total project snapshots does this repository's history hold?Git Branching and Merging
- How it worksHow does creating a branch let you make commits on a separate timeline before merging that work back into main?
- Worked exampleTrace a feature branch created from main, given two commits, then merged back into main.
- Going furtherWhat happens during a merge when both branches changed the exact same line of the exact same file?
Your turn1 of 2
A feature branch is created from main and given 35 commits before being merged back into main. How many total commits does the feature branch add to the project's history once merged?