Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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/
55 changes: 23 additions & 32 deletions challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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**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__':
Expand All @@ -57,32 +42,38 @@ def circumference_area(radius):
class GeometrySuite(unittest.TestCase):

def setUp(self):
# Initialize the needed values for the tests
pass
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]
}

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]))
Comment thread
juanan150 marked this conversation as resolved.
Outdated

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
del(self.areas)
pass

unittest.main()