def grader(b1, b2, b3, lw, rw, blk, sl, force, plate, iso): bar1 = PolyLine.PolyLines(b1) bar2 = PolyLine.PolyLines(b2) bar3 = PolyLine.PolyLines(b3) block = Polygon.Polygons(blk) iso_bub = Polygon.Polygons(iso) block_poly = block.polygons[0] if not iso_bub.get_polygon_count() == 1: return False, "There should be one isolation bubble." iso_poly = iso_bub.polygons[0] bar1_line = bar1.getPolyLineAsSegments(0).segments[0] bar2_line = bar2.getPolyLineAsSegments(0).segments[0] if len(iso_bub.get_intersections_with_polygon_boundary( bar1_line, iso_poly)) != 1: return False, "Iso bubble should cut the bars" if len(iso_bub.get_intersections_with_polygon_boundary( bar2_line, iso_poly)) != 1: return False, "Iso bubble should cut the bars" if iso_bub.contains_polygon(block_poly) == None: return False, "Iso bubble should contain the block" if not iso_bub.point_is_on_boundary([3, 0.6]): return False, "Iso bubble should cut the slider" 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) 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, 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_polyline_segments_true(self): data = self.load_as_gradeable_collections('polyline') d = data[1] poly = PolyLine.PolyLines(d['pl']) self.assertIsNotNone(poly.get_polyline_as_linesegments())
def test_polyline_count(self): data = self.load_as_gradeable_collections('polyline') d = data[1] poly = PolyLine.PolyLines(d['pl']) self.assertEqual(poly.get_polyline_count(), 1)
def test_polyline_splines_false(self): data = self.load_as_gradeable_collections('polyline') d = data[0] poly = PolyLine.PolyLines(d['pl']) funcs = poly.get_polyline_as_gradeablefunction().functions self.assertTrue(len(funcs) == 0)
def test_polyline_splines_true_count(self): data = self.load_as_gradeable_collections('polyline') d = data[1] poly = PolyLine.PolyLines(d['pl']) splines = poly.get_polyline_as_gradeablefunction() self.assertTrue(len(splines.functions) > 0)
def test_polyline_segments_false(self): data = self.load_as_gradeable_collections('polyline') d = data[0] poly = PolyLine.PolyLines(d['pl']) segs = poly.get_polyline_as_linesegments().segments self.assertTrue(len(segs) == 0)
def test_polyline_segments_true_count(self): data = self.load_as_gradeable_collections('polyline') d = data[1] poly = PolyLine.PolyLines(d['pl']) segments = poly.get_polyline_as_linesegments() self.assertTrue(len(segments.segments) > 0)
def test_polyline_spline_contains_tag_false(self): data = self.load_as_gradeable_collections('tag_data') d = data[0] pl = PolyLine.PolyLines(d['pl']) self.assertIsNone(pl.get_polyline_as_gradeablefunction().contains_tag('somethingelse'))
def test_polyline_spline_has_tag_true(self): data = self.load_as_gradeable_collections('tag_data') d = data[0] pl = PolyLine.PolyLines(d['pl']) self.assertTrue(pl.get_polyline_as_gradeablefunction().functions[0].tag_equals('tag'))
def test_polyline_segment_contains_tag_true(self): data = self.load_as_gradeable_collections('tag_data') d = data[0] pl = PolyLine.PolyLines(d['pl']) self.assertIsNotNone(pl.get_polyline_as_linesegments().contains_tag('tag'))
def test_polyline_segment_has_tag_false(self): data = self.load_as_gradeable_collections('tag_data') d = data[0] pl = PolyLine.PolyLines(d['pl']) self.assertFalse(pl.get_polyline_as_linesegments().segments[0].tag_equals('somethingelse'))