CSC 183 · Introduction to Problem Solving
Our notes
2 min readTesting
Testing runs a program with chosen inputs and compares its output with the expected output worked out by hand. Good test data includes:
- Normal data: typical values (a score of 65).
- Boundary data: values at the edges (0, 39, 40, 100).
- Erroneous data: values that should be rejected (−5, 150, "abc").
A test plan lists each test, its input, the expected result and the actual result.
Worked example: test plan for a grading program
| Test | Input | Expected | Why |
|---|---|---|---|
| 1 | 75 | A | normal |
| 2 | 70 | A | boundary of A |
| 3 | 69 | B | just below A |
| 4 | 40 | E | lowest pass |
| 5 | 39 | F | just below pass |
| 6 | 101 | "invalid score" | outside range |
If test 2 prints B, the program probably uses > 70 instead of >= 70.
Debugging
Debugging is finding and fixing the cause of an error.
- Reproduce the error with a small input.
- Trace the program by hand (a trace table) or add print() lines to see the values of variables at each step.
- Form a hypothesis about the cause, change one thing, and test again.
- Re-run all earlier tests to make sure the fix broke nothing else (regression testing).
Worked example: find the bug
total = 0
for i in range(1, 5):
total = total + i
print("Sum of 1 to 5 is", total)
It prints 10, but 1 + 2 + 3 + 4 + 5 = 15. A trace shows i takes 1, 2, 3, 4 only: range(1, 5) stops before 5. Fix: range(1, 6). Now it prints 15 ✓.
Evaluation and refinement
Once a program works, ask:
- Does it meet all the requirements, including unusual cases?
- Is it easy to read (clear names, comments)?
- Is it efficient enough for real data sizes (binary search instead of linear for a long sorted list)?
- Does it handle bad input politely instead of crashing?
Stepwise refinement also works the other way: start with a rough outline ("read scores; compute grades; print report") and refine each step into more detail until every line can be coded.
Documentation
Write what the program does, how to use it, its inputs and outputs, and its limits. Comments inside the code explain tricky parts. Others (and you, months later) will need it.
Exams usually ask
- Distinguish syntax, runtime and logic errors, with examples.
- Prepare test data (normal, boundary, erroneous) for a given program.
Common mistake
Testing only with "nice" values. Most bugs live at the boundaries.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Best pick Introduction to Python Programming, 1.6 Error messages
(opens openstax.org in a new tab)
OpenStax, Introduction to Python Programming, 1.6 Error messages, CC BY-NC-SA 4.0 · licence
-
Software testing
(opens en.wikipedia.org in a new tab)
Wikipedia, Software testing, CC BY-SA 4.0 · licence
-
Debugging
(opens en.wikipedia.org in a new tab)
Wikipedia, Debugging, CC BY-SA 4.0 · licence
-
OpenStax, Introduction to Python Programming (whole free textbook)
The whole book, free to read online or download as a PDF (the PDF is large: Wi-Fi).
(opens openstax.org in a new tab)
OpenStax, OpenStax, Introduction to Python Programming (whole free textbook), CC BY-NC-SA 4.0 · licence
Watch
-
Testing and Debugging
8 min · ≈ 36 MB · about ₦20
(opens youtube.com in a new tab)
-
Testing and Debugging in Software Engineering | Complete Guide for Beginners
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
Testing and debugging difference explained
7 min · ≈ 32 MB · about ₦18
(opens youtube.com in a new tab)
-
OCR Computer Science 2.3.2a Testing
6 min · ≈ 27 MB · about ₦15
(opens youtube.com in a new tab)
-
Iterative Refinement and Prompt Debugging: One-Change Principle | Prompt Engineering Ep 12
7 min · ≈ 32 MB · about ₦18
(opens youtube.com in a new tab)
-
UVU CS 2810 - Nov 9 2020 - Chapter 6 - Stepwise Refinement
1 h 18 min · ≈ 351 MB · about ₦197
(opens youtube.com in a new tab)
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.