def grader(pl, pg, pt, ls, c, cwm, ccwm): pl = PolyLine.PolyLines(pl) pg = Polygon.Polygons(pg) cls = LineSegment.LineSegments(c) beam = pl.get_polyline_as_segments(0) if not pg.get_polygon_count() == 1: return False, "Did you forget the isolation bubble?" poly = pg.polygons[0] beam1 = beam.segments[0] beam2 = beam.segments[1] if len(pg.get_intersections_with_polygon_boundary(beam1, poly)) > 0: return False, "wrong 1" if len(pg.get_intersections_with_polygon_boundary(beam2, poly)) > 1: return False, "wrong 2" if pg.point_is_on_boundary([-2, -1]) == None: return False, "wrong 3" if pg.point_is_on_boundary([-3, 2]) == None and pg.point_is_on_boundary([2, -1]) == None: return False, "wrong 4" return True, "Good job!"
def grader(pl, pt, h, r, ls, cwm, ccwm): pl = PolyLine.PolyLines(pl) pt = GradeableFunction.GradeableFunction(pt) h = GradeableFunction.GradeableFunction(h) r = GradeableFunction.GradeableFunction(r) ls = LineSegment.LineSegments(ls) cwm = GradeableFunction.GradeableFunction(cwm) ccwm = GradeableFunction.GradeableFunction(ccwm) if pl.get_polyline_count() > 0: beam = pl.get_polyline_as_segments(0) if beam.get_number_of_segments() != 2: return False, "Did you forget the beam?" for segment in beam.segments: if beam.check_segment_startpoint(segment, [-3, 2]): if not beam.check_segment_endpoint(segment, [-3, -1]): return False, "Check beam segment connected to A" if beam.check_segment_startpoint(segment, [-3, -1]): if not beam.check_segment_endpoint(segment, [2, -1]): return False, "Check beam segment connected to B" if not cwm.has_point_at(x=-3, y=1): return False, "Check cwm position" if not ccwm.has_point_at(x=-1, y=-1): return False, "Check ccwm position" # TODO force position and direction checks return True, "Good job!"
def grader(pl, pg, pt, ls, c, cwm, ccwm): pl = PolyLine.PolyLines(pl) pg = Polygon.Polygons(pg) cls = LineSegment.LineSegments(c) points = GradeableFunction.GradeableFunction(pt) beam = pl.get_polyline_as_linesegments() if not pg.get_polygon_count() == 1: return False, "Did you forget the isolation bubble?" poly = pg.polygons[0] beam1 = beam.segments[0] beam2 = beam.segments[1] pointA = None pointB = None if points.get_number_of_points() > 0: for point in points.points: if point.tag_equals('A'): pointA = point if point.tag_equals('B'): pointB = point if len(pg.get_intersections_with_polygon_boundary(poly, beam1)) > 0: return False, "Isolation bubble should not cut vertical beam." if not len(pg.get_intersections_with_polygon_boundary(poly, beam2)) == 1: return False, "Isolation bubble should only cut the horizontal beam once." if pg.point_is_on_boundary([-2, -1]) == None: return False, "Check where the isolation bubble cuts the horizontal beam." if pg.point_is_on_boundary(pointA) == None and pg.point_is_on_boundary( pointB) == None: return False, "Check the isolation bubble containment." return True, "Good job!"
def test_get_segments_at_y(self): data = self.load_as_gradeable_collections('ls-segs') for d in data: ls = LineSegment.LineSegments(d['ls']) segs = ls.get_segments_at(y=1) self.assertEqual(len(segs), 3)
def test_false_does_exist_between(self): data = self.load_as_gradeable_collections('ls-not-exist') for d in data: ls = LineSegment.LineSegments(d['ls']) self.assertFalse(ls.does_exist_between(-1, 1))
def test_false_has_angle_t_at_x(self): data = self.load_as_gradeable_collections('ls-slope-2') for d in data: ls = LineSegment.LineSegments(d['ls']) self.assertFalse(ls.has_angle_t_at_x(math.atan(4), 0))
def test_false_get_number_of_segments(self): data = self.load_as_gradeable_collections('ls-segs') for d in data: ls = LineSegment.LineSegments(d['ls']) self.assertNotEqual(ls.get_number_of_segments(), 0)
def test_false_get_segment_angle(self): data = self.load_as_gradeable_collections('ls-segs') for d in data: ls = LineSegment.LineSegments(d['ls']) seg = ls.get_segments_at(x=1, y=1)[0] self.assertNotEqual(ls.get_segment_angle(seg), math.pi / 2)
def test_false_has_slope_m_at_x(self): # test using data from the app2-7-1 csv data = self.load_as_gradeable_collections('ls-slope-2') for d in data: ls = LineSegment.LineSegments(d['ls']) self.assertFalse(ls.has_slope_m_at_x(4, 0))
def test_line_segment_contains_tag_false(self): data = self.load_as_gradeable_collections('tag_data') d = data[0] ls = LineSegment.LineSegments(d['ls']) self.assertIsNone(ls.contains_tag('somethingelse'))
def test_false_check_segment_endpoint(self): data = self.load_as_gradeable_collections('ls-segs') for d in data: ls = LineSegment.LineSegments(d['ls']) seg = ls.get_segments_at(x=1, y=1)[0] self.assertFalse(ls.check_segment_endpoint(seg, [0, 0]))
def test_false_has_segments_at(self): data = self.load_as_gradeable_collections('ls-segs') for d in data: ls = LineSegment.LineSegments(d['ls']) self.assertFalse(ls.get_segments_at(x=3, y=3))
def test_line_segment_no_tags(self): data = self.load_as_gradeable_collections('tag_none') d = data[0] ls = LineSegment.LineSegments(d['ls']) self.assertIsNone(ls.contains_tag('tag'))
def test_none_get_segments_at(self): data = self.load_as_gradeable_collections('ls-segs') for d in data: ls = LineSegment.LineSegments(d['ls']) segs = ls.get_segments_at(x=3, y=3) self.assertIsNone(segs, None)
def test_true_get_segment_length(self): data = self.load_as_gradeable_collections('ls-segs') for d in data: ls = LineSegment.LineSegments(d['ls']) seg = ls.get_segments_at(x=1, y=1)[0] self.assertEqual(ls.get_segment_length(seg), math.sqrt(8))
def test_get_segments_at_x(self): data = self.load_as_gradeable_collections('ls-segs') for d in data: ls = LineSegment.LineSegments(d['ls']) self.assertTrue(ls.get_segments_at(x=1))
def test_line_segment_has_tag_false(self): data = self.load_as_gradeable_collections('tag_data') d = data[0] ls = LineSegment.LineSegments(d['ls']) self.assertFalse(ls.segments[0].tag_equals('somethingelse'))