Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 40 additions & 39 deletions challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,87 @@

def square_area(side):
"""Returns the area of a square"""
# You have to code here
# REMEMBER: Tests first!!!
pass

area = pow(side,2)
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 = ((base_major + base_minor) / 2) * height
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):
"""Returns the area of a circumference"""
# You have to code here
# REMEMBER: Tests first!!!
# Use math.pi for π value
pass

area = round((math.pi * pow(radius, 2)),2)
Copy link

@hyfi06 hyfi06 May 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Por qué reondeas a 2? esto depende del caso de uso. Si tu instrumento de medición, normalmente se toda la mitad de la mínima escala. Por ejemplo una regla que mide milímetros, tendrías que tomar 0.0005 m como incertidumbre. Manejar más decimales no tiene sentido.

return area

if __name__ == '__main__':
import unittest

class GeometrySuite(unittest.TestCase):

def setUp(self):
# Initialize the needed values for the tests
pass
self.values = {
'square_area' : 16,
'rectangle_area': 35,
'triangle_area': 10,
'rhombus_area': 20,
'trapezoid_area': 9,
'regular_polygon_area': 12,
'circumference_area': 28.27
}

def test_square_area(self):
# 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...
value = self.values.get('rectangle_area')
self.assertEqual(value, rectangle_area(7,5))

def test_triangle_area(self):
# Make this test first...
value = self.values.get('triangle_area')
self.assertEqual(value, triangle_area(5,4))

def test_rhombus_area(self):
# Make this test first...
value = self.values.get('rhombus_area')
self.assertEqual(value, rhombus_area(8,5))

def test_trapezoid_area(self):
# Make this test first...
value = self.values.get('trapezoid_area')
self.assertEqual(value, trapezoid_area(3,3,3))

def test_regular_polygon_area(self):
# Make this test first...
value = self.values.get('regular_polygon_area')
self.assertEqual(value, regular_polygon_area(8,3))

def test_circumference_area(self):
# Make this test first...

value = self.values.get('circumference_area')
self.assertEqual(value, circumference_area(3))

def tearDown(self):
# Delete the needed values for the tests
pass
del(self.values)

unittest.main()