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
72 changes: 39 additions & 33 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 float('%.3f'%(radius * math.pi))


if __name__ == '__main__':
Expand All @@ -57,32 +42,53 @@ def circumference_area(radius):
class GeometrySuite(unittest.TestCase):

def setUp(self):
# Initialize the needed values for the tests
pass
self.values = {
'side': 2,
'base': 3,
'height': 4,
'diagonal_1': 5,
'diagonal_2': 7,
'base_minor': 3,
'base_major': 5,
'perimeter': 4,
'apothem': 5,
'radius': 3
}

def test_square_area(self):
# Make this test first...
"""Test the function to find the area of a square with a side greater than zero"""
self.assertEqual(4, square_area(self.values['side']))

def test_rectangle_area(self):
# Make this test first...
"""Test the function to find the area of a rectangle with height and base greater than zero"""
self.assertEqual(12, rectangle_area(
self.values['base'], self.values['height']))

def test_triangle_area(self):
# Make this test first...
"""Test the function to find the area of a triangle with height and base greater than zero"""
self.assertEqual(6, triangle_area(
self.values['base'], self.values['height']))

def test_rhombus_area(self):
# Make this test first...
"""Test the function to find the area of a rhombus with diagonals greater than zero"""
self.assertEqual(17.5, rhombus_area(
self.values['diagonal_1'], self.values['diagonal_2']))

def test_trapezoid_area(self):
# Make this test first...
"""Test the function to find the area of a rhombus with bases greater than zero and height greater than zero"""
self.assertEqual(16, trapezoid_area(
self.values['base_minor'], self.values['base_major'], self.values['height']))

def test_regular_polygon_area(self):
# Make this test first...
"""Test the function to find the area of a polygon with apothem and perimeter greater than zero"""
self.assertEqual(10, regular_polygon_area(
self.values['perimeter'], self.values['apothem']))

def test_circumference_area(self):
# Make this test first...
"""Test the function to find the area of a circle with radius greater than zero"""
self.assertEqual(9.425, circumference_area(self.values['radius']))

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

unittest.main()