From 808a5981203661276745d8b4ba6f055a0402a5f9 Mon Sep 17 00:00:00 2001 From: EdwardTL Date: Sun, 21 Jun 2020 21:11:17 -0500 Subject: [PATCH 1/2] Resuelve con arrays globales y locales --- challenge.py | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/challenge.py b/challenge.py index ffdfcce..706f319 100644 --- a/challenge.py +++ b/challenge.py @@ -4,22 +4,22 @@ def square_area(side): """Returns the area of a square""" # You have to code here - # REMEMBER: Tests first!!! - pass + # REMEMBER: Tests first!! + 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): @@ -53,36 +53,65 @@ def circumference_area(radius): if __name__ == '__main__': import unittest - + test_base = [2, 3, 4, 5, 6] + test_height = [7, 8, 9, 10, 11] class GeometrySuite(unittest.TestCase): def setUp(self): - # Initialize the needed values for the tests - pass + self.squares_sides = { + 2: 4, + 3: 9, + 4: 16, + 5: 25, + 6: 36 + } def test_square_area(self): - # Make this test first... + for key, value in self.squares_sides.items(): + self.assertEqual(value, square_area(key)) def test_rectangle_area(self): # Make this test first... + + rectangle_areas = [14, 24, 36, 50, 66] + for r in range(len(test_base)): + t_base = test_base[r] + t_height = test_height[r] + answer = rectangle_areas[r] + + self.assertEqual(answer, rectangle_area(t_base,t_height)) + # pass def test_triangle_area(self): # Make this test first... + + triangle_areas = [7, 12, 18, 25, 33] + for r in range(len(test_base)): + t_base = test_base[r] + t_height = test_height[r] + answer = triangle_areas[r] + + self.assertEqual(answer, triangle_area(t_base,t_height)) def test_rhombus_area(self): # Make this test first... + pass def test_trapezoid_area(self): # Make this test first... + pass def test_regular_polygon_area(self): # Make this test first... + pass def test_circumference_area(self): # Make this test first... + pass def tearDown(self): # Delete the needed values for the tests + # del(self.example_square_areas) pass unittest.main() From 53347ac8013cab325a7bd149b8b4381770cbbd15 Mon Sep 17 00:00:00 2001 From: EdwardTL Date: Sun, 21 Jun 2020 23:47:08 -0500 Subject: [PATCH 2/2] Completado el reto 05 --- challenge.py | 65 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/challenge.py b/challenge.py index 706f319..2c1e1c3 100644 --- a/challenge.py +++ b/challenge.py @@ -26,21 +26,21 @@ 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_minor+base_major)*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 perimeter*apothem/2 def circumference_area(radius): @@ -48,11 +48,14 @@ def circumference_area(radius): # You have to code here # REMEMBER: Tests first!!! # Use math.pi for π value - pass + pi = math.pi + return pi*(radius**2) if __name__ == '__main__': import unittest + import numpy + test_base = [2, 3, 4, 5, 6] test_height = [7, 8, 9, 10, 11] class GeometrySuite(unittest.TestCase): @@ -72,14 +75,14 @@ def test_square_area(self): def test_rectangle_area(self): # Make this test first... - rectangle_areas = [14, 24, 36, 50, 66] - for r in range(len(test_base)): + + for r in range(len(rectangle_areas)): t_base = test_base[r] t_height = test_height[r] answer = rectangle_areas[r] - self.assertEqual(answer, rectangle_area(t_base,t_height)) + self.assertEqual(answer, rectangle_area(t_base, t_height)) # pass def test_triangle_area(self): @@ -95,23 +98,61 @@ def test_triangle_area(self): def test_rhombus_area(self): # Make this test first... - pass + rhombus_areas = [7, 12, 18, 25, 33] + for r in range(len(test_base)): + t_base = test_base[r] + t_height = test_height[r] + answer = rhombus_areas[r] + + self.assertEqual(answer, triangle_area(t_base,t_height)) def test_trapezoid_area(self): # Make this test first... - pass + Minor_base = [2, 3, 4, 5, 6] + Major_Base = [4, 6, 6, 8, 12] + trapezoid_heigth = [8, 7, 6, 5, 4] + + trapezoid_answer = [24, 31.5, 30, 32.5, 36] + + for r in range(len(trapezoid_answer)): + Min_base = Minor_base[r] + Maj_base = Major_Base[r] + height = trapezoid_heigth[r] + + answer = trapezoid_answer[r] + + self.assertEqual(answer, trapezoid_area(Min_base, Maj_base, height)) def test_regular_polygon_area(self): # Make this test first... - pass + perimeters_array = [18, 60, 40, 64, 60] + apothems_array = [2.6, 8.66, 3, 6, 9.3] + Area_RegPol_array = [23.4, 259.8, 60, 192, 279] + + for r in range(len(Area_RegPol_array)): + perimeter = perimeters_array[r] + apothem = apothems_array[r] + answer = Area_RegPol_array[r] + + #DON'T ADD ARRAYS BECAUSE OF THE FLOAT VARIABLE TYPES + self.assertAlmostEqual(answer, regular_polygon_area(perimeter, apothem)) def test_circumference_area(self): + # Make this test first... - pass + radius_array = [3, 7.33, 5, 8.6543, 9] + circumference_answers_array = [28.27, 168.79, 78.54, 235.3, 254.47] + + for r in range(len(circumference_answers_array)): + radius = radius_array[r] + answer = circumference_answers_array[r] + + #DON'T ADD ARRAYS BECAUSE OF THE FLOAT VARIABLE TYPES + self.assertAlmostEqual(answer, round(circumference_area(radius),2)) def tearDown(self): # Delete the needed values for the tests # del(self.example_square_areas) - pass + del(self.squares_sides) unittest.main()