From eaf12d6cd695e07d4b8786a76e88d2a94ae3f7c2 Mon Sep 17 00:00:00 2001 From: Cristhian Castillo Date: Thu, 21 May 2020 16:57:33 -0500 Subject: [PATCH 1/3] Added tests and setup --- challenge.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/challenge.py b/challenge.py index ffdfcce..03645b2 100644 --- a/challenge.py +++ b/challenge.py @@ -57,32 +57,49 @@ def circumference_area(radius): class GeometrySuite(unittest.TestCase): def setUp(self): - # Initialize the needed values for the tests - pass + self.values = { + 'side': 0, + 'base': 0, + 'height': 0, + 'diagonal_1': 0, + 'diagonal_2': 0, + 'base_minor': 0, + 'base_major': 0, + 'perimeter': 0, + 'apothem': 0, + 'radius': 0 + } def test_square_area(self): - # Make this test first... + """Test the function to find the area of a square with a side greater than zero""" + self.assertEqual(0, square_area(self.values['side'])) def test_rectangle_area(self): - # Make this test first... + """Test the function to find the area of a rectangle with height and base greater than zero""" + self.assertEqual(0, rectangle_area(self.values['base'], self.values['height'])) def test_triangle_area(self): - # Make this test first... + """Test the function to find the area of a triangle with height and base greater than zero""" + self.assertEqual(0, triangle_area(self.values['base'], self.values['height'])) def test_rhombus_area(self): - # Make this test first... + """Test the function to find the area of a rhombus with diagonals greater than zero""" + self.assertEqual(0, rhombus_area(self.values['diagonal_1'], self.values['diagonal_2'])) def test_trapezoid_area(self): - # Make this test first... + """Test the function to find the area of a rhombus with bases greater than zero and height greater than zero""" + self.assertEqual(0, trapezoid_area(self.values['base_minor'], self.values['base_major'], self.values['height'])) def test_regular_polygon_area(self): - # Make this test first... + """Test the function to find the area of a polygon with apothem and perimeter greater than zero""" + self.assertEqual(0, regular_polygon_area(self.values['perimeter'], self.values['apothem'])) + def test_circumference_area(self): - # Make this test first... + """Test the function to find the area of a circle with radius greater than zero""" + self.assertEqual(0, circumference_area(self.values['radius'])) def tearDown(self): - # Delete the needed values for the tests - pass + del(self.values) unittest.main() From 73a10407796e065147a1b2ce4bfa243786dcd49f Mon Sep 17 00:00:00 2001 From: Cristhian Castillo Date: Thu, 21 May 2020 17:12:28 -0500 Subject: [PATCH 2/3] Added values for tests and minimal implementation to pass them --- challenge.py | 69 ++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/challenge.py b/challenge.py index 03645b2..910dc09 100644 --- a/challenge.py +++ b/challenge.py @@ -3,52 +3,37 @@ def square_area(side): """Returns the area of a square""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return 4 def rectangle_area(base, height): """Returns the area of a rectangle""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return 12 def triangle_area(base, height): """Returns the area of a triangle""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return 6 def rhombus_area(diagonal_1, diagonal_2): """Returns the area of a rhombus""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return 17.5 def trapezoid_area(base_minor, base_major, height): """Returns the area of a trapezoid""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return 16 def regular_polygon_area(perimeter, apothem): """Returns the area of a regular polygon""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return 10 def circumference_area(radius): """Returns the area of a circumference""" - # You have to code here - # REMEMBER: Tests first!!! - # Use math.pi for π value - pass + return 9.424 if __name__ == '__main__': @@ -58,46 +43,50 @@ class GeometrySuite(unittest.TestCase): def setUp(self): self.values = { - 'side': 0, - 'base': 0, - 'height': 0, - 'diagonal_1': 0, - 'diagonal_2': 0, - 'base_minor': 0, - 'base_major': 0, - 'perimeter': 0, - 'apothem': 0, - 'radius': 0 + 'side': 2, + 'base': 3, + 'height': 4, + 'diagonal_1': 5, + 'diagonal_2': 7, + 'base_minor': 3, + 'base_major': 5, + 'perimeter': 4, + 'apothem': 5, + 'radius': 3 } def test_square_area(self): """Test the function to find the area of a square with a side greater than zero""" - self.assertEqual(0, square_area(self.values['side'])) + self.assertEqual(4, square_area(self.values['side'])) def test_rectangle_area(self): """Test the function to find the area of a rectangle with height and base greater than zero""" - self.assertEqual(0, rectangle_area(self.values['base'], self.values['height'])) + self.assertEqual(12, rectangle_area( + self.values['base'], self.values['height'])) def test_triangle_area(self): """Test the function to find the area of a triangle with height and base greater than zero""" - self.assertEqual(0, triangle_area(self.values['base'], self.values['height'])) + self.assertEqual(6, triangle_area( + self.values['base'], self.values['height'])) def test_rhombus_area(self): """Test the function to find the area of a rhombus with diagonals greater than zero""" - self.assertEqual(0, rhombus_area(self.values['diagonal_1'], self.values['diagonal_2'])) + self.assertEqual(17.5, rhombus_area( + self.values['diagonal_1'], self.values['diagonal_2'])) def test_trapezoid_area(self): """Test the function to find the area of a rhombus with bases greater than zero and height greater than zero""" - self.assertEqual(0, trapezoid_area(self.values['base_minor'], self.values['base_major'], self.values['height'])) + self.assertEqual(16, trapezoid_area( + self.values['base_minor'], self.values['base_major'], self.values['height'])) def test_regular_polygon_area(self): """Test the function to find the area of a polygon with apothem and perimeter greater than zero""" - self.assertEqual(0, regular_polygon_area(self.values['perimeter'], self.values['apothem'])) - + self.assertEqual(10, regular_polygon_area( + self.values['perimeter'], self.values['apothem'])) def test_circumference_area(self): """Test the function to find the area of a circle with radius greater than zero""" - self.assertEqual(0, circumference_area(self.values['radius'])) + self.assertEqual(9.424, circumference_area(self.values['radius'])) def tearDown(self): del(self.values) From ef14f33811c50469192ce86218cdc019911b019b Mon Sep 17 00:00:00 2001 From: Cristhian Castillo Date: Thu, 21 May 2020 17:20:56 -0500 Subject: [PATCH 3/3] Added method implementation and solved the challenge using tdd --- challenge.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/challenge.py b/challenge.py index 910dc09..be0f297 100644 --- a/challenge.py +++ b/challenge.py @@ -3,37 +3,37 @@ def square_area(side): """Returns the area of a square""" - return 4 + return side**2 def rectangle_area(base, height): """Returns the area of a rectangle""" - return 12 + return (base * height) def triangle_area(base, height): """Returns the area of a triangle""" - return 6 + return (base * height) / 2 def rhombus_area(diagonal_1, diagonal_2): """Returns the area of a rhombus""" - return 17.5 + return (diagonal_1 * diagonal_2) / 2 def trapezoid_area(base_minor, base_major, height): """Returns the area of a trapezoid""" - return 16 + return ((base_major + base_minor) / 2 ) * height def regular_polygon_area(perimeter, apothem): """Returns the area of a regular polygon""" - return 10 + return (perimeter * apothem) / 2 def circumference_area(radius): """Returns the area of a circumference""" - return 9.424 + return float('%.3f'%(radius * math.pi)) if __name__ == '__main__': @@ -86,7 +86,7 @@ def test_regular_polygon_area(self): def test_circumference_area(self): """Test the function to find the area of a circle with radius greater than zero""" - self.assertEqual(9.424, circumference_area(self.values['radius'])) + self.assertEqual(9.425, circumference_area(self.values['radius'])) def tearDown(self): del(self.values)