|
5 | 5 | ) |
6 | 6 |
|
7 | 7 | MISSING_FILE = "You are missing the {filename} file." |
8 | | -COMMITS_UNREVERTED = "You have not reverted the commits yet!" |
| 8 | +COMMITS_UNREVERTED = "You have not reverted all the commits yet!" |
9 | 9 | COMMITS_REVERTED_WRONG_ORDER = "You have reverted the commits in the wrong order!" |
10 | 10 | INCORRECT_READINGS = "The files contain the wrong readings!" |
11 | | -NO_REVERT_COMMIT = "You have not performed the changes through revert commits!" |
12 | 11 |
|
13 | 12 | EXPECTED_EAST = ( |
14 | 13 | "4821\n9304\n1578\n6042\n7189\n2463\n8931\n5710\n4428\n3097\n8652\n1904\n7485\n6379\n5140\n9836\n2057\n4719\n3568\n8243\n" |
|
23 | 22 | "5193\n8042\n6721\n4389\n2075\n9510\n3648\n7281\n5904\n1837\n4416\n9032\n7765\n6208\n3589\n8471\n2940\n1683\n7352\n5129\n" |
24 | 23 | ) |
25 | 24 |
|
26 | | -UNREVERTED_EAST = EXPECTED_EAST.replace("7485", "7285") |
27 | | -UNREVERTED_NORTH = EXPECTED_NORTH.replace("8501", "8301") |
28 | | -# Unreverted South and West are equivalent to expected South and West |
29 | | - |
30 | | -# Reverting East and North in the wrong order leads to the same result |
31 | | -WRONG_ORDER_REVERT_SOUTH = EXPECTED_SOUTH.replace("4530", "4330") |
32 | | -WRONG_ORDER_REVERT_WEST = EXPECTED_WEST.replace("3648", "3638") |
33 | | - |
34 | 25 |
|
35 | 26 | def verify(exercise: GitAutograderExercise) -> GitAutograderOutput: |
36 | 27 | comments = [] |
@@ -62,24 +53,28 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput: |
62 | 53 | if comments: |
63 | 54 | raise exercise.wrong_answer(comments) |
64 | 55 |
|
65 | | - if (east_contents == UNREVERTED_EAST |
66 | | - and north_contents == UNREVERTED_NORTH): |
| 56 | + branch = exercise.repo.branches.branch("main") |
| 57 | + commit_messages = [str(c.commit.message.strip()) for c in branch.commits] |
| 58 | + commit_messages.reverse() |
| 59 | + |
| 60 | + reverted_14th = False |
| 61 | + reverted_13th = False |
| 62 | + for m in commit_messages[-4:]: |
| 63 | + if not reverted_14th and 'Revert "Record data for Jan 14"' in m: |
| 64 | + reverted_14th = True |
| 65 | + if not reverted_13th and 'Revert "Record data for Jan 13"' in m: |
| 66 | + if not reverted_14th: |
| 67 | + raise exercise.wrong_answer([COMMITS_REVERTED_WRONG_ORDER]) |
| 68 | + reverted_13th = True |
| 69 | + break |
| 70 | + |
| 71 | + if not (reverted_14th and reverted_13th): |
67 | 72 | raise exercise.wrong_answer([COMMITS_UNREVERTED]) |
68 | 73 |
|
69 | | - if (south_contents == WRONG_ORDER_REVERT_SOUTH |
70 | | - and west_contents == WRONG_ORDER_REVERT_WEST): |
71 | | - raise exercise.wrong_answer([COMMITS_REVERTED_WRONG_ORDER]) |
72 | | - |
73 | 74 | if not (east_contents == EXPECTED_EAST |
74 | 75 | and north_contents == EXPECTED_NORTH |
75 | 76 | and south_contents == EXPECTED_SOUTH |
76 | 77 | and west_contents == EXPECTED_WEST): |
77 | 78 | raise exercise.wrong_answer([INCORRECT_READINGS]) |
78 | 79 |
|
79 | | - commits = exercise.repo.branches.branch("main").commits |
80 | | - |
81 | | - if ("Revert" not in commits[0].commit.message |
82 | | - or "Revert" not in commits[1].commit.message): |
83 | | - raise exercise.wrong_answer([NO_REVERT_COMMIT]) |
84 | | - |
85 | 80 | return exercise.to_output(["Good work reverting commits!"], GitAutograderStatus.SUCCESSFUL) |
0 commit comments