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

Commit df7beb3

Browse files
committed
🐛 Fix unittest
1 parent b7cfe16 commit df7beb3

4 files changed

Lines changed: 51 additions & 39 deletions

File tree

runestone/hparsons/hparsons.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def setup(app):
4848

4949
TEMPLATE_END = """
5050
</div>
51-
<div>%(instructions)s</div>
52-
<div class="hparsons" %(textentry)s %(nostrictmatch)s %(hidetests)s>
51+
<div class="hparsons" %(textentry)s %(nostrictmatch)s %(hidetests)s %(type)s>
5352
<pre>%(settings)s</pre>
5453
</div>
5554
</div>
@@ -178,9 +177,11 @@ def run(self):
178177

179178
if '--problem--' in sorted_delimiters:
180179
index = sorted_delimiters.index('--problem--')
181-
self.options['instructions'] = '\n'.join(content[(sorted_index[index] + 1): (sorted_index[index + 1] if index + 1 < len(sorted_index) else len(content))])
180+
self.options['instructions'] = content[(sorted_index[index] + 1): (sorted_index[index + 1] if index + 1 < len(sorted_index) else len(content))]
181+
self.options['problem'] = '\n'.join(content[(sorted_index[index] + 1): (sorted_index[index + 1] if index + 1 < len(sorted_index) else len(content))])
182182
else:
183-
self.options['instructions'] = 'empty problem'
183+
self.options['instructions'] = ['empty problem']
184+
self.options['problem'] = 'empty problem'
184185

185186
if '--blocks--' in sorted_delimiters:
186187
index = sorted_delimiters.index('--blocks--')
@@ -212,6 +213,7 @@ def run(self):
212213
index += 2
213214

214215
self.options['settings'] = json.dumps(parsons_settings)
216+
self.options['type'] = type(self.options['instructions'])
215217

216218
# same
217219
maybeAddToAssignment(self)
@@ -229,9 +231,9 @@ def run(self):
229231
# TODO: fix the nested parse
230232
# same as mchoice, different from parsons. i think it is for generating instructions.
231233
# parsons:
232-
# self.state.nested_parse(
233-
# self.options['instructions'], self.content_offset, hparsons_node
234-
# )
234+
self.state.nested_parse(
235+
self.options['instructions'], self.content_offset, hparsons_node
236+
)
235237

236238

237239
# same

runestone/hparsons/js/hparsons.js

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ export default class HParsons extends RunestoneBase {
8787
regexElement.setNegativeInitialTestString(settings.negativetest);
8888
}
8989
if (settings.testcases) {
90+
for (let index in settings.testcases) {
91+
settings.testcases[index].expect = settings.testcases[index].expect.length < 4 ? [] : settings.testcases[index].expect.slice(2, -2).split(', ');
92+
console.log(settings.testcases[index])
93+
}
9094
regexElement.setTestCases(settings.testcases);
9195
}
9296

@@ -126,48 +130,35 @@ export default class HParsons extends RunestoneBase {
126130
}
127131

128132
renderFeedback() {
129-
console.log('hparsons, renderfeedback')
133+
// console.log('hparsons, renderfeedback')
130134
// this.feedbackDiv.innerHTML = "Your answer has been saved.";
131135
// $(this.feedbackDiv).removeClass("alert-danger");
132136
// $(this.feedbackDiv).addClass("alert alert-success");
133137
}
134138
setLocalStorage(data) {
135-
console.log('hparsons, setlocalstorage')
139+
// console.log('hparsons, setlocalstorage')
136140
// if (!this.graderactive) {
137141
// let key = this.localStorageKey();
138142
// localStorage.setItem(key, JSON.stringify(data));
139143
// }
140144
}
141145
checkLocalStorage() {
142146
console.log('hparsons, checklocalstorage')
143-
// Repopulates the short answer text
144-
// which was stored into local storage.
145-
// var answer = "";
146-
// if (this.graderactive) {
147-
// return;
148-
// }
149-
// var len = localStorage.length;
150-
// if (len > 0) {
151-
// var ex = localStorage.getItem(this.localStorageKey());
152-
// if (ex !== null) {
153-
// try {
154-
// var storedData = JSON.parse(ex);
155-
// answer = storedData.answer;
156-
// } catch (err) {
157-
// // error while parsing; likely due to bad value stored in storage
158-
// console.log(err.message);
159-
// localStorage.removeItem(this.localStorageKey());
160-
// return;
161-
// }
162-
// let solution = $("#" + this.divid + "_solution");
163-
// solution.text(answer);
164-
// this.renderMath(answer);
165-
// this.feedbackDiv.innerHTML =
166-
// "Your current saved answer is shown above.";
167-
// $(this.feedbackDiv).removeClass("alert-danger");
168-
// $(this.feedbackDiv).addClass("alert alert-success");
169-
// }
170-
// }
147+
var toStore;
148+
if (data == undefined) {
149+
toStore = {
150+
source: this.sourceHash(),
151+
answer: this.answerHash(),
152+
timestamp: new Date(),
153+
};
154+
var adaptiveHash = this.adaptiveHash();
155+
if (adaptiveHash.length > 0) {
156+
toStore.adaptive = adaptiveHash;
157+
}
158+
} else {
159+
toStore = data;
160+
}
161+
localStorage.setItem(this.storageId, JSON.stringify(toStore));
171162
}
172163
restoreAnswers(data) {
173164
console.log('hparsons, restoreanswers')

runestone/hparsons/js/regex-element.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16078,7 +16078,6 @@ class UnitTestTable {
1607816078
row.innerHTML += this._getRevealedRow(this.testCases[index], this.latestResults[index]);
1607916079
};
1608016080
setTestCases = (testCases) => {
16081-
console.log('unittest 242');
1608216081
this.testCases = testCases;
1608316082
// TODO: make this an option. Set all revealed for study 0 and 1.
1608416083
this.hintRevealed = Array(testCases.length).fill(true);

runestone/hparsons/test/_sources/index.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ Horizontal Parsons + Regex
1414
Capture words that start with a vowel letter(aeiou), but ends with a non-vowel letter.
1515
There can be 0 or more letters in between.
1616
Also, it is not allowed to have other characters besides letter in between.
17+
18+
.. code-block:: python
19+
20+
sum = 0
21+
for i in range(10):
22+
sum = sum + i
23+
24+
print(sum)
25+
1726
e.g. your regular expression should match unicorn, element, but should not match: banana, apple. All letters are lowercase.
1827
--blocks--
1928
[a-z]
@@ -50,15 +59,26 @@ Horizontal Parsons + Regex
5059
['az']
5160
abcdefghizsdz
5261
['abcdefghizsdz']
53-
abc9defghizsdz'
62+
abc9defghizsdz
5463
[]
5564

5665

5766
.. hparsons:: codeexample2
5867
:textentry:
5968
:hidetests:
6069

70+
--problem--
71+
Capture words that start with a vowel letter(aeiou), but ends with a non-vowel letter.
72+
There can be 0 or more letters in between.
73+
Also, it is not allowed to have other characters besides letter in between.
74+
e.g. your regular expression should match unicorn, element, but should not match: banana, apple. All letters are lowercase.
6175
content content content
76+
--positive test string--
77+
unicorn
78+
element
79+
--negative test string--
80+
apple
81+
banana
6282

6383

6484
Other Problems for reference

0 commit comments

Comments
 (0)