← VCE Software Development U3O1

Checking and testing AI-generated code

Read and trace AI code, then test it with your own boundary and invalid data, and check it meets the requirements. It can look right but be wrong or use made-up functions.

Understanding Checking and testing AI-generated code in VCE Software Development U3O1

What it does: A trace table is how you read and trace AI code step by step to find out what it really does, rather than assuming it works. Passing text where a number is expected is invalid test data, and it shows whether the AI code handles wrong input safely. Boundary values (0 and 100) and values just outside the range (-1 and 101) are the most likely to expose errors in AI code. The code should use >= and <=. Boundary testing with 0 and 100 would catch this logic error. AI tools sometimes invent functions or libraries. Check the official documentation. Here, sum(prices) is the real function.

Common mistakes: The requirement says a mark of 50 passes. Testing the boundary value 50 returns False with >, so the AI code is wrong. It should be >=. math.squareroot() does not exist. AI tools can make up functions that look real. Check the documentation. The real function is math.sqrt().

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 178–193) and word search (Modules 168–193).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
An AI tool gives you code that looks neat and runs without errors. What should you do before using it?
Trace it and test it with your own test dataTrust it, because code that runs must be correct
Matches
# AI code ran with no errors, so it is correct. Ship it!
↓
Running without errors does not prove the code is correct. It can still give wrong results, so it needs tracing and testing with your own data.
Applying
Meanings
Term
Verify AI-generated code
Meaning
Read and trace AI code, then test it with your own boundary and invalid data, and check it meets the requirements. It can look right but be wrong or use made-up functions.
Practice
def is_valid_age(age):
Testing
Gaps
grade(50) == "P"
Check Answer
Spots
1def is_pass(mark):
2 return mark > 50

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Void Whale' badge — Definition Drifter, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. An AI tool gives you code that looks neat and runs without errors. What should you do before using it?
A. Trust it, because code that runs must be correct
B. Trace it and test it with your own test data ✓
Code can run without errors and still give wrong results. You must read, trace and test AI code before you use it.
2. Your requirement says a mark must be accepted from 0 to 100. Which test data best checks AI-generated validation code?
A. -1, 0, 100 and 101 ✓
B. Only 50, because it is a typical value
Boundary values (0 and 100) and values just outside the range (-1 and 101) are the most likely to expose errors in AI code.
3. The AI wrote: if mark > 0 and mark < 100. The requirement says 0 to 100 inclusive. What is the problem?
A. It rejects the boundary values 0 and 100 ✓
B. It is fine, because it accepts all marks
The code should use >= and <=. Boundary testing with 0 and 100 would catch this logic error.
4. AI code contains the line: total = math.sum_all(prices). You cannot find sum_all in Python's documentation. What is the most likely issue?
A. The AI made up a function that does not exist ✓
B. Your Python needs to be restarted to find it
AI tools sometimes invent functions or libraries. Check the official documentation. Here, sum(prices) is the real function.
5. Why is tracing AI-generated code with a trace table useful?
A. It makes the code run faster
B. It shows how variable values change and reveals logic errors ✓
A trace table lets you follow the code step by step by hand and compare each result with what you expect.

Match the Pairs

assert is_adult(18) == True → A test with your own boundary value: checks the AI function gives the right result at exactly the cut-off age
import easy_grader → A possible made-up library: check that it really exists before trusting the AI code that uses it
Trace the AI code by hand with sample values, recording each variable as the lines run → | i | total | | 1 | 5 |
Test AI code with invalid data to see if it copes with bad input → calculate_average("abc")
# AI code ran with no errors, so it is correct. Ship it! → Running without errors does not prove the code is correct. It can still give wrong results, so it needs tracing and testing with your own data.
if age > 18: # requirement: 18 or over → The AI code fails the requirement at the boundary: age 18 should be accepted, so it should use >= instead of >.

Key Term

Verify AI-generated code
Read and trace AI code, then test it with your own boundary and invalid data, and check it meets the requirements. It can look right but be wrong or use made-up functions.

Fill in the Blanks

1. assert grade(50) == "P"
Hint: Type the keyword that stops the program if a test condition is false.
2. assert valid(-1) is False
Hint: Type the Boolean value you expect when invalid test data is checked.
3. try: result = int("abc") except ValueError:
Hint: Type the exception name raised when invalid text cannot be converted to a number.
4. print(hasattr(str, "reverse"))
Hint: Type the built-in function that checks whether an object really has a named method, to catch made-up ones.
5. mark = 100 print(0 <= mark <= 100)
Hint: Type the variable that holds the boundary test value being checked against the requirement.

Spot the Error

Question 1
A def is_pass(mark):
B return mark > 50
C print(is_pass(50))
Line B — The requirement says a mark of 50 passes. Testing the boundary value 50 returns False with >, so the AI code is wrong. It should be >=.
Question 2
A import math
B r = math.squareroot(49)
C print(r)
Line B — math.squareroot() does not exist. AI tools can make up functions that look real. Check the documentation. The real function is math.sqrt().
Question 3
A def double(n):
B return n * 2
C assert double(4) == 6
Line C — The expected result must be worked out by hand from the requirement, not copied from the AI. Doubling 4 gives 8, so the test should expect 8.
Question 4
A from random import randdice
B roll = randint(1, 6)
C print(roll)
Line A — randdice is a made-up function that the random module does not have. The real function is randint, so check that imports exist before trusting AI code.
Question 5
A total = 0
B for n in [2, 4, 6]:
C total = n
D print(total)
Line C — Tracing shows total is overwritten each loop, so it ends at 6 instead of 12. To add up the values, the line should be total += n.

Student with a class code? Join your class →