Question: Unit Tests The shapes_test.py file will contain the unit tests (some have been provided) to test the Point and Circle classes. Review the Testing lecture

Unit Tests

The shapes_test.py file will contain the unit tests (some have been provided) to test the Point and Circle classes. Review the Testing lecture from Week 7 if you need help, especially how to test the errors raised in the Circle class.

DO NOT CHANGE THE EXISTING TESTS THAT COME WITH THE FILE.

Please number your test methods in their docstrings to match the lines below. You may find it easier to copy these lines and use them as the docstrings for each of the tests. Perhaps make all the skeleton test methods first and put a failing test, like self.assertEqual(0, 1) as one line of code, then implementing the tests as needed.

Be sure to do sanity checks on your tests to make sure they are testing what they are supposed to test. I will be running your shapes.py against my shapes_test.py and vice-versa, along with manually inspecting your code.

When you are done, it should run 45 tests! To run the tests:

$ python shapes_test.py ............................................. ------------------------------------------------------------------- Ran 45 tests in 0.004s

OK

When you are finished and run the test program, it should run 45 tests. If you have any questions about what these tests are supposed to test, please ask! The tests marked Done are included with

shapes_test.py.

Tests for Points: P-1. Create a Point with no arguments -Done P-2. Create a Point with values -Done P-3. Verify modification of x, y -Done P-4. Verify Point is iterable -Done P-5. Verify Point magnitude property -Done P-6. Verify magnitude property changes after Point changes -Done P-7. Verify distance between two Point objects -Done P-8. Verify Point addition -Done P-8a. Verify Point += mutating addition -Done P-9. Verify Point str result -Done P-10. Verify Point repr result -Done

You write:

P-11. Create a Point using from_tuple P-12. Verify error when using from_tuple with no arguments P-13. Verify modification of x, y using loc_from_tuple with values P-14. Verify error when using loc_from_tuple with no arguments P-15. Verify Point multiplied with scalar P-16. Verify scalar multiplied with Point P-17. Verify Point *= mutating multiply with scalar

Tests for Circles: C-0. Make sure Circle centers are different objects for default -Done (This test makes sure that you are creating the default circle correctly.) C-1. Create Circle with no arguments -Done C-2. Create Circle with center Point but no radius -Done

C-3. Create Circle with radius but no center Point -Done C-4. Create Circle with center Point and radius -Done C-5. Create Circle without keywords -Done C-5A. Verify moving center Point of Circle works -Done C-6. Verify area property -Done

You write:

C-7. Verify radius attribute change works C-8. Verify area changes correctly when radius changes C-9. Verify center attribute change works C-10. Verify error if center is not a Point on creation C-11. Verify error if changing center to something not a Point C-12. Verify diameter property works C-13. Verify diameter changes works C-14. Verify error when creating a Circle with radius < 0 C-15. Verify error when changing radius < 0 C-16. Verify error when changing diameter < 0 C-17. Verify Circle addition C-17a. Verify Circle += mutating addition C-18. Verify Circle str result C-19. Verify Circle repr result C-20. Create Circle using from_tuple instead of a Point C-21. Verify error using Circle.from_tuple with no arguments C-22. Create Circle using from_tuple with only tuple C-23. Verify Circle modification with center_from_tuple method C-24. Verify error using center_from_tuple with no arguments

the shape_test file is attached below:

import unittest from shapes import Point, Circle

# Helper functions - use these for verification when appropriate. def point_data(point): """Return tuple of Point data for comparison.""" return (point.x, point.y)

def circle_data(circle): """Return tuple of Circle data for comparison.""" return ( (circle.center.x, circle.center.y), circle.radius )

class PointTests(unittest.TestCase):

def test_create_point_no_data(self): """P-1. Create a Point with no arguments.""" # Create a tuple of what the answer from point_data should be expected = (0, 0) point = Point() self.assertEqual(point_data(point), expected)

def test_create_point_with_data(self): """P-2. Create a Point with values.""" expected = (2, 3) point = Point(2, 3) self.assertEqual(point_data(point), expected)

def test_point_modification(self): """P-3. Verify modification of x, y works.""" expected = (-1, 5) point = Point() point.x, point.y = -1, 5 self.assertEqual(point_data(point), expected)

