Skip to content

Commit

Permalink
Fix bug in parsing ASSESSMENT.md
Browse files Browse the repository at this point in the history
* Newlines after the assessment table has led to a parsing error
  • Loading branch information
jheinzel committed Feb 5, 2024
1 parent b61a918 commit 305176f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/TutorBot.Cli/Domain/Assessment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ int ReadLine(string content, int from, out string line)
return index + 1;
}

bool HasMoreTableLines(string content, int from)
{
ReadLine(content, from, out string line);
return !string.IsNullOrWhiteSpace(line) && line.TrimStart()[0] == '|';
}

int ReadTableLine(string content, int from, out string[] values)
{
int index = ReadLine(content, from, out string line);
Expand Down Expand Up @@ -211,7 +217,7 @@ bool TryParseHeaderEntry(string entry, out double weight)

var lines = new List<AssessmentLine>();

while (index < content.Length)
while (index < content.Length && HasMoreTableLines(content, index))
{
index = ReadTableLine(content, index, out string[] values);
if (values.Length != 5)
Expand Down
50 changes: 44 additions & 6 deletions src/TutorBot.Tests/AssessmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,76 @@ public class AssessmentTests
| 2 | 50 | 0 | 0 | 0 |
""";

// Has extra newlines at the end of the table
const string correct5 = """
# **SWO3-Übungen - WS2023/24 - Übungszettel 8 - Deckblatt**

const string wrong1 = """
Nachname und Vorname: Sorglos Susi

Aufwand [Stunden]: 10.0

## **Erfüllungsgrad**

| Beispiel | Gewichtung | Lösungsidee (15%) | Implement. (70%) | Testen (15%) |
| --------- | :---------: | :---------------: | :--------------: | :-------------: |
| 1 | 100 | 100 | 100 | 100 |



""";

const string wrong1 = """
# Erfüllungsgrad

Aufwand [Stunden]: 10.0

| Beispiel | Gewichtung | Lösungsidee (20%) | Implement. (70%) | Testen (10%) |
| --------- | :---------: | :---------------: | :--------------: | :----------: |
| 1 | 40 | 0 | 0 | 0 |
|
""";

const string wrong2 = """
Aufwand (in Stunden): 10.0
# Erfüllungsgrad

Aufwand [Stunden]: 10.0

| Beispiel | Gewichtung | Lösungsidee (20%) | Implement. (70%) |
| --------- | :---------: | :---------------: | :--------------: |
| 1 | 40 | 0 | 0 |
""";

const string wrong3 = """
# Erfüllungsgrad

Aufwand [Stunden]: 10.0

| Beispiel | Gewichtung | Lösungsidee (20%) | Implement. (xxx%) | Testen (10%) |
| --------- | :---------: | :---------------: | :--------------: | :----------: |
| 1 | 40 | 0 | 0 | 0 |
""";

const string wrong4 = """
# Erfüllungsgrad

Aufwand [Stunden]: 10.0

| Beispiel | Gewichtung | Lösungsidee (20%) | Implement. (70%) | Testen (10%) |
| --------- | :---------: | :---------------: | :--------------: | :----------: |
| 1 | 40 | 0 | xxx | 0 |
""";

const string wrong5 = """
# Erfüllungsgrad

Aufwand (in Stunden): 10.0

| Beispiel | Gewichtung | Lösungsidee (20%) | Implement. (70%) | Testen (10%) |
| --------- | :---------: | :---------------: | :--------------: | :----------: |
| 1 | 4xxx0 | 0 | xxx | 0 |
""";


[Fact]
[Fact]
public void Test_Assessment_Extensively()
{
Assessment assessment = new Assessment();
Expand Down Expand Up @@ -119,8 +155,9 @@ public void Test_Assessment_Extensively()
[InlineData(correct1, 10.5, 50.57)]
[InlineData(correct2, 10.0, 100)]
[InlineData(correct3, 0.0, 0.0)]
[InlineData(correct4, 10.0, 50.0)]
public void Assessment_ShouldBe_Correct(string content, double effort, double totalGrading)
[InlineData(correct4, 10.0, 50.0)]
[InlineData(correct5, 10.0, 100.0)]
public void Assessment_ShouldBe_Correct(string content, double effort, double totalGrading)
{
var assessment = new Assessment();
assessment.LoadFromString(content);
Expand All @@ -138,6 +175,7 @@ public void Assessment_ShouldBe_Correct(string content, double effort, double to
[InlineData(wrong3)]
[InlineData(wrong4)]
[InlineData(wrong5)]

public void Assessment_ShouldBe_ThrowExcecption(string content)
{
var assessment = new Assessment();
Expand Down
2 changes: 1 addition & 1 deletion src/TutorBot.Tests/AssignReviewersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public async Task AssignmentOfProposedReviewers_IsCorrectlyIntegratedIntoSubmiss

private Repository CreateRepository(int id, string repoName)
{
return new Repository("", htmlUrl: $"https://{repoName}", "", "", "", "", "", id, "", owner: null, repoName, $"swo3/{repoName}", false, "", "", "", true, false, 0, 0, "", 0, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, permissions: null, null, null, null, false, false, false, false, false, 0, 0, false, false, false, false, 0, false, RepositoryVisibility.Private, Enumerable.Empty<string>(), null, null, null);
return new Repository("", htmlUrl: $"https://{repoName}", "", "", "", "", "", "", id, "", owner: null, repoName, $"swo3/{repoName}", false, "", "", "", true, false, 0, 0, "", 0, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, permissions: null, null, null, null, false, false, false, false, false, 0, 0, false, false, false, false, 0, false, RepositoryVisibility.Private, Enumerable.Empty<string>(), null, null, null);
}

private IList<Student> CreateStudentList(int n)
Expand Down
2 changes: 1 addition & 1 deletion src/TutorBot.Tests/AssignmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ public async Task SimpleAssignment_With_Reviewers_IsLoadedCorrectly()

private Repository CreateRepository(int id, string repoName)
{
return new Repository("", htmlUrl: $"https://{repoName}", "", "", "", "", "", id, "", owner: null, repoName, $"swo3/{repoName}", false, "", "", "", true, false, 0, 0, "", 0, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, permissions: null, null, null, null, false, false, false, false, false, 0, 0, false, false, false, false, 0, false, RepositoryVisibility.Private, Enumerable.Empty<string>(), null, null, null);
return new Repository("", htmlUrl: $"https://{repoName}", "", "", "", "", "", "", id, "", owner: null, repoName, $"swo3/{repoName}", false, "", "", "", true, false, 0, 0, "", 0, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, permissions: null, null, null, null, false, false, false, false, false, 0, 0, false, false, false, false, 0, false, RepositoryVisibility.Private, Enumerable.Empty<string>(), null, null, null);
}
}

0 comments on commit 305176f

Please sign in to comment.