def setUp(self): self.square = basic.Square() self.square.construct(20, 'hello', 'world') self.square.set_pos(50, 50) self.circle = basic.Circle() self.circle.construct(15, 'ittdpibs', 'if this test doesnt pass ill be sad') self.circle.set_pos(100, 100) self.rounded_rect = basic.RoundedRect() self.rounded_rect.construct(30, 20, 10, 'ccsg', 'cool cool sounds good (aka bootleg asg)') self.rounded_rect.set_pos(200, 200) self.arrow = basic.Arrow( self.square, self.circle, basic.ArrowSettings(basic.ArrowSettings.SOLID, basic.ArrowSettings.EDGE, basic.ArrowSettings.CENTER)) self.scene = basic.Scene() self.scene._directory = { 's': self.square, 'c': self.circle, 'rr': self.rounded_rect, 'a': self.arrow } self.snapshot = basic.Snapshot({'test': self.scene}, '', '')
def test_get_center_end_pos(self): tail_obj = basic.BasicShape() head_obj = basic.BasicShape() arrow = basic.Arrow( tail_obj, head_obj, basic.ArrowSettings(None, basic.ArrowSettings.CENTER, basic.ArrowSettings.CENTER)) tail_obj.construct(50, 50, '', '') head_obj.construct(50, 50, '', '') tail_obj.set_pos(0, 0) head_obj.set_pos(200, 200) self.assertEqual(arrow.get_tail_pos(), (0, 0)) self.assertEqual(arrow.get_head_pos(), (200, 200))
def test_get_center_end_pos(self): tail_obj = basic.Square() head_obj = basic.Square() arrow = basic.Arrow( tail_obj, head_obj, basic.ArrowSettings(None, basic.ArrowSettings.EDGE, basic.ArrowSettings.EDGE)) tail_obj.construct(50, '', '') head_obj.construct(50, '', '') tail_obj.set_pos(0, 0) head_obj.set_pos(100, 100) self.assertEqual(tuple(round(coord) for coord in arrow.get_tail_pos()), (25, 25)) self.assertEqual(tuple(round(coord) for coord in arrow.get_head_pos()), (75, 75))
def test_arrow_angles(self): tail_obj = basic.BasicShape() head_obj = basic.BasicShape() arrow = basic.Arrow(tail_obj, head_obj, basic.ArrowSettings(None, None, None)) tail_obj.construct(50, 50, '', '') head_obj.construct(50, 50, '', '') tail_obj.set_pos(100, 100) head_poses = [(200, 100), (200, 0), (100, 0), (0, 0), (0, 100), (0, 200), (100, 200), (200, 200)] expected_tail_angles = [0, 45, 90, 135, 180, -135, -90, -45] expected_head_angles = [180, -135, -90, -45, 0, 45, 90, 135] for (i, head_pos) in enumerate(head_poses): head_obj.set_pos(*head_poses[i]) self.assertEqual(expected_tail_angles[i], round(math.degrees(arrow.get_tail_angle()))) self.assertEqual(expected_head_angles[i], round(math.degrees(arrow.get_head_angle())))
def test_end_pos_caching(self): tail_obj = basic.Square() head_obj = basic.Square() arrow = basic.Arrow( tail_obj, head_obj, basic.ArrowSettings(None, basic.ArrowSettings.EDGE, basic.ArrowSettings.EDGE)) tail_obj.construct(50, '', '') head_obj.construct(50, '', '') tail_obj.set_pos(0, 0) head_obj.set_pos(100, 100) # check that the same call twice works the same self.assertEqual(tuple(round(coord) for coord in arrow.get_tail_pos()), (25, 25)) self.assertEqual(tuple(round(coord) for coord in arrow.get_tail_pos()), (25, 25)) self.assertEqual(tuple(round(coord) for coord in arrow.get_head_pos()), (75, 75)) self.assertEqual(tuple(round(coord) for coord in arrow.get_head_pos()), (75, 75)) # check that reposition recaches tail_obj.set_pos(200, 0) self.assertEqual(tuple(round(coord) for coord in arrow.get_tail_pos()), (175, 25)) self.assertEqual(tuple(round(coord) for coord in arrow.get_tail_pos()), (175, 25)) self.assertEqual(tuple(round(coord) for coord in arrow.get_head_pos()), (125, 75)) self.assertEqual(tuple(round(coord) for coord in arrow.get_head_pos()), (125, 75)) # check that caching actually happens self.assertEqual(arrow._get_end_pos(basic.Arrow.HEAD, say_cached=True), 'cached')