Skip to content

Commit ea727c3

Browse files
meisterTnickygerritsen
authored andcommitted
Prefer english name if available.
1 parent b3ff3d7 commit ea727c3

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

webapp/src/Entity/Problem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Problem extends BaseApiEntity implements
5252

5353
#[ORM\Column(options: ['comment' => 'Descriptive name'])]
5454
#[Assert\NotBlank]
55-
private string $name;
55+
private string $name = 'Unknown name';
5656

5757
#[ORM\Column(options: [
5858
'comment' => 'Maximum run time (in seconds) for this problem',

webapp/src/Service/ImportProblemService.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,14 @@ public static function parseYaml(bool|string $problemYaml, array &$messages, str
10061006
$yamlProblemProperties = [];
10071007
if (isset($yamlData['name'])) {
10081008
if (is_array($yamlData['name'])) {
1009-
foreach ($yamlData['name'] as $name) {
1010-
// TODO: select a specific instead of the first language.
1011-
$yamlProblemProperties['name'] = $name;
1012-
break;
1009+
// Prefer english name, but if not available, use first name.
1010+
$englishOrFirstName = null;
1011+
foreach ($yamlData['name'] as $lang => $name) {
1012+
if ($englishOrFirstName === null || $lang === 'en') {
1013+
$englishOrFirstName = $name;
1014+
}
10131015
}
1016+
$yamlProblemProperties['name'] = $englishOrFirstName;
10141017
} else {
10151018
$yamlProblemProperties['name'] = $yamlData['name'];
10161019
}

webapp/tests/Unit/Service/ImportProblemServiceTest.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testEmptyYaml()
2323

2424
$ret = ImportProblemService::parseYaml($yaml, $messages, $validationMode, PropertyAccess::createPropertyAccessor(), $problem);
2525
$this->assertTrue($ret);
26-
$this->assertEquals('', $problem->getName());
26+
$this->assertEquals('Unknown name', $problem->getName());
2727
}
2828

2929
public function testMinimalYamlTest()
@@ -248,4 +248,55 @@ public function testMaximalProblem() {
248248
$this->assertEquals(3, $problem->getMultipassLimit());
249249
$this->assertEquals('special flags', $problem->getSpecialCompareArgs());
250250
}
251+
252+
public function testMultipleLanguages() {
253+
$yaml = <<<YAML
254+
name:
255+
de: deutsch
256+
en: english
257+
YAML;
258+
$messages = [];
259+
$validationMode = 'xxx';
260+
$problem = new Problem();
261+
262+
$ret = ImportProblemService::parseYaml($yaml, $messages, $validationMode, PropertyAccess::createPropertyAccessor(), $problem);
263+
$this->assertTrue($ret);
264+
$this->assertEmpty($messages);
265+
$this->assertEquals('english', $problem->getName());
266+
}
267+
268+
public function testKattisExample()
269+
{
270+
$yaml = <<<YAML
271+
problem_format_version: 2023-07-draft
272+
uuid: 5ca6ba5b-36d5-4eff-8aa7-d967cbc4375e
273+
source: Kattis
274+
license: cc by-sa
275+
276+
type: interactive
277+
name:
278+
en: Guess the Number
279+
sv: Gissa talet
280+
281+
# Override standard limits: say that the TLE solutions provided should
282+
# be at least 4 times above the time limit in order for us to be
283+
# happy.
284+
limits:
285+
time_multipliers:
286+
time_limit_to_tle: 4
287+
YAML;
288+
$messages = [];
289+
$validationMode = 'xxx';
290+
$problem = new Problem();
291+
292+
$ret = ImportProblemService::parseYaml($yaml, $messages, $validationMode, PropertyAccess::createPropertyAccessor(), $problem);
293+
$this->assertTrue($ret);
294+
$this->assertEmpty($messages);
295+
$this->assertEquals('Guess the Number', $problem->getName());
296+
$this->assertEquals('pass-fail, interactive', $problem->getTypesAsString());
297+
$this->assertEquals('default', $validationMode);
298+
$this->assertEquals(0, $problem->getTimelimit());
299+
$this->assertEquals(null, $problem->getMemlimit());
300+
$this->assertEquals(null, $problem->getOutputlimit());
301+
}
251302
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy