Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDD practice #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Password.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Password.h"
#include <string>
#include <cctype>

using std::string;

Expand All @@ -19,11 +20,28 @@ int Password::count_leading_characters(string phrase){
return repetition;
}


/*
receives a string and returns whether it has both at least one upper-case
letter and at least one lower-case letter
*/
bool Password::has_mixed_case(string pass){
bool has_upper_case = false;
bool has_lower_case = false;

for(int i = 0; i < pass.size(); i++){
char ch = pass[i];
if (isupper(ch)){
has_upper_case = true;
}
if (islower(ch)){
has_lower_case = true;
}

if(has_lower_case && has_upper_case){
return true;
}

}

return false;
}
}
44 changes: 43 additions & 1 deletion PasswordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,46 @@ TEST(PasswordTest, single_letter_password)
Password my_password;
int actual = my_password.count_leading_characters("Z");
ASSERT_EQ(1, actual);
}
}

TEST(PasswordTest, all_lowercase_password) {
Password my_password;
bool actual = my_password.has_mixed_case("password");
ASSERT_EQ(false, actual); //Should return false since there are no uppercase letters
}

TEST(PasswordTest, all_uppercase_password) {
Password my_password;
bool actual = my_password.has_mixed_case("PASSWORD");
ASSERT_EQ(false, actual); //Should return false since there are no lowercase letters
}

TEST(PasswordTest, mixed_case_password) {
Password my_password;
bool actual = my_password.has_mixed_case("PassWord");
ASSERT_EQ(true, actual); //Should return true since both uppercase and lowercase letters are present
}

TEST(PasswordTest, single_lowercase_character) {
Password my_password;
bool actual = my_password.has_mixed_case("a");
ASSERT_EQ(false, actual); //Should return false since there is only one lowercase letter
}

TEST(PasswordTest, single_uppercase_character) {
Password my_password;
bool actual = my_password.has_mixed_case("A");
ASSERT_EQ(false, actual); //Should return false since there is only one uppercase letter
}

TEST(PasswordTest, empty_string) {
Password my_password;
bool actual = my_password.has_mixed_case("");
ASSERT_EQ(false, actual); //Should return false since the string is empty
}

TEST(PasswordTest, mixed_case_with_numbers_and_symbols) {
Password my_password;
bool actual = my_password.has_mixed_case("P@ssw0rd!");
ASSERT_EQ(true, actual); //Should return true since both uppercase and lowercase letters are present
}