From dcedd8fdaa96d16f3eb34c6c122d7887c66d2a66 Mon Sep 17 00:00:00 2001 From: Dimanson perez Date: Sat, 1 Aug 2020 21:46:08 -0500 Subject: [PATCH] reto termindado --- challenge.py | 77 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/challenge.py b/challenge.py index ffdfcce..a9c36a9 100644 --- a/challenge.py +++ b/challenge.py @@ -5,42 +5,53 @@ def square_area(side): """Returns the area of a square""" # You have to code here # REMEMBER: Tests first!!! - pass + area = pow(2, side) + return area + def rectangle_area(base, height): """Returns the area of a rectangle""" # You have to code here # REMEMBER: Tests first!!! - pass + area = base * height + return area + def triangle_area(base, height): """Returns the area of a triangle""" # You have to code here # REMEMBER: Tests first!!! - pass + area = (base * height) / 2 + return area + def rhombus_area(diagonal_1, diagonal_2): """Returns the area of a rhombus""" # You have to code here # REMEMBER: Tests first!!! - pass + area = (diagonal_1 * diagonal_2) / 2 + return area + def trapezoid_area(base_minor, base_major, height): """Returns the area of a trapezoid""" # You have to code here # REMEMBER: Tests first!!! - pass + area = height * ((base_minor + base_major)/ 2) + return area def regular_polygon_area(perimeter, apothem): """Returns the area of a regular polygon""" # You have to code here # REMEMBER: Tests first!!! - pass + area = (perimeter * apothem) / 2 + return area + def circumference_area(radius): @@ -48,41 +59,69 @@ def circumference_area(radius): # You have to code here # REMEMBER: Tests first!!! # Use math.pi for π value - pass + area = round((math.pi * pow(radius, 2)) / 2) + return area + if __name__ == '__main__': import unittest - class GeometrySuite(unittest.TestCase): def setUp(self): - # Initialize the needed values for the tests - pass + # Initi8alize the needed values for the tests + self.values = { + 'square_area': 16, + 'rectangle_area' : 40, + 'triangle_area' : 9, + 'rhombus_area' : 12, + 'trapezoid_area' : 56.0, + 'regular_polygon_area' : 9, + 'circumference_area' : 6 + } def test_square_area(self): - # Make this test first... + # Make this test first... + value = self.values.get('square_area') + self.assertEqual(value, square_area(4)) + def test_rectangle_area(self): - # Make this test first... + # Make this test first... + value = self.values.get('rectangle_area') + self.assertEqual(value, rectangle_area(8, 5)) + def test_triangle_area(self): - # Make this test first... + # Make this test first... + value = self.values.get('triangle_area') + self.assertEqual(value, triangle_area(6, 3)) def test_rhombus_area(self): - # Make this test first... + # Make this test first... + value = self.values.get('rhombus_area') + self.assertEqual(value, rhombus_area(6, 4)) def test_trapezoid_area(self): - # Make this test first... + # Make this test first... + value = self.values.get('trapezoid_area') + self.assertEqual(value, trapezoid_area(8, 8, 7)) + def test_regular_polygon_area(self): - # Make this test first... + # Make this test first... + value = self.values.get('regular_polygon_area') + self.assertEqual(value, regular_polygon_area(6, 3)) def test_circumference_area(self): - # Make this test first... + # Make this test first... + value = self.values.get('circumference_area') + self.assertEqual(value, circumference_area(2)) + def tearDown(self): - # Delete the needed values for the tests - pass + # Delete the needed values for the tests + del(self.values) + unittest.main()