def test_point_iterable(self): """P-4. Verify Point is iterable.""" expected = (2, 3) point = Point(2, 3) x, y = point self.assertEqual((x, y), expected) j, k = point self.assertEqual((j, k), expected)

def test_magnitude(self): """P-5. Verify Point magnitude property.""" expected = 3.605551275463989 point = Point(2, 3) self.assertEqual(point.magnitude, expected)

def test_magnitude_changes(self): """P-6. Verify magnitude property changes after Point changed.""" expected = 5 point = Point(-1, 6) point.x, point.y = 3, 4 self.assertEqual(point.magnitude, expected)

def test_distance(self): """P-7. Verify distance between two Point objects.""" expected = 5 point1 = Point(2, 3) point2 = Point(5, 7) self.assertEqual(point1.distance(point2), expected)

def test_point_addition(self): """P-8. Verify Point addition.""" expected1 = (2, 3) expected2 = (4, 5) expected3 = (6, 8) point1 = Point(2, 3) point2 = Point(4, 5) point3 = point1 + point2 # Ensure original points unchanged self.assertEqual(point_data(point1), expected1) self.assertEqual(point_data(point2), expected2) # Verify new point is correct self.assertEqual(point_data(point3), expected3)

def test_point_plus_equal_addition(self): """P-8a. Verify Point += mutating addition.""" expected = (6, 8) point1 = Point(2, 3) # Save the id to make sure it doesn't change. id1 = id(point1) point2 = Point(4, 5) # Add using += point1 += point2 self.assertEqual(point_data(point1), expected) # Verify point2 has not changed expected = (4, 5) self.assertEqual(point_data(point2), expected) # Verify that point1 is the same object self.assertEqual(id(point1), id1)

def test_point_str(self): """P-9. Verify Point str result.""" expected = "Point at (2, 3)" point = Point(2, 3) self.assertEqual(str(point), expected)

def test_point_repr(self): """P-10. Verify Point repr result.""" expected = "Point(x=2, y=3)" point = Point(2, 3) self.assertEqual(repr(point), expected)

# Remaining Point tests go here

class CircleTests(unittest.TestCase):

def test_circle_point_objects_different(self): """C-0. Make sure Circle centers are different objects for default.""" # In other words, they should have the same VALUES, # But NOT be the same objects. circle1 = Circle() circle2 = Circle() self.assertIsNot(circle1.center, circle2.center) self.assertEqual(circle_data(circle1), circle_data(circle2))

def test_create_no_input(self): """C-1. Create Circle with no arguments.""" # Create a tuple of what the answer from circle_data should be expected = ((0, 0), 1) circle = Circle() self.assertEqual(circle_data(circle), expected)

def test_create_only_point_input(self): """C-2. Create Circle with Point but no radius.""" expected = ((2, 3), 1) circle = Circle(center=Point(2, 3)) self.assertEqual(circle_data(circle), expected)

def test_create_only_radius_input(self): """C-3. Create Circle with radius but no Point.""" expected = ((0, 0), 2.5) circle = Circle(radius=2.5) self.assertEqual(circle_data(circle), expected)

def test_create_point_and_radius_input(self): """C-4. Create Circle with Point and radius.""" expected = ((2, 3), 1.5) circle = Circle(center=Point(2, 3), radius=1.5) self.assertEqual(circle_data(circle), expected)

def test_create_no_keywords(self): """C-5. Create Circle without keywords.""" expected = ((2, 3), 1.5) circle = Circle(Point(2, 3), 1.5) self.assertEqual(circle_data(circle), expected)

def test_move_center(self): """C-5A. Verify moving center Point of Circle works.""" expected = ((6, 2), 1.5) point = Point(2, 3) circle = Circle(point, 1.5) point.x = 6 point.y = 2 self.assertEqual(circle_data(circle), expected)

def test_area(self): """C-6. Verify area property.""" expected = 12.566370614359172 circle = Circle(radius=2) self.assertEqual(circle.area, expected)

# Remaining Circle tests go here

if __name__ == "__main__": unittest.main()

Would someone help me with it asap? Its kind of last minute assignment. Thank you a lotttttt!!!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!