From 66de6daa17283a91e3797ef497fe45b1a76bc22d Mon Sep 17 00:00:00 2001 From: Andres Cendales Date: Mon, 22 Jun 2020 17:52:23 -0500 Subject: [PATCH] Solved - 9 casos de prueba --- challenge.py | 186 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 136 insertions(+), 50 deletions(-) diff --git a/challenge.py b/challenge.py index ffdfcce..7f03952 100644 --- a/challenge.py +++ b/challenge.py @@ -1,88 +1,174 @@ import math - def square_area(side): - """Returns the area of a square""" - # You have to code here - # REMEMBER: Tests first!!! - pass + if side < 0: + return False + 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 ((base_minor+ base_major)/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 math.pi * (radius**2) if __name__ == '__main__': + print() import unittest class GeometrySuite(unittest.TestCase): def setUp(self): - # Initialize the needed values for the tests - pass + self.squares = { + # Orden de los datos + # Resultado: Side + 0 : 0, + 1 : 1, + 4: 2, + False : -1, + 9 : 3, + 16 : 4, + 25 : 5 , + 36: 6 , + 49 : 7, + } + + self.rectangles = { + # Orden de los datos + # Resultado : base , altura + 1 : [1,1], + 2 : [1,2], + 3 : [1,3], + 2 : [2,1], + 4 : [2,2], + 6 : [2,3], + 3 : [3,1], + 6 : [3,2], + 9 : [3,3], + } + + self.triangles = { + #Orden de los datos + # Resultado: Base, altura + 0.5 : [1,1], + 1 : [1,2], + 1.5 : [1,3], + 1 : [2,1], + 2 : [2,2], + 3 : [2,3], + 1.5 : [3,1], + 3 : [3,2], + 4.5 : [3,3], + } + + self.rhombus = { + #Orden de los datos + # Resultado: diagonal_1, diagonal_2 + 1 : [1,1], + 2 : [1,2], + 3 : [1,3], + 2 : [2,1], + 4 : [2,2], + 6 : [2,3], + 3 : [3,1], + 6 : [3,2], + 9 : [3,3], + } + + self.trapezoids = { + #Orden de los datos + # Resultado: base_menor, base_mayor, altura + 1 : [1,1,1], + 2 : [1,1,2], + 1.5 : [2,1,1], + 3 : [2,1,2], + 2 : [3,1,1], + 4 : [3,1,2], + 1.5 : [1,2,1], + 3 : [1,2,2], + 2 : [2,2,1], + 4 : [2,2,2], + 2.5 : [3,2,1], + 5 : [3,2,2], + } + + self.regular_polygons = { + #Orden de los datos + # Resultado: perimetro, apothem + 0.5 : [1,1], + 1 : [1,2], + 1.5 : [1,3], + 1 : [2,1], + 2 : [2,2], + 3 : [2,3], + 1.5 : [3,1], + 3 : [3,2], + 4.5 : [3,3], + } + + self.circunferences ={ + #Orden de los datos + # Resultado: radio + 0 : 0, + 3.1416 : 1, + 12.5664: 2, + 28.2743 : 3, + 50.2655 : 4, + 78.5398 : 5 , + 113.0973: 6 , + 153.938 : 7, + 201.0619 : 8, + + } def test_square_area(self): - # Make this test first... - + for key, value in self.squares.items(): + self.assertEqual(key, square_area(value),) + def test_rectangle_area(self): - # Make this test first... - + for key, value in self.rectangles.items(): + self.assertEqual(key, rectangle_area(value[0],value[1])) + def test_triangle_area(self): - # Make this test first... + for key, value in self.triangles.items(): + self.assertEqual(key, triangle_area(value[0],value[1])) def test_rhombus_area(self): - # Make this test first... - + for key, value in self.rhombus.items(): + self.assertEqual(key, rhombus_area(value[0],value[1])) + def test_trapezoid_area(self): - # Make this test first... + for key, value in self.trapezoids.items(): + self.assertEqual(key, trapezoid_area(value[0],value[1],value[2])) def test_regular_polygon_area(self): - # Make this test first... + for key, value in self.regular_polygons.items(): + self.assertEqual(key, regular_polygon_area(value[0],value[1])) def test_circumference_area(self): - # Make this test first... + for key, value in self.circunferences.items(): + self.assertEqual(key, round(circumference_area(value),4)) def tearDown(self): - # Delete the needed values for the tests - pass + del(self.squares) + del(self.rectangles) + del(self.triangles) + del(self.rhombus) + del(self.trapezoids) + del(self.regular_polygons) + del(self.circunferences) + unittest.main()