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
49 changes: 40 additions & 9 deletions challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,51 @@ 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_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):
"""Returns the area of a circumference"""
# You have to code here
# REMEMBER: Tests first!!!
# Use math.pi for π value
pass

area = math.pi * (radius**2)
return round(area,2)

if __name__ == '__main__':
import unittest
Expand All @@ -58,28 +58,59 @@ class GeometrySuite(unittest.TestCase):

def setUp(self):
# Initialize the needed values for the tests
pass
global side, base, height, diagonal_1, diagonal_2,base_minor, base_major, perimeter, apothem, radius
side = 2
base = 3
height = 4
diagonal_1 = 8
diagonal_2 = 6
base_minor = 20
base_major = 40
perimeter = 30
apothem = 4
radius = 5

def test_square_area(self):
# Make this test first...
result = square_area(side)

self.assertEqual(result, 4)

def test_rectangle_area(self):
# Make this test first...
result = rectangle_area(base, height)

self.assertEqual(result, 12)

def test_triangle_area(self):
# Make this test first...
result = triangle_area(base , height)

self.assertEqual(result, 6)

def test_rhombus_area(self):
# Make this test first...
result = rhombus_area(diagonal_1, diagonal_2)

self.assertEqual(result, 24)

def test_trapezoid_area(self):
# Make this test first...
result = trapezoid_area(base_minor, base_major, height)

self.assertEqual(result, 120)

def test_regular_polygon_area(self):
# Make this test first...
result = regular_polygon_area(perimeter, apothem)

self.assertEqual(result, 60)

def test_circumference_area(self):
# Make this test first...
result = circumference_area(radius)

self.assertEqual(result, 78.54)

def tearDown(self):
# Delete the needed values for the tests
Expand Down