Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 857f69d

Browse files
Fix indentation handling for DAG based Parsons problems
1 parent 491aca8 commit 857f69d

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

runestone/parsons/js/dagGrader.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ export default class DAGGrader extends LineBasedGrader {
9292
return indices;
9393
}
9494

95+
checkCorrectIndentation(solutionLines, answerLines) {
96+
this.indentLeft = [];
97+
this.indentRight = [];
98+
let loopLimit = Math.min(solutionLines.length, answerLines.length);
99+
for (let i = 0; i < loopLimit; i++) {
100+
let solutionIndex = answerLines[i].tag;
101+
if (answerLines[i].viewIndent() < solutionLines[solutionIndex].indent) {
102+
this.indentRight.push(answerLines[i]);
103+
} else if (answerLines[i].viewIndent() > solutionLines[solutionIndex].indent) {
104+
this.indentLeft.push(answerLines[i]);
105+
}
106+
}
107+
this.incorrectIndents =
108+
this.indentLeft.length + this.indentRight.length;
109+
110+
return this.incorrectIndents == 0;
111+
}
112+
95113
checkCorrectOrdering(solutionLines, answerLines) {
96114
if (!isDirectedAcyclicGraph(graphToNX(solutionLines))) {
97115
throw "Dependency between blocks does not form a Directed Acyclic Graph; Problem unsolvable.";

runestone/parsons/js/lineGrader.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,10 @@ export default class LineBasedGrader {
7575
let isCorrectOrder = this.checkCorrectOrdering(solutionLines, answerLines)
7676

7777
// Determine whether blocks are indented correctly
78-
this.indentLeft = [];
79-
this.indentRight = [];
80-
let loopLimit = Math.min(solutionLines.length, answerLines.length);
81-
for (i = 0; i < loopLimit; i++) {
82-
if (answerLines[i].viewIndent() < solutionLines[i].indent) {
83-
this.indentRight.push(answerLines[i]);
84-
} else if (answerLines[i].viewIndent() > solutionLines[i].indent) {
85-
this.indentLeft.push(answerLines[i]);
86-
}
87-
}
88-
this.incorrectIndents =
89-
this.indentLeft.length + this.indentRight.length;
78+
let isCorrectIndents = this.checkCorrectIndentation(solutionLines, answerLines);
79+
9080
if (
91-
this.incorrectIndents == 0 &&
81+
isCorrectIndents &&
9282
isCorrectOrder &&
9383
this.correctLength
9484
) {
@@ -105,6 +95,23 @@ export default class LineBasedGrader {
10595
return state;
10696
}
10797

98+
checkCorrectIndentation(solutionLines, answerLines) {
99+
this.indentLeft = [];
100+
this.indentRight = [];
101+
let loopLimit = Math.min(solutionLines.length, answerLines.length);
102+
for (let i = 0; i < loopLimit; i++) {
103+
if (answerLines[i].viewIndent() < answerLines[i].indent) {
104+
this.indentRight.push(answerLines[i]);
105+
} else if (answerLines[i].viewIndent() > solutionLines[i].indent) {
106+
this.indentLeft.push(answerLines[i]);
107+
}
108+
}
109+
this.incorrectIndents =
110+
this.indentLeft.length + this.indentRight.length;
111+
112+
return this.incorrectIndents == 0;
113+
}
114+
108115
checkCorrectOrdering(solutionLines, answerLines) {
109116
let isCorrectOrder = true;
110117
this.correctLines = 0;

0 commit comments

Comments
 (0)