Skip to content

Commit 1be4ec3

Browse files
committed
Add pracdemo stage for pracdemo marking
1 parent b835c70 commit 1be4ec3

5 files changed

Lines changed: 74 additions & 8 deletions

File tree

src/main/java/chalkbox/commands/Grade.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ private Stage getStage(String name, Config config) {
8484
case "codestyle" -> config.toCodestyle();
8585
case "conformance" -> config.toConformance();
8686
case "functionality" -> config.toFunctionality();
87+
case "pracdemo" -> config.toPracDemo();
8788
case "mutation" -> config.toMutation();
8889
case "tlc" -> config.toTLC();
8990
default -> null;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package chalkbox.commands;
2+
3+
import chalkbox.config.Config;
4+
import chalkbox.stages.StageException;
5+
import com.google.common.flogger.FluentLogger;
6+
import picocli.CommandLine.Command;
7+
import picocli.CommandLine.Mixin;
8+
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
12+
@Command(name = "pracdemo",
13+
description = "Runs practical demonstration marking")
14+
public class PracDemo implements Runnable {
15+
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
16+
17+
@Mixin Shared shared = new Shared();
18+
19+
@Override
20+
public void run() {
21+
Path configFile = Paths.get(shared.configFile);
22+
var config = new Config(configFile);
23+
24+
var solution = config.toSolution();
25+
var submission = config.toSubmission();
26+
var stage = config.toPracDemo();
27+
try {
28+
var result = stage.run(submission, solution);
29+
logger.atInfo().log("Practical Demonstration Run");
30+
logger.atInfo().log(result.overview().getOutput());
31+
for (var inner : result.results()) {
32+
logger.atInfo().log(inner.getOutput());
33+
}
34+
} catch (StageException e) {
35+
logger.atSevere().log(e.toString());
36+
System.exit(0);
37+
} catch (Exception e) {
38+
throw new RuntimeException(e);
39+
}
40+
}
41+
}

src/main/java/chalkbox/commands/Run.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
@Command(name = "run",
77
description = "Run one of the supported commands: CheckStyle, Conformance, Functionality, Mutation",
8-
subcommands = { Grade.class, Conformance.class, CodeStyle.class, Functionality.class, Mutation.class, TLC.class, CommandLine.HelpCommand.class })
8+
subcommands = { Grade.class, Conformance.class, CodeStyle.class, Functionality.class, PracDemo.class, Mutation.class, TLC.class, CommandLine.HelpCommand.class })
99
public class Run implements Runnable {
1010

1111
@Override

src/main/java/chalkbox/config/Config.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import chalkbox.stages.codestyle.CodeStyle;
88
import chalkbox.stages.conformance.Conformance;
99
import chalkbox.stages.mutation.Mutation;
10+
import chalkbox.stages.pracdemos.PracDemo;
1011
import chalkbox.stages.tlc.TLC;
1112
import org.github.gestalt.config.Gestalt;
1213
import org.github.gestalt.config.builder.GestaltBuilder;
@@ -76,6 +77,14 @@ public Functionality toFunctionality() throws ConfigException {
7677
}
7778
}
7879

80+
public PracDemo toPracDemo() throws ConfigException {
81+
return new PracDemo(
82+
gestalt.getConfig("pracdemo.weighting", 100.0, Double.class),
83+
gestalt.getConfig("pracdemo.showPassing", true, Boolean.class),
84+
gestalt.getConfig("pracdemo.allVisible", false, Boolean.class)
85+
);
86+
}
87+
7988
public Mutation toMutation() throws ConfigException {
8089
try {
8190
return new Mutation(

src/main/java/chalkbox/stages/pracdemos/PracDemo.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010

1111
import java.io.File;
1212
import java.io.IOException;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
1315
import java.util.*;
1416

17+
/**
18+
* The practical demonstration stage differs from the Functionality stage
19+
* in that test classes are read from a tasks file included in the submission
20+
* as each student will have a different subset of test classes.
21+
*/
22+
// TODO: This should really share as much of Functionality as possible
1523
public class PracDemo implements Stage {
1624

17-
public final static String name = "Functionality";
25+
public final static String name = "PracDemo";
1826

1927
private final double maxScore;
2028
private final boolean showPassing;
@@ -104,10 +112,16 @@ public StageResult run(Submission submission, Solution solution) throws StageExc
104112
var totalNumTests = 0;
105113
var innerResults = new ArrayList<Result>();
106114
var classResults = new ArrayList<ClassResult>();
107-
for (String className : tests) {
108-
if (!className.endsWith("Test")) {
109-
continue;
110-
}
115+
116+
List<String> testNames;
117+
try {
118+
Path taskFile = Path.of(submission.getBasePath() + "/tasks");
119+
testNames = Files.readAllLines(taskFile);
120+
} catch (IOException e) {
121+
throw new StageException("Unable to find tasks file");
122+
}
123+
for (String className : testNames) {
124+
className = "demos." + className + "Test";
111125

112126
int classPassing = 0;
113127

@@ -171,9 +185,10 @@ public StageResult run(Submission submission, Solution solution) throws StageExc
171185
}
172186
double scaled = Math.ceil((total / possible) * maxScore);
173187

174-
var equation = "\n$$\n\\dfrac{" + String.format("%.3f", total) + "}{" + possible + "} \\times " + maxScore + " = " + scaled + "\n$$";
188+
//var equation = "\n$$\n\\dfrac{" + String.format("%.3f", total) + "}{" + possible + "} \\times " + maxScore + " = " + scaled + "\n$$";
189+
var equation = "\n$$sum = "+total+"$$";
175190
var overview = new Result(name);
176-
overview.setScore(scaled)
191+
overview.setScore(total)
177192
.setMaxScore(maxScore)
178193
.appendOutput(table + equation)
179194
.setOutputFormat("md")

0 commit comments

Comments
 (0)