Designing an algorithm – example two
Algorithm design option one - flow diagram
Algorithm design option two - pseudocode
#set error flag to True to enable loop
error = True #iterate until a valid password is entered
while error == True #set all variables to default values error = False lowerCase = 0 upperCase = 0 number = 0 #input the password password = input ("Type in a password of at least 5 characters including 1 l/c letters, 1 u/c, 1 number: ") #check password length - error if not at least 5 characters if len(password)< 5 then error = True endif #if the password is the right length then #inspect each character in the password #add 1 to the number of uppercase for each uppercase character #add 1 to the number of lowercase for each lowercase character #add 1 to the number of numbers for each number if error == False then for position in range(0,len(password)) if password[position] >="A" and password[position] < ="Z" then upperCase += 1 elseif password[position] >="a" and password[position]< ="z" then lowerCase += 1 elseif password[position] >="0" and password[position]< ="9" then number += 1 next position endif #if character requirements are not met, an error has occured if upperCase < 1 or lowerCase < 1 or number < 1 then error = True endif #output acceptance
print("Password accepted: ",password)Testing table
Tests will be required to test that the final program runs correctly.
| Test no | Description | Test data | Test type | Expected outcome |
| 1 | Enter a valid password | Abcd36 | Valid | Password should be accepted |
| 2 | Enter a ten-character password | ABcd457Anz | Valid | Password should be accepted |
| 3 | Enter a five-character password | Abc67 | Extreme | Password should be accepted |
| 4 | Password has at least one lowercase character | ABCd57 | Extreme | Password should be accepted |
| 5 | Password has at least one number | ABcd36 | Extreme | Password should be accepted |
| 6 | Password has at least one uppercase character | Abcd45 | Extreme | Password should be accepted |
| 7 | Password is too short | Abc5 | Invalid | Password must be re-entered |
| 8 | Password does not contain at least one uppercase character | abcd5 | Invalid | Password must be re-entered |
| 9 | Password does not contain at least one lowercase character | ABCD8 | Invalid | Password must be re-entered |
| 10 | Password does not contain at least one number | ABcde | Invalid | Password must be re-entered |
| Test no | 1 |
|---|---|
| Description | Enter a valid password |
| Test data | Abcd36 |
| Test type | Valid |
| Expected outcome | Password should be accepted |
| Test no | 2 |
|---|---|
| Description | Enter a ten-character password |
| Test data | ABcd457Anz |
| Test type | Valid |
| Expected outcome | Password should be accepted |
| Test no | 3 |
|---|---|
| Description | Enter a five-character password |
| Test data | Abc67 |
| Test type | Extreme |
| Expected outcome | Password should be accepted |
| Test no | 4 |
|---|---|
| Description | Password has at least one lowercase character |
| Test data | ABCd57 |
| Test type | Extreme |
| Expected outcome | Password should be accepted |
| Test no | 5 |
|---|---|
| Description | Password has at least one number |
| Test data | ABcd36 |
| Test type | Extreme |
| Expected outcome | Password should be accepted |
| Test no | 6 |
|---|---|
| Description | Password has at least one uppercase character |
| Test data | Abcd45 |
| Test type | Extreme |
| Expected outcome | Password should be accepted |
| Test no | 7 |
|---|---|
| Description | Password is too short |
| Test data | Abc5 |
| Test type | Invalid |
| Expected outcome | Password must be re-entered |
| Test no | 8 |
|---|---|
| Description | Password does not contain at least one uppercase character |
| Test data | abcd5 |
| Test type | Invalid |
| Expected outcome | Password must be re-entered |
| Test no | 9 |
|---|---|
| Description | Password does not contain at least one lowercase character |
| Test data | ABCD8 |
| Test type | Invalid |
| Expected outcome | Password must be re-entered |
| Test no | 10 |
|---|---|
| Description | Password does not contain at least one number |
| Test data | ABcde |
| Test type | Invalid |
| Expected outcome | Password must be re-entered |
The problem has now been fully decomposed and an algorithm has been designed.