Skip to content

Commit

Permalink
Give 0 for automated style if submission doesn't compile
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcmiller committed May 3, 2021
1 parent cfc792e commit 237f068
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Run Gradle Test
uses: eskatos/gradle-command-action@v1
with:
arguments: test
arguments: test --stacktrace --debug
37 changes: 22 additions & 15 deletions src/chalkbox/java/checkstyle/Checkstyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ public Checkstyle(CheckstyleOptions options) {
public Collection run(Collection collection) {
Data feedback = collection.getResults();

JSONArray tests = (JSONArray) feedback.get("tests");
Data result = new Data();
result.set("name", "Automated Style");

// if submission didn't compile, give 0 marks for automated style
if (!feedback.is("extra_data.compilation.compiles")) {
result.set("score", 0);
result.set("max_score", options.weighting);
result.set("output", "Submission did not compile, not checking automated style");
tests.add(result);
return collection;
}

// execute the checkstyle jar on the src directory
ProcessExecution process;
try {
Expand All @@ -148,20 +161,13 @@ public Collection run(Collection collection) {
processArgs.toArray(String[]::new));
} catch (IOException e) {
e.printStackTrace();
// TODO improve how this is done, maybe refactor Data
JSONArray tests = (JSONArray) feedback.get("tests");
Data result = new Data();
result.set("name", "Automated Style");
result.set("score", 0);
result.set("max_score", options.weighting);
result.set("output", "IOError when running Checkstyle");
tests.add(result);
return collection;
} catch (TimeoutException e) {
e.printStackTrace();
JSONArray tests = (JSONArray) feedback.get("tests");
Data result = new Data();
result.set("name", "Automated Style");
result.set("score", 0);
result.set("max_score", options.weighting);
result.set("output", "Timed out when running Checkstyle");
Expand All @@ -175,19 +181,20 @@ public Collection run(Collection collection) {
// replace the base path to make output easier to read
String checkstyleOutput = process.getOutput().replace(basePath, "");

// if Checkstyle didn't exit successfully, give 0 marks for automated style
if (!checkstyleOutput.contains("Audit done.")) {
result.set("score", 0);
result.set("max_score", options.weighting);
result.set("output", "Checkstyle did not exit successfully");
tests.add(result);
return collection;
}

// count violations based on lines in output
// subtract 2 for header/footer lines
int numViolations = Math.max(0,
checkstyleOutput.split("\n").length - 2);

// if Checkstyle didn't exit successfully, give 0 marks for automated style
if (!checkstyleOutput.contains("Audit done.")) {
numViolations = Integer.MAX_VALUE; // many violations -> 0 marks
}

JSONArray tests = (JSONArray) feedback.get("tests");
Data result = new Data();
result.set("name", "Automated Style");
result.set("score", Math.max(0,
options.weighting - numViolations * options.violationPenalty));
result.set("max_score", options.weighting);
Expand Down
2 changes: 1 addition & 1 deletion test/resources/csse1001/results/results.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"output": "/------------------------------------------------------------------------------\\\n| Summary of Results |\n\\------------------------------------------------------------------------------/\nTestDesign: 2/3\n + 1. test no prints on import\n + 2. test all functions are defined correctly\n - 3. test all functions have documentation strings\nTestSelectWordAtRandom: 5/5\n + 1. test select random word from fixed\n + 2. test select random word from arbitrary\n + 3. test select random word from fixed 2\n + 4. test select random word from arbitrary 2\n + 5. test invalid word_select returns None\nTestCreateGuessLine: 5/5\n + 1. test guess 1 length 6\n + 2. test guess 1 length 9\n + 3. test guess 6 length 6\n + 4. test guess 9 length 9\n + 5. test guess 4 length 7\nTestDisplayGuessMatrix: 4/4\n + 1. test display_guess_matrix guess 1 length 6\n + 2. test display_guess_matrix guess 2 length 6\n + 3. test display_guess_matrix guess 3 length 6\n + 4. test display_guess_matrix guess 9 length 9\nTestComputeValueForGuess: 7/7\n + 1. test no score\n + 2. test vowel match wrong index\n + 3. test vowel match index\n + 4. test consonant match wrong index\n + 5. test consonant match index\n + 6. test multiple matches\n + 7. test guess in word not substring\nTestMain: 8/8\n + 1. test main help action\n + 2. test quit action\n + 3. test invalid action\n + 4. test invalid action\n + 5. test main FIXED win\n + 6. test main ARBITRARY win\n + 7. test main FIXED lose\n + 8. test main FIXED with invalid length\nTestNoPrint: 1/1\n + check for no unexpected prints\n--------------------------------------------------------------------------------\n/------------------------------------------------------------------------------\\\n| Failed/Skipped Tests |\n\\------------------------------------------------------------------------------/\n================================================================================\nFAIL: TestDesign 3. test all functions have documentation strings\n--------------------------------------------------------------------------------\n Traceback (most recent call last):\n File \"test_a1.py\", line 72, in test_doc_strings\n self.aggregate_tests()\n AssertionError: \n Documentation string is required for 'create_line_separator'\n Documentation string is required for 'create_top_line'\n Documentation string is required for 'game'\n\n--------------------------------------------------------------------------------\nRan 33 tests with 32 passed/0 skipped/1 failed.\n", "score": 32, "tests": [{"name": "TestDesign", "score": 2, "max_score": 3, "output": "1. test_functions_defined : +\n2. test_clean_import : +\n3. test_doc_strings : -\n", "visibility": "visible"}, {"name": "TestCreateGuessLine", "score": 5, "max_score": 5, "output": "1. test_1_6 : +\n2. test_4_7 : +\n3. test_1_9 : +\n4. test_6_6 : +\n5. test_9_9 : +\n", "visibility": "visible"}, {"name": "TestMain", "score": 8, "max_score": 8, "output": "1. test_invalid : +\n2. test_main_arbitrary_win : +\n3. test_main_fixed_win : +\n4. test_main_fixed_lose : +\n5. test_invalid_multiple : +\n6. test_quit : +\n7. test_main_fixed_invalid_length : +\n8. test_help : +\n", "visibility": "after_published"}, {"name": "TestDisplayGuessMatrix", "score": 4, "max_score": 4, "output": "1. test_display_01 : +\n2. test_display_04 : +\n3. test_display_03 : +\n4. test_display_02 : +\n", "visibility": "after_published"}, {"name": "TestNoPrint", "score": 1, "max_score": 1, "output": "1. runTest : +\n", "visibility": "after_published"}, {"name": "TestSelectWordAtRandom", "score": 5, "max_score": 5, "output": "1. test_select_fixed_2 : +\n2. test_none : +\n3. test_select_fixed : +\n4. test_select_arbitrary_2 : +\n5. test_select_arbitrary : +\n", "visibility": "visible"}, {"name": "TestComputeValueForGuess", "score": 7, "max_score": 7, "output": "1. test_vowel_match_index : +\n2. test_no_score : +\n3. test_consonant_match_index : +\n4. test_vowel_match_wrong_index : +\n5. test_multiple_match : +\n6. test_guess_in_word_no_substring : +\n7. test_consonant_match_wrong_index : +\n", "visibility": "after_published"}]}
{"output":"","tests":[],"test":{}}
Loading

0 comments on commit 237f068

Please sign in to comment.