From db29ed4d30c8f8cee66818e480804e8b587ec5e6 Mon Sep 17 00:00:00 2001 From: Mario Barbosa Date: Wed, 24 Jun 2020 22:50:16 -0500 Subject: [PATCH] Challenge solved --- challenge.py | 107 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 33 deletions(-) diff --git a/challenge.py b/challenge.py index ffdfcce..9855c71 100644 --- a/challenge.py +++ b/challenge.py @@ -3,52 +3,37 @@ 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 height * (base_minor + base_major) / 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): """Returns the area of a circumference""" - # You have to code here - # REMEMBER: Tests first!!! - # Use math.pi for π value - pass + return 3.14159*radius*radius if __name__ == '__main__': @@ -57,32 +42,88 @@ def circumference_area(radius): class GeometrySuite(unittest.TestCase): def setUp(self): - # Initialize the needed values for the tests - pass + self.dict_squares_area = { + 1 : 1, + 4 : 2, + 9 : 3, + } + + self.dict_rectangle_area = { + 2 : (1,2), + 6 : (2,3), + 12 : (3,4), + } + + self.dict_triangle_area ={ + 1 : (1,2), + 3 : (2,3), + 6 : (3,4), + } + + self.dict_rhombus_area ={ + 1 : (1,2), + 3 : (2,3), + 6 : (3,4), + } + + self.dict_trapezoid_area ={ + 4.5 : (1,2,3), + 10 : (2,3,4), + 17.5 : (3,4,5), + } + + self.dict_polygon_area ={ + 1 : (1,2), + 3 : (2,3), + 6 : (3,4), + } + + self.dict_circumference_area ={ + 3.14159 : 1, + 12.56636 : 2, + 50.26544 : 4, + } + def test_square_area(self): - # Make this test first... + for key, value in self.dict_squares_area.items(): + self.assertEqual(key, square_area(value)) + def test_rectangle_area(self): - # Make this test first... + for key, value in self.dict_rectangle_area.items(): + self.assertEqual(key, rectangle_area(value[0], value[1])) + def test_triangle_area(self): - # Make this test first... + for key, value in self.dict_triangle_area.items(): + self.assertEqual(key, triangle_area(value[0], value[1])) + def test_rhombus_area(self): - # Make this test first... + for key, value in self.dict_rhombus_area.items(): + self.assertEqual(key, rhombus_area(value[0], value[1])) + def test_trapezoid_area(self): - # Make this test first... + for key, value in self.dict_trapezoid_area.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.dict_polygon_area.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.dict_circumference_area.items(): + self.assertEqual(key, circumference_area(value)) def tearDown(self): - # Delete the needed values for the tests - pass + del(self.dict_squares_area) + del(self.dict_rectangle_area) + del(self.dict_triangle_area) + del(self.dict_rhombus_area) + del(self.dict_trapezoid_area) + del(self.dict_polygon_area) + del(self.dict_circumference_area) unittest.main()