From dfc003c33e96b7bdb4e187f8d1a77f350c84a198 Mon Sep 17 00:00:00 2001 From: Jaso Salgado Date: Tue, 16 Jun 2020 15:32:13 -0500 Subject: [PATCH] Challenge solved --- challenge.py | 78 +++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/challenge.py b/challenge.py index ffdfcce..c07c675 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 side * side + def rectangle_area(base, height): """Returns the area of a rectangle""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return base * height def triangle_area(base, height): """Returns the area of a triangle""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return (base * height)/2 def rhombus_area(diagonal_1, diagonal_2): """Returns the area of a rhombus""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return diagonal_1 * diagonal_2 def trapezoid_area(base_minor, base_major, height): """Returns the area of a trapezoid""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return (height * (base_major * base_minor))/2 def regular_polygon_area(perimeter, apothem): """Returns the area of a regular polygon""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return (perimeter * apothem)/2 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 round(math.pi * pow(radius, 2), 1) if __name__ == '__main__': @@ -57,32 +42,55 @@ def circumference_area(radius): class GeometrySuite(unittest.TestCase): def setUp(self): - # Initialize the needed values for the tests - pass + self.values = { + 'side':2, + 'base':2, + 'height':5, + 'diagonal_1':6, + 'diagonal_2':4, + 'base_major':6, + 'perimeter':12, + 'apothem':4, + 'radius':2, + } + def test_square_area(self): - # Make this test first... + self.assertEqual(4, square_area(self.values['side'])) + def test_rectangle_area(self): - # Make this test first... - + self.assertEqual(10, rectangle_area(self.values['base'], + self.values['height'])) + + def test_triangle_area(self): - # Make this test first... + self.assertEqual(5, triangle_area(self.values['base'], + self.values['height'])) + def test_rhombus_area(self): - # Make this test first... + self.assertEqual(24, rhombus_area(self.values['diagonal_1'], + self.values['diagonal_2'])) + def test_trapezoid_area(self): - # Make this test first... + self.assertEqual(30, trapezoid_area(self.values['base'], + self.values['base_major'], + self.values['height'])) + def test_regular_polygon_area(self): - # Make this test first... + self.assertEqual(24, regular_polygon_area(self.values['perimeter'], + self.values['apothem'])) + def test_circumference_area(self): - # Make this test first... + self.assertEqual(12.6, circumference_area(self.values['radius'])) + def tearDown(self): - # Delete the needed values for the tests - pass + del(self.values) + unittest.main()