From b354ed47f1867c889d56338bc5f80f22e947ad37 Mon Sep 17 00:00:00 2001 From: roostAI <108646238+roostAI@users.noreply.github.com> Date: Thu, 21 Sep 2023 07:23:25 +0000 Subject: [PATCH] Test generated by RoostGPT for test PythonUnitTest using AI Type Open AI and AI Model gpt-4 --- .../test_Choose_random_word_dfc5b1b036.py | 23 +++++++ .../test_Display_word_326f97541e.py | 32 +++++++++ .../test_Guess_the_word_c33d1e7d06.py | 67 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 Guess the Word Game/test_Choose_random_word_dfc5b1b036.py create mode 100644 Guess the Word Game/test_Display_word_326f97541e.py create mode 100644 Guess the Word Game/test_Guess_the_word_c33d1e7d06.py diff --git a/Guess the Word Game/test_Choose_random_word_dfc5b1b036.py b/Guess the Word Game/test_Choose_random_word_dfc5b1b036.py new file mode 100644 index 0000000000..47cf606961 --- /dev/null +++ b/Guess the Word Game/test_Choose_random_word_dfc5b1b036.py @@ -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() diff --git a/Guess the Word Game/test_Display_word_326f97541e.py b/Guess the Word Game/test_Display_word_326f97541e.py new file mode 100644 index 0000000000..91070d9ccd --- /dev/null +++ b/Guess the Word Game/test_Display_word_326f97541e.py @@ -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() diff --git a/Guess the Word Game/test_Guess_the_word_c33d1e7d06.py b/Guess the Word Game/test_Guess_the_word_c33d1e7d06.py new file mode 100644 index 0000000000..323127e1fe --- /dev/null +++ b/Guess the Word Game/test_Guess_the_word_c33d1e7d06.py @@ -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()