diff --git a/.gitignore b/.gitignore index b6e4761..1d5c63a 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# vscode folder +.vscode/ \ No newline at end of file diff --git a/challenge.py b/challenge.py index ffdfcce..7d84d48 100644 --- a/challenge.py +++ b/challenge.py @@ -3,86 +3,98 @@ def square_area(side): """Returns the area of a square""" - # You have to code here - # REMEMBER: Tests first!!! - pass + return side**2 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) / 2) * height 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 * radius**2, 3)) if __name__ == '__main__': import unittest class GeometrySuite(unittest.TestCase): - def setUp(self): - # Initialize the needed values for the tests - pass + #!El setUp sólo se recomienda cuando los mismos datos sirven para diferentes Tests, y va + #!con el TearDown al final + self.areas = { + 'square': [16, 4], + 'rectangle': [30, 6, 5], + 'triangle': [7.5, 5, 3], + 'rhombus': [25, 5, 10], + 'trapezoid': [8, 3, 5, 2], + 'polygon': [168, 48, 7], + 'circumference': [12.566, 2] + } def test_square_area(self): - # Make this test first... + self.assertEqual(self.areas['square'][0], + square_area(self.areas['square'][1])) def test_rectangle_area(self): - # Make this test first... + self.assertEqual( + self.areas['rectangle'][0], + rectangle_area(self.areas['rectangle'][1], + self.areas['rectangle'][2])) def test_triangle_area(self): - # Make this test first... + self.assertEqual( + self.areas['triangle'][0], + triangle_area(self.areas['triangle'][1], + self.areas['triangle'][2])) def test_rhombus_area(self): - # Make this test first... + self.assertEqual( + self.areas['rhombus'][0], + rhombus_area(self.areas['rhombus'][1], + self.areas['rhombus'][2])) def test_trapezoid_area(self): - # Make this test first... + self.assertEqual( + self.areas['trapezoid'][0], + trapezoid_area(self.areas['trapezoid'][1], + self.areas['trapezoid'][2], + self.areas['trapezoid'][3])) def test_regular_polygon_area(self): - # Make this test first... + self.assertEqual( + self.areas['polygon'][0], + regular_polygon_area(self.areas['polygon'][1], + self.areas['polygon'][2])) def test_circumference_area(self): - # Make this test first... + self.assertEqual( + self.areas['circumference'][0], + circumference_area(self.areas['circumference'][1])) def tearDown(self): - # Delete the needed values for the tests - pass + #!Acompaña al setUp + del (self.areas) unittest.main()