From 9d85d3a4c4373189aaefccae3fd5433f91050d10 Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:35:14 -0500 Subject: [PATCH 1/8] clarify "no function calls" item --- .github/PULL_REQUEST_TEMPLATE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6e269b4ad..eb18b4638 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -55,7 +55,8 @@ about: A template PR for code review with a checklist - [ ] The function's name describes it's behavior - [ ] The function's name matches the file name - [ ] The function has correct type annotations -- [ ] The function is not called in the function file +- [ ] The function is not called at the top level of the function file + - _Recursive solutions **can** call the function from **inside** the function body_ ## Strategy From 50a35d279bd92d18a2886bf55d9c483e8aa859b7 Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:18:33 -0500 Subject: [PATCH 2/8] checklist updates post-Q&A --- .github/PULL_REQUEST_TEMPLATE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index eb18b4638..eba8a7be2 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -54,6 +54,7 @@ about: A template PR for code review with a checklist - [ ] The function's name describes it's behavior - [ ] The function's name matches the file name + - _It's ok to have extra helper functions if necessary, like with mergesort_ - [ ] The function has correct type annotations - [ ] The function is not called at the top level of the function file - _Recursive solutions **can** call the function from **inside** the function body_ @@ -68,7 +69,7 @@ about: A template PR for code review with a checklist ### Don'ts -- [ ] The function's strategy _is not_ described in the documentation +- [ ] The function's strategy _is not_ described in any docstrings or tests - [ ] Comments explain the _strategy_, **not** the _implementation_ - [ ] The function _does not_ have more comments than code - If it does, consider finding a new strategy or a simpler implementation From d9989b60673f84fbd863dfbc3a08a0a16a9c7874 Mon Sep 17 00:00:00 2001 From: "F. Ismail SAHIN" <114308096+fevziismailsahin@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:58:48 -0700 Subject: [PATCH 3/8] pine_tree_art --- solutions/pine_tree_art.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/pine_tree_art.py diff --git a/solutions/pine_tree_art.py b/solutions/pine_tree_art.py new file mode 100644 index 000000000..6b17fe11a --- /dev/null +++ b/solutions/pine_tree_art.py @@ -0,0 +1,18 @@ +def draw_tree(): + tree = [] + height = 10 + for i in range(height): + spaces = ' ' * (height - i - 1) + stars = '*' * (2 * i + 1) + tree.append(spaces + stars + spaces) + + trunk_width = 3 + trunk_height = 3 + trunk = ' ' * (height - 2) + '|' * trunk_width + + for _ in range(trunk_height): + tree.append(trunk) + + return '\n'.join(tree) + +print(draw_tree()) \ No newline at end of file From 54bb4063640f843244618c57e7af886a57fd4cdb Mon Sep 17 00:00:00 2001 From: fevziismailsahin Date: Thu, 9 Jan 2025 16:24:19 -0700 Subject: [PATCH 4/8] update pine tree art generation function --- solutions/pine_tree_art.py | 54 +++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/solutions/pine_tree_art.py b/solutions/pine_tree_art.py index 6b17fe11a..030419ec2 100644 --- a/solutions/pine_tree_art.py +++ b/solutions/pine_tree_art.py @@ -1,18 +1,48 @@ -def draw_tree(): +""" +Module for generating and displaying ASCII art of a pine tree. + +This module provides a function to create a visual representation of a pine tree +with a customizable height and trunk dimensions. + +Author: fevziismailsahin +Created: 01/09/2025 +""" + + +def draw_tree(height: int = 10, trunk_width: int = 3, trunk_height: int = 3) -> str: + """ + Generate an ASCII art representation of a pine tree. + + Parameters: + height (int): The height of the tree (default is 10). + trunk_width (int): The width of the tree trunk (default is 3). + trunk_height (int): The height of the tree trunk (default is 3). + + Returns: + str: The generated ASCII art as a string. + + Example: + >>> print(draw_tree(height=5, trunk_width=3, trunk_height=2)) + * + *** + ***** + ******* + ********* + ||| + ||| + """ tree = [] - height = 10 for i in range(height): - spaces = ' ' * (height - i - 1) - stars = '*' * (2 * i + 1) + spaces = " " * (height - i - 1) + stars = "*" * (2 * i + 1) tree.append(spaces + stars + spaces) - - trunk_width = 3 - trunk_height = 3 - trunk = ' ' * (height - 2) + '|' * trunk_width - + + trunk = " " * (height - trunk_width // 2 - 1) + "|" * trunk_width for _ in range(trunk_height): tree.append(trunk) - - return '\n'.join(tree) -print(draw_tree()) \ No newline at end of file + return "\n".join(tree) + + +if __name__ == "__main__": + print(draw_tree()) From 78b039ede064bf0c2b0765a6613ad6518e9757f4 Mon Sep 17 00:00:00 2001 From: fevziismailsahin Date: Sat, 11 Jan 2025 15:03:07 -0700 Subject: [PATCH 5/8] Update pine_tree_art.py --- solutions/pine_tree_art.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/solutions/pine_tree_art.py b/solutions/pine_tree_art.py index 030419ec2..b2befacc2 100644 --- a/solutions/pine_tree_art.py +++ b/solutions/pine_tree_art.py @@ -31,16 +31,19 @@ def draw_tree(height: int = 10, trunk_width: int = 3, trunk_height: int = 3) -> ||| ||| """ + # Create the foliage of the tree tree = [] for i in range(height): - spaces = " " * (height - i - 1) - stars = "*" * (2 * i + 1) + spaces = " " * (height - i - 1) # Add spaces for alignment + stars = "*" * (2 * i + 1) # Create the stars for the current level tree.append(spaces + stars + spaces) + # Create the trunk of the tree trunk = " " * (height - trunk_width // 2 - 1) + "|" * trunk_width for _ in range(trunk_height): tree.append(trunk) + # Return the tree as a single string return "\n".join(tree) From 1b1eb7757c62f758c0da3b56a3bc739b121cff71 Mon Sep 17 00:00:00 2001 From: fevziismailsahin Date: Sat, 11 Jan 2025 16:49:57 -0700 Subject: [PATCH 6/8] update draw_tree --- solutions/pine_tree_art.py | 16 +++-- solutions/tests/test_pine_tree_art.py | 84 +++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 solutions/tests/test_pine_tree_art.py diff --git a/solutions/pine_tree_art.py b/solutions/pine_tree_art.py index b2befacc2..fcf5f1e08 100644 --- a/solutions/pine_tree_art.py +++ b/solutions/pine_tree_art.py @@ -2,7 +2,7 @@ Module for generating and displaying ASCII art of a pine tree. This module provides a function to create a visual representation of a pine tree -with a customizable height and trunk dimensions. +with customizable height and trunk dimensions. Author: fevziismailsahin Created: 01/09/2025 @@ -31,15 +31,23 @@ def draw_tree(height: int = 10, trunk_width: int = 3, trunk_height: int = 3) -> ||| ||| """ + # Defensive assertions + if height <= 0: + raise ValueError("Height must be a positive integer") + if trunk_width <= 0: + raise ValueError("Trunk width must be a positive integer") + if trunk_height <= 0: + raise ValueError("Trunk height must be a positive integer") + # Create the foliage of the tree tree = [] for i in range(height): - spaces = " " * (height - i - 1) # Add spaces for alignment + spaces = " " * (height - i - 1) # Add spaces for alignment (center the stars) stars = "*" * (2 * i + 1) # Create the stars for the current level - tree.append(spaces + stars + spaces) + tree.append(spaces + stars) # Append to tree list with correct alignment # Create the trunk of the tree - trunk = " " * (height - trunk_width // 2 - 1) + "|" * trunk_width + trunk = " " * (height - trunk_width // 2 - 1) + "|" * trunk_width # Centered trunk for _ in range(trunk_height): tree.append(trunk) diff --git a/solutions/tests/test_pine_tree_art.py b/solutions/tests/test_pine_tree_art.py new file mode 100644 index 000000000..2703684ac --- /dev/null +++ b/solutions/tests/test_pine_tree_art.py @@ -0,0 +1,84 @@ +"""Test module for pine_tree_art. + +@author: fevziismailsahin +@created: 01/10/2025 +""" + +import unittest + +from ..pine_tree_art import draw_tree + + +class TestDrawTree(unittest.TestCase): + """ + Test class to verify the functionality of the draw_tree function. + """ + + maxDiff = None # To see the full difference in case of failure + + def test_default_tree(self): + """ + Test case for the default tree with default parameters. + """ + expected_result = """ * + *** + ***** + ******* + ********* + *********** + ************* + *************** + ***************** + ******************* +********************* + ||| + |||""" + + result = draw_tree() + self.assertEqual(result, expected_result) + + def test_tree_with_large_height(self): + """ + Test case for a tree with a large height of 15. + """ + expected_result = """ * + *** + ***** + ******* + ********* + *********** + ************* + *************** + ***************** + ******************* + ********************* + *********************** + ************************* + *************************** + ***************************** + ******************************* +********************************* + ||| + |||""" + + result = draw_tree(15) + self.assertEqual(result, expected_result) + + def test_tree_with_narrow_trunk(self): + """ + Test case for a tree with a narrow trunk width of 1. + """ + expected_result = """ * + *** + ***** + ******* +********* + | + |""" + + result = draw_tree(5, 1, 2) + self.assertEqual(result, expected_result) + + +if __name__ == "__main__": + unittest.main() From a990dcae8618ae590d7c841eae3fda8b89e5531d Mon Sep 17 00:00:00 2001 From: fevziismailsahin Date: Sun, 12 Jan 2025 16:19:33 -0700 Subject: [PATCH 7/8] solved bug test_pine_tree.py --- solutions/pine_tree_art.py | 28 ++--- solutions/tests/test_pine_tree_art.py | 150 +++++++++++++------------- 2 files changed, 89 insertions(+), 89 deletions(-) diff --git a/solutions/pine_tree_art.py b/solutions/pine_tree_art.py index fcf5f1e08..cc61ae1eb 100644 --- a/solutions/pine_tree_art.py +++ b/solutions/pine_tree_art.py @@ -9,7 +9,7 @@ """ -def draw_tree(height: int = 10, trunk_width: int = 3, trunk_height: int = 3) -> str: +def pine_tree_art(height: int = 10, trunk_width: int = 3, trunk_height: int = 3) -> str: """ Generate an ASCII art representation of a pine tree. @@ -20,17 +20,16 @@ def draw_tree(height: int = 10, trunk_width: int = 3, trunk_height: int = 3) -> Returns: str: The generated ASCII art as a string. - - Example: - >>> print(draw_tree(height=5, trunk_width=3, trunk_height=2)) - * - *** - ***** - ******* - ********* - ||| - ||| """ + + # Type checks + if ( + not isinstance(height, int) + or not isinstance(trunk_width, int) + or not isinstance(trunk_height, int) + ): + raise TypeError("Height, trunk_width, and trunk_height must be integers") + # Defensive assertions if height <= 0: raise ValueError("Height must be a positive integer") @@ -51,9 +50,10 @@ def draw_tree(height: int = 10, trunk_width: int = 3, trunk_height: int = 3) -> for _ in range(trunk_height): tree.append(trunk) - # Return the tree as a single string - return "\n".join(tree) + # Return the tree as a single string with an extra newline at the end + return "\n".join(tree) + "\n" +# Example usage if __name__ == "__main__": - print(draw_tree()) + print(pine_tree_art()) diff --git a/solutions/tests/test_pine_tree_art.py b/solutions/tests/test_pine_tree_art.py index 2703684ac..cc91aee1d 100644 --- a/solutions/tests/test_pine_tree_art.py +++ b/solutions/tests/test_pine_tree_art.py @@ -1,83 +1,83 @@ -"""Test module for pine_tree_art. +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit test module for generating ASCII art of a pine tree. + +Test categories: + - Standard cases: correct inputs for height, trunk_width, trunk_height; + - Edge cases; + - Defensive tests: wrong input types, assertions; -@author: fevziismailsahin -@created: 01/10/2025 +Created on 2025-01-11 +Author: fevziismailsahin """ import unittest -from ..pine_tree_art import draw_tree - - -class TestDrawTree(unittest.TestCase): - """ - Test class to verify the functionality of the draw_tree function. - """ - - maxDiff = None # To see the full difference in case of failure - - def test_default_tree(self): - """ - Test case for the default tree with default parameters. - """ - expected_result = """ * - *** - ***** - ******* - ********* - *********** - ************* - *************** - ***************** - ******************* -********************* - ||| - |||""" - - result = draw_tree() - self.assertEqual(result, expected_result) - - def test_tree_with_large_height(self): - """ - Test case for a tree with a large height of 15. - """ - expected_result = """ * - *** - ***** - ******* - ********* - *********** - ************* - *************** - ***************** - ******************* - ********************* - *********************** - ************************* - *************************** - ***************************** - ******************************* -********************************* - ||| - |||""" - - result = draw_tree(15) - self.assertEqual(result, expected_result) - - def test_tree_with_narrow_trunk(self): - """ - Test case for a tree with a narrow trunk width of 1. - """ - expected_result = """ * - *** - ***** - ******* -********* - | - |""" - - result = draw_tree(5, 1, 2) - self.assertEqual(result, expected_result) +from ..pine_tree_art import pine_tree_art + + +class TestPineTreeArt(unittest.TestCase): + """Test suite for generating ASCII art of a pine tree.""" + + # Standard cases: correct inputs + def test_standard_case_1(self): + """Test with typical valid inputs for height, trunk_width, trunk_height.""" + expected_result = ( + " *\n" + " ***\n" + " *****\n" + " *******\n" + " *********\n" + " ***********\n" + " *************\n" + " ***************\n" + " *****************\n" + "*******************\n" + " |||\n" + " |||\n" + " |||\n" + ) + self.assertEqual(pine_tree_art(10, 3, 3), expected_result) + + def test_standard_case_2(self): + """Test with smaller tree height and trunk dimensions.""" + expected_result = ( + " *\n ***\n *****\n *******\n*********\n |||\n |||\n |||\n" + ) + self.assertEqual(pine_tree_art(5, 3, 3), expected_result) + + # Edge cases: testing zero or near-zero values + def test_zero_height(self): + """Test when height is zero, which should raise a ValueError.""" + with self.assertRaises(ValueError): + pine_tree_art(0, 3, 3) + + def test_zero_trunk_width(self): + """Test when trunk width is zero, which should raise a ValueError.""" + with self.assertRaises(ValueError): + pine_tree_art(10, 0, 3) + + def test_zero_trunk_height(self): + """Test when trunk height is zero, which should raise a ValueError.""" + with self.assertRaises(ValueError): + pine_tree_art(10, 3, 0) + + # Defensive tests: wrong input types, assertions + def test_invalid_height_type(self): + """Test when 'height' is not an integer, which should raise a TypeError.""" + with self.assertRaises(TypeError): + pine_tree_art("ten", 3, 3) + + def test_invalid_trunk_width_type(self): + """Test when 'trunk_width' is not an integer, which should raise a TypeError.""" + with self.assertRaises(TypeError): + pine_tree_art(10, "three", 3) + + def test_invalid_trunk_height_type(self): + """Test when 'trunk_height' is not an integer, which should raise a TypeError.""" + with self.assertRaises(TypeError): + pine_tree_art(10, 3, "three") if __name__ == "__main__": From 5d1415d0d5dc327faf918a84cfbf163895986a6c Mon Sep 17 00:00:00 2001 From: fevziismailsahin Date: Sun, 12 Jan 2025 16:23:14 -0700 Subject: [PATCH 8/8] pine_tree_art.py update --- solutions/pine_tree_art.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/solutions/pine_tree_art.py b/solutions/pine_tree_art.py index cc61ae1eb..8bf95f0f2 100644 --- a/solutions/pine_tree_art.py +++ b/solutions/pine_tree_art.py @@ -52,8 +52,3 @@ def pine_tree_art(height: int = 10, trunk_width: int = 3, trunk_height: int = 3) # Return the tree as a single string with an extra newline at the end return "\n".join(tree) + "\n" - - -# Example usage -if __name__ == "__main__": - print(pine_tree_art())