Skip to content

Commit

Permalink
Programming exercises: Fix visible testid if the task name is also a …
Browse files Browse the repository at this point in the history
…test name (#7703)
  • Loading branch information
Strohgelaender authored Dec 4, 2023
1 parent d3cf5d0 commit b16f5c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,15 @@ private String replaceTaskTests(String problemStatement, Set<ProgrammingExercise
Matcher matcher = TASK_PATTERN.matcher(problemStatement);

return matcher.replaceAll(matchResult -> {
// matchResult is fa full task, e.g., [task][Bubble Sort](testBubbleSort,testClass[BubbleSort])
String fullMatch = matchResult.group();
// group 1: task name, group 2: test names, e.g, testBubbleSort,testClass[BubbleSort]
String taskName = matchResult.group(1);
String testNames = matchResult.group(2);

// converted testids, e.g., <testid>10</testid>,<testid>12</testid>
String testIds = replacer.apply(testNames, testCases);

// replace the names with their ids
return fullMatch.replace(testNames, testIds);
// construct a new task using the testids
return "[task][%s](%s)".formatted(taskName, testIds);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,30 @@ void testNameReplacementOnlyWithinTasks() {
programmingExerciseTaskService.replaceTestNamesWithIds(programmingExercise);
String problemStatement = programmingExercise.getProblemStatement();

assertThat(problemStatement).contains("[task][Taskname](<testid>%s</testid>,<testid>%s</testid>".formatted(test1.getId(), test2.getId()))
assertThat(problemStatement).contains("[task][Taskname](<testid>%s</testid>,<testid>%s</testid>)".formatted(test1.getId(), test2.getId()))
.contains("This description contains the words test and taskTest, which should not be replaced.");
}

@Test
void testNameReplacementTaskNameSameAsTestName() {
var sort = programmingExerciseUtilService.addTestCaseToProgrammingExercise(programmingExercise, "sort");

updateProblemStatement("""
[task][sort](sort)
Sort using the method sort.
@startuml
class LinkedList<T> {
<color:testsColor(sort)>+ sort()</color>
}
@enduml""");

programmingExerciseTaskService.replaceTestNamesWithIds(programmingExercise);
String problemStatement = programmingExercise.getProblemStatement();

assertThat(problemStatement).contains("[task][sort](<testid>%s</testid>)".formatted(sort.getId())).contains("Sort using the method sort.")
.contains("<color:testsColor(<testid>%s</testid>)>+ sort()</color>".formatted(sort.getId()));
}

@Test
void testIdReplacementWithNames() {
var bubbleSort = programmingExerciseTestCaseRepository.findByExerciseIdAndTestName(programmingExercise.getId(), "testClass[BubbleSort]").orElseThrow();
Expand Down

0 comments on commit b16f5c1

Please sign in to comment.