Bitpath

Lesson 2 · Unit 02

Spot the bug

Boundaries, missing cases, defaults, callers

12 exercisesabout 3 min

What you practise

  • Off-by-one, a missing check for nothing, a changed default, the caller that was not updated, the test that no longer tests

Try a question from this lesson

Pick one

The commit message says "fix: end index is inclusive". With this change applied, what does page 1 of size 3 hold for the items a, b, c, d?

--- a/pages.py
+++ b/pages.py
@@ -1,4 +1,4 @@
 def page(items, number, size):
     start = (number - 1) * size
-    end = start + size
+    end = start + size - 1
     return items[start:end]
Hint

Work out start and end for page 1, then recall whether a slice includes its end index.

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

What a diff does not show

A diff shows what changed. Bugs hide in what did not.

Five places to look: the boundaries of changed arithmetic and comparisons; the empty and the missing case; changed defaults; callers outside the diff; tests that became weaker.

And read the removed lines. A deleted check is a deleted behaviour.

10 more exercises in the app

  • 2× type the answer
  • 5× multiple choice
  • 1× true or false
  • 1× fill the blanks
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy