Skip to content

Commit

Permalink
Want to have option to capitalize first letter of each word.
Browse files Browse the repository at this point in the history
  • Loading branch information
szaydel committed Apr 1, 2018
1 parent a8c2f97 commit 032d2f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/test_xkcdpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_set_case(self):
results["upper"] = xkcd_password.set_case(words, method="upper")
results["alternating"] = xkcd_password.set_case(words, method="alternating")
results["random"] = xkcd_password.set_case(words, method="random", testing=True)
results["first"] = xkcd_password.set_case(words, method="first")

words_after = set(word.lower() for group in list(results.values()) for word in group)

Expand All @@ -84,6 +85,7 @@ def test_set_case(self):
# Test that the words have been uppered or lowered respectively.
self.assertTrue(all(word.islower() for word in results["lower"]))
self.assertTrue(all(word.isupper() for word in results["upper"]))
self.assertTrue(all(word.istitle() for word in results["first"]))
# Test that the words have been correctly uppered randomly.
expected_random_result_1 = ['THIS', 'IS', 'ONLY', 'a', 'test']
expected_random_result_2 = ['THIS', 'IS', 'a', 'test', 'ALSO']
Expand Down
9 changes: 8 additions & 1 deletion xkcdpass/xkcd_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ def upper_case(words):
"""
return [w.upper() for w in words]

def first_upper_case(words):
"""
Set First character of each word to UPPER case.
"""
return [w.capitalize() for w in words]

def lower_case(words):
"""
Expand Down Expand Up @@ -268,7 +273,9 @@ def make_upper(word):
CASE_METHODS = {"alternating": alternating_case,
"upper": upper_case,
"lower": lower_case,
"random": random_case}
"random": random_case,
"first": first_upper_case,
}


def set_case(words, method="lower", testing=False):
Expand Down

0 comments on commit 032d2f8

Please sign in to comment.