Skip to content

Commit

Permalink
improvements to test_random_delimiter
Browse files Browse the repository at this point in the history
check both expected string length and expected number of delimiters
  • Loading branch information
Steven Tobin committed Nov 20, 2023
1 parent 4044ab2 commit 90a717c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions tests/test_xkcdpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,21 @@ def test_delim(self):
self.assertIsNotNone(re.match('([a-z]+(_|$))+', result))

def test_random_delimiter(self):
wordlist = xkcd_password.generate_wordlist(WORDFILE, min_length=3, max_length=3)
result = xkcd_password.generate_xkcdpassword(wordlist, numwords=3, random_delimiters=True)
# result can be length 9, 10, or 11 depending on which random delimiters are chose
self.assertTrue(len(result) in {9, 10, 11})
wordlength = 4
numwords = 3
wordlist = xkcd_password.generate_wordlist(
WORDFILE, min_length=wordlength, max_length=wordlength
)
result = xkcd_password.generate_xkcdpassword(
wordlist, numwords=numwords, random_delimiters=True
)
# check that the result is the right length
self.assertEquals(len(result), numwords * wordlength + (numwords - 1))
# check we have the right number of delimiters
self.assertEqual(
len([x for x in result if x in set(xkcd_password.DEFAULT_DELIMITERS)]),
numwords - 1
)

def test_set_case(self):
words = "this is only a GREAT Test".lower().split()
Expand Down

0 comments on commit 90a717c

Please sign in to comment.