Module 2 – Use types to describe valid data
Validation needs a policy, not just a type
Suppose an AI suggestion immediately converts every raw integer into Score. A value outside the subtype range can raise Constraint_Error. That check can expose a bug, but it is not a friendly explanation for a learner entering a score. Decide how your application should react: reject the value with a clear message, or ask for a corrected value. Do not silently replace 101 with 100 unless the requirements explicitly choose that policy.
Use a boundary table with values -1, 0, 1, 99, 100, and 101. Mark each as accepted or rejected before running. This is more useful than six random middle values because it examines both sides of each decision. A valid numeric value can still be the wrong score for the student, so type checks and real-world accuracy are different responsibilities.
Complete this lesson
Answer every check correctly to earn your lesson certificate. Feedback helps you review and try again.
Sign in · Save your progress and earn a certificate for this lesson.