Testing CS Thinking Example 3
Follow the full solution, then compare it with the other examples linked below.
Example 3
mediumA password validation function requires: at least 8 characters, at least one uppercase letter, and at least one digit. Design test cases that check each requirement independently.
Solution
- 1 Step 1: Valid: 'Passw0rd' (meets all). Too short: 'Pa1' (fails length). No uppercase: 'password1' (fails uppercase). No digit: 'Password' (fails digit).
- 2 Step 2: Boundary: 'Passwor1' (exactly 8 chars โ should pass). Each test isolates one requirement to identify exactly which check fails.
Answer
Test each requirement separately: valid, too short, no uppercase, no digit, exactly 8 characters.
Isolating test cases to check one requirement each makes it easy to locate bugs. If a test fails, you know exactly which validation rule has the problem.
About Testing
Systematically running a program with known inputs to verify that its outputs are correct. Testing involves designing test cases that cover normal inputs, boundary values, and error conditions, then comparing actual results against expected results.
Learn more about Testing โMore Testing Examples
Example 1 easy
A function isEven(n) should return TRUE if n is even and FALSE otherwise. Suggest three test cases,
Example 2 mediumA program grades students: 90-100 = A, 80-89 = B, 70-79 = C, 60-69 = D, below 60 = F. Design a compl
Example 4 hardExplain the difference between white-box and black-box testing. Which approach would you use to test