Skip to content

Commit b3ff3d7

Browse files
meisterTnickygerritsen
authored andcommitted
Default to pass-fail problem type if not explicitly set.
1 parent a3e3b29 commit b3ff3d7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

webapp/src/Entity/Problem.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ public function setTypes(array $types): Problem
338338
foreach ($types as $type) {
339339
$this->types |= $type;
340340
}
341-
if (!($this->types & self::TYPE_PASS_FAIL) xor ($this->types & self::TYPE_SCORING)) {
341+
if (!($this->types & self::TYPE_SCORING)) {
342+
// In case the problem is not explicitly a scoring problem, default to pass-fail.
343+
$this->types |= self::TYPE_PASS_FAIL;
344+
}
345+
if (($this->types & self::TYPE_PASS_FAIL) && ($this->types & self::TYPE_SCORING)) {
342346
throw new Exception("Invalid problem type: must be exactly one of 'pass-fail' or 'scoring'.");
343347
}
344348
if ($this->types & self::TYPE_SUBMIT_ANSWER) {

webapp/tests/Unit/Service/ImportProblemServiceTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public function testTypesYamlTest()
5858
foreach ([
5959
'pass-fail',
6060
'scoring',
61+
'multi-pass',
62+
'interactive',
63+
'submit-answer',
6164
'pass-fail multi-pass',
6265
'pass-fail interactive',
6366
'pass-fail submit-answer',
@@ -77,6 +80,10 @@ public function testTypesYamlTest()
7780
$ret = ImportProblemService::parseYaml($yaml, $messages, $validationMode, PropertyAccess::createPropertyAccessor(), $problem);
7881
$messageString = var_export($messages, true);
7982
$this->assertTrue($ret, 'Parsing failed for type: ' . $type . ', messages: ' . $messageString);
83+
if (in_array($type, ['interactive', 'multi-pass', 'submit-answer'])) {
84+
// Default to pass-fail if not explicitly set.
85+
$type = 'pass-fail ' . $type;
86+
}
8087
$typesString = str_replace(' ', ', ', $type);
8188
$this->assertEquals($typesString, $problem->getTypesAsString());
8289
}
@@ -100,11 +107,9 @@ public function testUnknownProblemType()
100107

101108
public function testInvalidProblemType() {
102109
foreach ([
103-
'interactive',
104-
'multi-pass',
105-
'submit-answer',
106-
'pass-fail submit-answer multi-pass',
107-
'pass-fail submit-answer interactive',
110+
'pass-fail scoring',
111+
'submit-answer multi-pass',
112+
'submit-answer interactive',
108113
] as $type) {
109114
$yaml = <<<YAML
110115
name: test

0 commit comments

Comments
 (0)