Skip to content
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
23 changes: 23 additions & 0 deletions Guess the Word Game/test_Choose_random_word_dfc5b1b036.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Test generated by RoostGPT for test PythonUnitTest using AI Type Open AI and AI Model gpt-4

import unittest
import random

def choose_random_word():
words = ["apple", "banana", "cherry", "grape",
"orange", "watermelon", "kiwi", "mango"]
return random.choice(words)

class TestChoose_random_word_dfc5b1b036(unittest.TestCase):

def test_choose_random_word(self):
word = choose_random_word()
self.assertIn(word, ["apple", "banana", "cherry", "grape",
"orange", "watermelon", "kiwi", "mango"])

def test_choose_random_word_failure(self):
word = choose_random_word()
self.assertNotIn(word, ["pineapple", "strawberry", "blueberry"])

if __name__ == '__main__':
unittest.main()
32 changes: 32 additions & 0 deletions Guess the Word Game/test_Display_word_326f97541e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Test generated by RoostGPT for test PythonUnitTest using AI Type Open AI and AI Model gpt-4

import unittest

def display_word(word, guessed_letters):
display = ""
for letter in word:
if letter in guessed_letters:
display += letter
else:
display += "_"
return display

class TestDisplayWord(unittest.TestCase):
def test_display_word_success(self):
result = display_word("apple", ["a", "p"])
self.assertEqual(result, "app__")

def test_display_word_failure(self):
result = display_word("apple", ["b", "c"])
self.assertEqual(result, "_____")

def test_display_word_edge_case(self):
result = display_word("", ["a", "p"])
self.assertEqual(result, "")

def test_display_word_error_handling(self):
with self.assertRaises(TypeError):
display_word("apple", 123)

if __name__ == '__main__':
unittest.main()
67 changes: 67 additions & 0 deletions Guess the Word Game/test_Guess_the_word_c33d1e7d06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import unittest
from unittest.mock import patch
from io import StringIO
import random

def choose_random_word():
words = ["python", "java", "ruby", "javascript"]
return random.choice(words)

def display_word(word, guessed_letters):
return ''.join([letter if letter in guessed_letters else '_' for letter in word])

def guess_the_word():
print("Welcome to Guess the Word game!")
secret_word = choose_random_word()
guessed_letters = []
attempts = 6

while attempts > 0:
print(f"\nWord: {display_word(secret_word, guessed_letters)}")
print(f"Attempts left: {attempts}")
guess = input("Guess a letter: ").lower()

if len(guess) != 1 or not guess.isalpha():
print("Invalid input. Please enter a single letter.")
continue

if guess in guessed_letters:
print("You already guessed that letter.")
continue

guessed_letters.append(guess)

if guess in secret_word:
if set(guessed_letters) == set(secret_word):
print("Congratulations! You guessed the word!")
print(f"The word was: {secret_word}")
return True
else:
print("Correct guess!")
else:
attempts -= 1
print("Incorrect guess!")

else:
print("Game over! You ran out of attempts.")
print(f"The word was: {secret_word}")
return False

class TestGuessTheWord(unittest.TestCase):

@patch('builtins.input', side_effect=['p', 'y', 't', 'h', 'o', 'n'])
@patch('sys.stdout', new_callable=StringIO)
def test_guess_the_word_success(self, mock_stdout, mock_input):
random.seed(0)
self.assertTrue(guess_the_word())
self.assertIn("Congratulations! You guessed the word!", mock_stdout.getvalue())

@patch('builtins.input', side_effect=['a', 'b', 'c', 'd', 'e', 'f'])
@patch('sys.stdout', new_callable=StringIO)
def test_guess_the_word_failure(self, mock_stdout, mock_input):
random.seed(0)
self.assertFalse(guess_the_word())
self.assertIn("Game over! You ran out of attempts.", mock_stdout.getvalue())

if __name__ == "__main__":
unittest.main()