From bb0e5790ceaecc212924dfd9191ac63096d2c342 Mon Sep 17 00:00:00 2001 From: SantiagoDuque1700 Date: Wed, 17 Jun 2020 12:16:09 -0500 Subject: [PATCH] Finalizado --- challenge.py | 102 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 33 deletions(-) diff --git a/challenge.py b/challenge.py index ffdfcce..bfbbfff 100644 --- a/challenge.py +++ b/challenge.py @@ -3,52 +3,36 @@ 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) / 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 ((base_major + base_minor) * height) / 2 def regular_polygon_area(perimeter, apothem): """Returns the area of a regular polygon""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return round((perimeter * apothem) / 2, 1) 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,2) * (radius**2) if __name__ == '__main__': @@ -58,31 +42,83 @@ class GeometrySuite(unittest.TestCase): def setUp(self): # Initialize the needed values for the tests - pass + self.operations = { + 'square': { + 'side': 5, + 'result': 25 + }, + 'rectangle': { + 'base': 10, + 'height': 5, + 'result': 50 + }, + 'triangle': { + 'base': 5, + 'height': 10, + 'result': 25 + }, + 'rhombus': { + 'diagonal_1': 36, + 'diagonal_2': 24, + 'result': 432 + }, + 'trapezoid': { + 'base_minor': 7, + 'base_major': 13, + 'height': 6, + 'result': 60 + }, + 'regular_polygon': { + 'perimeter': 30, + 'apothem': 4.1, + 'result': 61.5 + }, + 'circumference': { + 'radius': 10, + 'result': 314 + } + } + def test_square_area(self): - # Make this test first... + square = self.operations['square'] + + self.assertEqual(square['result'], square_area(square['side'])) + def test_rectangle_area(self): - # Make this test first... + rectangle = self.operations['rectangle'] + + self.assertEqual(rectangle['result'], rectangle_area(rectangle['base'], rectangle['height'])) + def test_triangle_area(self): - # Make this test first... + triangle = self.operations['triangle'] + + self.assertEqual(triangle['result'],triangle_area(triangle['base'], triangle['height'])) + def test_rhombus_area(self): - # Make this test first... + rhombus = self.operations['rhombus'] + + self.assertEqual(rhombus['result'], rhombus_area(rhombus['diagonal_1'], rhombus['diagonal_2'])) def test_trapezoid_area(self): - # Make this test first... + trapezoid = self.operations['trapezoid'] + + self.assertEqual(trapezoid['result'], trapezoid_area(trapezoid['base_minor'], trapezoid['base_major'], trapezoid['height'])) def test_regular_polygon_area(self): - # Make this test first... + regular_polygon = self.operations['regular_polygon'] + + self.assertEqual(regular_polygon['result'], regular_polygon_area(regular_polygon['perimeter'], regular_polygon['apothem'])) def test_circumference_area(self): - # Make this test first... + circumference = self.operations['circumference'] + + self.assertEqual(circumference['result'], circumference_area(circumference['radius'])) def tearDown(self): - # Delete the needed values for the tests - pass + del(self.operations) unittest.main()