Sub topic 3
Checking AI Code Without Skipping the Learning
Assume you know variables, functions, conditionals, loops, and how to run Python scripts and tests. The goal is not only to make AI-generated code pass once. The goal is to understand its behavior and limits.
Check Code with Tests You Write
Read the proposed behavior first. List normal cases, boundary cases, and invalid inputs. Then write tests before accepting the code. For example:
def median(values):
if not values:
raise ValueError("median() requires at least one value")
ordered = sorted(values)
middle = len(ordered) // 2
if len(ordered) % 2:
return ordered[middle]
return (ordered[middle - 1] + ordered[middle]) / 2
assert median([3, 1, 2]) == 2
assert median([4, 1, 3, 2]) == 2.5
assert median([9]) == 9
try:
median([])
except ValueError:
pass
else:
raise AssertionError("empty input should fail")These tests check odd and even lengths, one item, and empty input. Add cases based on the function's contract, not only on examples supplied by the AI.
Debug with Your Own Hypotheses
When a test fails, first state what you think is wrong. Predict the failing value or program state. Then ask the AI to inspect that hypothesis, show relevant intermediate values, or suggest one diagnostic experiment. Compare its explanation with your prediction. Do not ask for a replacement immediately.
Explain the Code Back
After the tests pass, explain each branch and important variable in your own words. If you cannot explain why sorting is safe here or why the middle indexes differ, ask for a smaller hint and try again.
Set Project Boundaries
Decide which work AI may do. For example, you might allow syntax suggestions and review, but require yourself to design the data model, write initial tests, and explain every accepted change.
Reduce Support and Track Progress
Use AI less as your unaided skill grows: hints first, then review, then occasional full solutions. Keep a log of tasks completed without help. At regular intervals, solve a small problem from memory and record whether you could predict behavior, test edge cases, and debug independently.
Exercise
What should you do before asking an AI to fix a failing test?
Show answer
State your own hypothesis, predict the relevant result, and run a focused diagnostic.