AbstractClass - more flexible grading
Opened this issue · 0 comments
jy95 commented
Hello @AlexandreDubray,
If you want that exercise AbstractClass (and others in the future with this kind) to be more "tolerant" to students errors, here are a few tips on how to do it with an example :
- Replace all .class invocations by Class.forName() (that is what causes students to see message "You modified ..." )
- Add multiple Exception handlers (mainly ClassNotFoundException and NoSuchMethodError )
Example :
try {
String classNameWithPackage = "templates.Shape";
Class shapeClass = Class.forName(classNameWithPackage);
Method my_method = shapeClass.getDeclaredMethod("getArea", double.class);
// ... Some piece of code later ...
throw new CustomGradingResult(TestStatus.SUCCESS,1, "You defined a class Shape with a method called getArea")
} catch(ClassNotFoundException err) {
throw new CustomGradingResult(TestStatus.FAILED, 0, "Shape class not found");
} catch(NoSuchMethodError err) {
throw new CustomGradingResult(TestStatus.FAILED, 0, "Shape method getArea cannot be found");
} catch(Exception err) {
if (err instanceof CustomGradingResult) {
throw err;
}
throw new CustomGradingResult(TestStatus.FAILED, 0, "Unexpected error");
}
PS: As I'm busy with work, I can't make any PR for a long time.