Question: Write 4 different Unit Tests for this c++ method using assert functions with visual studio. /* This function checks the strength of a password: A

Write 4 different Unit Tests for this c++ method using assert functions with visual studio.

/* This function checks the strength of a password: A password should have following properties: It contains at least one lowercase English character. It contains at least one uppercase English character. It contains at least one special character. The special characters are: !@#$%^&*()-+ Its length is at least 8. It contains at least one digit.

Let a strong password is one that satisfies all above conditions. A moderate password is one that satisfies first three conditions and has length at least 6. Otherwise password is weak. function returns 2 if password is strong. function returns 1 if password is moderate. function returns 0 if password is weak. */ int getStrongNess(string& input) { int n = input.length();

// Checking lower alphabet in string bool hasLower = false, hasUpper = false; bool hasDigit = false, specialChar = false; string normalChars = "abcdefghijklmnopqrstu" "vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ";

for (int i = 0; i < n; i++) { if (islower(input[i])) hasLower = true; if (isupper(input[i])) hasUpper = true; if (isdigit(input[i])) hasDigit = true;

size_t special = input.find_first_not_of(normalChars); if (special != string::npos) specialChar = true; }

if (hasLower && hasUpper && hasDigit && specialChar && (n >= 8)) return 2; else if ((hasLower || hasUpper) && specialChar && (n >= 6)) return 1; else return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!