Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# vscode folder
.vscode/
80 changes: 46 additions & 34 deletions challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Comment on lines +46 to +54
Copy link

Choose a reason for hiding this comment

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

Te recomiendo leer la documentación para ver cuando y por que se usa setUp. En este caso no es necesario ya que tus valores no se comparten entre test.
https://docs.python.org/3/library/unittest.html#organizing-test-code

Copy link
Author

Choose a reason for hiding this comment

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

Gracias Héctor! La doc me dejó todo muy claro (no estuve en esta clase en Máster), este lo voy a dejar así como material de estudio y voy a agregar un comment explicando que el setUp se usa cuando los mismos datos de evaluación sirven para diferentes tests 👍

Copy link

Choose a reason for hiding this comment

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

La documentación es tu amiga, consúltala!


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()