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(grp, f): # Only have to declare the plugins you want to grade. lines = GradeableFunction.GradeableFunction(grp) function = GradeableFunction.GradeableFunction(f) # Can now grade data either from individual plugins or handle multiple # plugins with comparable data through the group return True, "Good job!"
def grader(pt): pt = GradeableFunction.GradeableFunction(pt) if pt.get_number_of_points() < 2: return False, 'You have not created at least two points' return True, 'Good Job'
def test_false__is_zero_at_x_equals_zero(self): # initialize data from u4-app2-sketch1.py csv data data = self.load_as_gradeable_collections( 'app_2-tab7-problem1.anon.csv') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.is_zero_at_x_equals_zero())
def test_false_with_x_has_point_at(self): # test using data from the hw4A-4-1 csv data = self.load_as_gradeable_collections( 'hw4A-tab4-problem1.anon.csv') for d in data: cp = GradeableFunction.GradeableFunction(d['cp']) self.assertFalse(cp.has_point_at(x=-2))
def test_is_none_with_xy_get_point_at(self): # test using data from the hw4A-4-1 csv data = self.load_as_gradeable_collections( 'hw4A-tab4-problem1.anon.csv') for d in data: cp = GradeableFunction.GradeableFunction(d['cp']) self.assertIsNone(cp.get_point_at(x=-2, y=5))
def test_get_number_of_points(self): # test using data from the hw4A-4-1 csv data = self.load_as_gradeable_collections( 'hw4A-tab4-problem1.anon.csv') for d in data: cp = GradeableFunction.GradeableFunction(d['cp']) self.assertEqual(cp.get_number_of_points(), 2)
def grader(f): f = GradeableFunction.GradeableFunction(f) if not f.is_straight_between(-1, 1): return False, 'Not straight' return True, 'Good Job'
def test_false__is_less_than_y_between(self): # initialize data from u4-app2-sketch1.py csv data data = self.load_as_gradeable_collections( 'app_2-tab7-problem1.anon.csv') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.is_less_than_y_between(2, -4, -1))
def test_true__is_zero_at_x_equals_zero(self): # initialize data from u4-ps4B-criticaldamping.py csv data data = self.load_as_gradeable_collections( 'hw4B-tab4-problem4.anon.csv') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertTrue(f.is_zero_at_x_equals_zero())
def test_false__has_value_y_at_x(self): # initialize data from u4-psA-u2b1-a.py csv data data = self.load_as_gradeable_collections( 'hw4A-tab4-problem1.anon.csv') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.has_value_y_at_x(3, 0))
def test_false_with_point_has_point_at(self): # test using data from the hw4A-4-1 csv data = self.load_as_gradeable_collections( 'hw4A-tab4-problem1.anon.csv') for d in data: cp = GradeableFunction.GradeableFunction(d['cp']) test_point = Point.Point(cp, -2, 5, pixel=False) self.assertFalse(cp.has_point_at(point=test_point))
def test_not_none_with_x_get_point_at(self): # test using data from the hw4A-4-1 csv data = self.load_as_gradeable_collections( 'hw4A-tab4-problem1.anon.csv') for d in data: cp = GradeableFunction.GradeableFunction(d['cp']) p = cp.get_point_at(x=-1) self.assertIsNotNone(p) self.assertAlmostEqual(p.y, 3, places=0)
def test_closest_point_to_x(self): # test using data from the app2-17-1 csv data = self.load_as_gradeable_collections( 'hw4A-tab4-problem1.anon.csv') for d in data: cp = GradeableFunction.GradeableFunction(d['cp']) dist, p = cp.closest_point_to_x(-1) self.assertLess(dist, 1) self.assertIsNotNone(p)
def test_closest_point_to_point(self): # test using data from the app2-17-1 csv data = self.load_as_gradeable_collections( 'hw4A-tab4-problem1.anon.csv') for d in data: cp = GradeableFunction.GradeableFunction(d['cp']) test_point = Point.Point(cp, -1, 3, pixel=False) dist, p = cp.closest_point_to_point(test_point) # print '' + str(p.x) + ' ' + str(p.y) # print dist # the square pixel distance can be quite big e.g. 98.5 for (-.95, 3.16) self.assertLess(dist, 100) self.assertIsNotNone(p)
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_false_has_slope_m_at_x(self): data = self.load_as_gradeable_collections('slope') for d in data: f = GradeableFunction.GradeableFunction(d['f']) print 'false slope' self.assertFalse(f.has_slope_m_at_x(-1, 0))
def test_true_does_exist_between(self): data = self.load_as_gradeable_collections('hw4A-tab4-problem1.anon.csv') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertTrue(f.does_exist_between(-1, 0))
def test_false_does_exist_between(self): data = self.load_as_gradeable_collections('not_exist') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.does_exist_between(-1, 1))
def test_false_has_constant_value_y_between(self): data = self.load_as_gradeable_collections('not_constant') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.has_constant_value_y_between(0.5, -1, 1))
def test_false_has_max_at(self): data = self.load_as_gradeable_collections('min_at_zero') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.has_max_at(0))
def test_false_has_negative_curvature_between(self): data = self.load_as_gradeable_collections('hw4A-tab4-problem1.anon.csv') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.has_negative_curvature_between(0, 2.5))
def test_true_is_straight_between(self): data = self.load_as_gradeable_collections('straight_line') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertTrue(f.is_straight_between(-1, 1))
def test_false_is_always_decreasing(self): data = self.load_as_gradeable_collections('increasing_line') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.is_always_decreasing())
def test_false_is_decreasing_between(self): data = self.load_as_gradeable_collections('hw4A-tab4-problem1.anon.csv') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.is_decreasing_between(-10, -1))
def test_false_get_horizontal_line_crossings(self): data = self.load_as_gradeable_collections('vert_cross') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertNotEqual(len(f.get_horizontal_line_crossings(0)), 2)
def test_true_has_constant_value_y_between(self): data = self.load_as_gradeable_collections('constant_2') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertTrue(f.has_constant_value_y_between(2, -1, 1))
def test_spline_no_tags(self): data = self.load_as_gradeable_collections('tag_none') d = data[0] f = GradeableFunction.GradeableFunction(d['f']) self.assertIsNone(f.contains_tag('tag'))
def test_spline_contains_tag_false(self): data = self.load_as_gradeable_collections('tag_data') d = data[0] f = GradeableFunction.GradeableFunction(d['f']) self.assertIsNone(f.contains_tag('somethingelse'))
def test_false_is_straight_between(self): data = self.load_as_gradeable_collections('min_at_zero') for d in data: f = GradeableFunction.GradeableFunction(d['f']) self.assertFalse(f.is_straight_between(-1, 1))