def test_secret_word_no_repeat(): with open("/tmp/words.txt","w") as f: for i in ["disaster","recall","advise","national","infrastructure","shots","fired","federation","duress"]: f.write(i+"\n") l = [] for i in range(3): l.append(get_secret_word('/tmp/words.txt')) assert len(set(l)) == 3
def test_secret_word_lowercase(): with open("/tmp/words.txt","w") as f: for i in ["Wording","wOrding","WORDING","wording"]: f.write(i+"\n") selected_word = get_secret_word('/tmp/words.txt') assert selected_word == "wording"
def test_secret_word_no_punctuation(): with open ("/tmp/words.txt","w") as f: for i in ["word'one", "word_two", "wordthree"]: f.write(i+"\n") selected_word = get_secret_word('/tmp/words.txt') assert selected_word == "wordthree"
def test_secret_word_atleast_five(): with open("/tmp/words.txt","w") as f: for i in ["wo", "wor", "word", "bigword"]: f.write(i+"\n") selected_word = get_secret_word('/tmp/words.txt') assert selected_word == "bigword"
def test_secret_word_6_letters(): assert all(hangman.get_secret_word("./test_data/1.words") == "policeman" for _ in range(100))
def test_secret_word_no_proper_nouns(): assert all(hangman.get_secret_word("./test_data/3.words") == "policeman" for _ in range(100))
def test_secret_word_no_punctuation(): assert all(hangman.get_secret_word("./test_data/2.words") == "fireman" for _ in range(100))
def test_select_secret_word(): word = hangman.get_secret_word() assert len(word) >= 6, "{} is less than 6 letters long".format(word) assert word.islower(), "{} is not all lower".format(word) assert word.isalpha(), "{} is not all alphabetical".format(word)
def test_select_multiple_secret_words(): words = set() for i in range(10): words.add(hangman.get_secret_word()) assert len(words) == 10