def test_create_point_from_tuple(self): """P-11. Create a Point using from_tuple.""" expected = (3, 4) loc = (3, 4) point = Point.from_tuple(loc) self.assertEqual(point_data(point), expected)
def test_p05_magnitude(self): """P-05. Verify Point magnitude property.""" expected = 3.605551275463989 point = Point(2, 3) self.assertEqual(point.magnitude, expected)
def test_p07_distance(self): """P-07. Verify distance between two Point objects.""" expected = 5 point1 = Point(2, 3) point2 = Point(5, 7) self.assertEqual(point1.distance(point2), expected)
def test_c04_create_point_and_radius_input(self): """C-04. 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_p02_create_point_with_data(self): """P-02. Create a Point with values.""" expected = (2, 3) point = Point(2, 3) self.assertEqual(point_data(point), expected)
from shapes import Point from shapes import Triangle high = Point(0, 0, 4) low = Point(0, 0, -1) we = Point(0, 0, 3) we2 = Point(0, 0, 3) print we.is_equal(high) print we.is_equal(we2) tri = Triangle(high, low, we) print "high: " + tri.z_high.point_tos() + " expected: 0 0 4" print "low: " + tri.z_low.point_tos() + " expected: 0 0 -1" tri2 = Triangle(low, high, we) print "high: " + tri2.z_high.point_tos() + " expected: 0 0 4" print "low: " + tri2.z_low.point_tos() + " expected: 0 0 -1" tri3 = Triangle(we, high, low) print "high: " + tri3.z_high.point_tos() + " expected: 0 0 4" print "low: " + tri3.z_low.point_tos() + " expected: 0 0 -1" tri4 = Triangle(we, low, high) print "high: " + tri4.z_high.point_tos() + " expected: 0 0 4" print "low: " + tri4.z_low.point_tos() + " expected: 0 0 -1" tri5 = Triangle(high, we, low) print "high: " + tri5.z_high.point_tos() + " expected: 0 0 4" print "low: " + tri5.z_low.point_tos() + " expected: 0 0 -1"
def test_p09_point_str(self): """P-09. Verify Point str result.""" expected = "Point at (2, 3)" point = Point(2, 3) self.assertEqual(str(point), expected)
def test_change_center(self): """C-9. Verify center attribute change works.""" expected = ((2, 3), 1) circle = Circle() circle.center = Point(2, 3) self.assertEqual(circle_data(circle), expected)
def test_diameter(self): """C-12. Verify diameter property works.""" expected = 3 circle = Circle(center=Point(2, 3), radius=1.5) self.assertEqual(circle.diameter, expected)
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_change_radius(self): """C-7. Verify radius attribute change works.""" expected = ((2, 3), 1.5) circle = Circle(center=Point(2, 3)) circle.radius = 1.5 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_point_mod_loc_from_tuple_no_args(self): """P-14. Verify error when using loc_from_tuple with no arguments.""" point = Point(2, 3) with self.assertRaises(TypeError): point.loc_from_tuple()
def test_error_point_from_tuple_no_args(self): """P-12. Verify error when using from_tuple with no arguments""" with self.assertRaises(TypeError): Point.from_tuple()
from shapes import Point p1 = Point(4, 5) print(p1.x) # 4 print(p1.y) # 5 p1.color = 'blue' print(p1.color) # blue p2 = Point(7, 8) print(p2.x) # 7 print(p2.y) # 8 print(p2.color) # AttributeError: 'Point' object has no attribute 'color'
def test_diameter_changes(self): """C-13. Verify diameter changes works.""" expected = ((2, 3), 1.5) circle = Circle(center=Point(2, 3)) circle.diameter = 3 self.assertEqual(circle_data(circle), expected)
from drawing_pane import ConsoleDrawingPane from shapes import Circle, Point, Rectangle, Square pane = ConsoleDrawingPane() pane.shapes = [ Point(10, 5, 'P'), Point(30, 3, 'P'), Rectangle(2, 1, 10, 3, 'R'), Square(38, 2, 7, 'S'), Circle(20, 5, 2, 'C') ] # before moving pane.draw() pane.shapes[2].move(1,1) pane.shapes[4].move(2, 1) # after moving pane.draw()
def test_create_negative_radius(self): """C-14. Verify error when radius < 0.""" with self.assertRaises(ValueError): # Don't need to assign Circle to anything Circle(center=Point(2, 3), radius=-2)
from shapes import Point p1 = Point(2, 3, 'left') print(p1.x) # 2 print(p1.y) # 3 print(p1.name) # left p1.x = 7 # 7 print(p1.x) p1.color = 'blue' print(p1.color) # blue p1.x = 'infinity' # infinity print(p1.x)
def test_change_negative_radius(self): """C-15. Verify error when radius < 0.""" circle = Circle(center=Point(2, 3), radius=2) with self.assertRaises(ValueError): circle.radius = -2
def test_p10_point_repr(self): """P-10. Verify Point repr result.""" expected = "Point(x=2, y=3)" point = Point(2, 3) self.assertEqual(repr(point), expected)
def test_change_negative_diameter(self): """C-16. Verify error when diameter < 0.""" circle = Circle(center=Point(2, 3), radius=2) with self.assertRaises(ValueError): circle.diameter = -2
def test_c05_create_no_keywords(self): """C-05. Create Circle without keywords.""" expected = ((2, 3), 1.5) circle = Circle(Point(2, 3), 1.5) self.assertEqual(circle_data(circle), expected)
def test_circle_str(self): """C-18. Verify Circle str result.""" expected = 'Circle with center at (2, 3) and radius 2.5' circle = Circle(center=Point(2, 3), radius=2.5) self.assertEqual(str(circle), expected)
def test_p03_point_modification(self): """P-03. 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_circle_repr(self): """C-19. Verify Circle repr result.""" expected = 'Circle(center=Point(2, 3), radius=2.5)' circle = Circle(center=Point(2, 3), radius=2.5) self.assertEqual(repr(circle), expected)
def test_p06_magnitude_changes(self): """P-06. 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_circle_modify_center_from_tuple_no_args(self): """C-24. Verify error using center_from_tuple with no arguments.""" circle = Circle(center=Point(3, 4), radius=2) with self.assertRaises(TypeError): circle.center_from_tuple()
import numpy import mayavi.mlab as maya import matplotlib.pyplot as plt import time from tqdm import tqdm from os.path import join from shapes import Point, Sheet from utils import interactionPotential conc = 1e-5 A = 10e-20 use_mayavi = True mesh_size = 1 p = Point(0,0,0,mesh_size) sheet = Sheet(0,0,0,50,50,1,mesh_size) sheet = sheet.shift([-sheet.center[0], -sheet.center[1], -1]) p.visualize(use_mayavi) sheet.visualize(use_mayavi) if use_mayavi: maya.show() else: plt.show() root = r'W:\geeta\Rotation\InteractionPotential\point_Sheet' name = 'point_sheet1' start = time.time()
from shapes import Point p1 = Point(2, 3, 'left') print(p1) # Point(x=2, y=3, name='left')