-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Grading Strategy to grade deductively (#18)
* strategy built in and working as was * no longer ignoring iml file * graded test results track if they passed instead of inspecting the score * deductive grader strategy code and tests for it * pulled out method to deduct * cleaned up code again * docs and pom update for v1.1 * wording tweak, ready to merge
- Loading branch information
Tim Kutcher
authored
Jan 31, 2019
1 parent
2e2f95d
commit f5c456e
Showing
12 changed files
with
297 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module version="4"> | ||
<component name="ExternalSystem" externalSystem="Maven" /> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/examples/gradescope/src/main/java" isTestSource="false" /> | ||
<excludeFolder url="file://$MODULE_DIR$/examples/gradescope/classes" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" /> | ||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | ||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" /> | ||
<orderEntry type="library" name="Maven: org.json:org.json:chargebee-1.0" level="project" /> | ||
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/com/github/tkutche1/jgrade/DeductiveGraderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.github.tkutche1.jgrade; | ||
|
||
import com.github.tkutche1.jgrade.gradedtest.GradedTestResult; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Strategy to grade deductively. This strategy will take a point value, | ||
* all tests will be worth 0, and failed tests will count negative. | ||
*/ | ||
public class DeductiveGraderStrategy implements GraderStrategy { | ||
|
||
private double floor; | ||
private double startingScore; | ||
private double deductedPoints; | ||
|
||
/** | ||
* Create a new DeductiveGradingStrategy. | ||
* @param startingScore The score to deduct from. | ||
*/ | ||
public DeductiveGraderStrategy(double startingScore) { | ||
this.startingScore = startingScore; | ||
this.floor = 0; | ||
this.deductedPoints = 0; | ||
} | ||
|
||
/** | ||
* Set the floor to deduct to. | ||
* @param floor The floor to deduct to. | ||
*/ | ||
public void setFloor(double floor) { | ||
this.floor = floor; | ||
} | ||
|
||
/** | ||
* Get the amount of points deducted from running this. | ||
* @return The amount of points deducted. | ||
*/ | ||
public double getDeductedPoints() { | ||
return this.deductedPoints; | ||
} | ||
|
||
@Override | ||
public void grade(List<GradedTestResult> l) { | ||
for (GradedTestResult r : l) { | ||
if (!r.passed()) { | ||
this.deductedPoints += this.deduct(r); | ||
} | ||
r.setPoints(0); | ||
} | ||
} | ||
|
||
// Deduct from r, return the amount deducted | ||
private double deduct(GradedTestResult r) { | ||
double amountToDeduct = r.getPoints(); | ||
if ((this.deductedPoints + r.getPoints()) > potentialDeductions()) { | ||
r.addOutput("Failed test but deductive grading did not subtract" | ||
+ "points below floor"); | ||
amountToDeduct = potentialDeductions() - this.deductedPoints; | ||
} | ||
r.setScore(0 - amountToDeduct); | ||
return amountToDeduct; | ||
} | ||
|
||
// Get the amount of possible points that can be deducted in total. | ||
private double potentialDeductions() { | ||
return this.startingScore - this.floor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/github/tkutche1/jgrade/GraderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.github.tkutche1.jgrade; | ||
|
||
import com.github.tkutche1.jgrade.gradedtest.GradedTestResult; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Interface for the strategy design pattern on top of a {@link Grader} object. | ||
* If you want to change the grading strategy, for example to grade deductively | ||
* instead of simply adding the tests as they are, you can call | ||
* {@link Grader#setGraderStrategy(GraderStrategy)}. | ||
*/ | ||
public interface GraderStrategy { | ||
|
||
/** | ||
* Do work on the list of {@link GradedTestResult}s before they get | ||
* added to the overall list of tests. | ||
* @param l The list of {@link GradedTestResult}s to modify (or not | ||
* in the case of the default strategy). | ||
*/ | ||
void grade(List<GradedTestResult> l); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.