Skip to content

Commit c77f03d

Browse files
authored
[sensors-checkout] Implement exercise T4L4/sensors-checkout (#155)
# Exercise Review ## Exercise Discussion Fixes #144 ## Checklist - [ ] If you require a new remote repository on the `Git-Mastery` organization, have you [created a request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.md) for it? - [X] Have you written unit tests using [`repo-smith`](https://github.com/git-mastery/repo-smith) to validate the exercise grading scheme? - [X] Have you tested the download script using `test-download.sh`? - [X] Have you verified that this exercise does not already exist or is not currently in review? - [ ] Did you introduce a new grading mechanism that should belong to [`git-autograder`](https://github.com/git-mastery/git-autograder)? - [ ] Did you introduce a new dependency that should belong to [`app`](https://github.com/git-mastery/app)?
1 parent ef6a8f0 commit c77f03d

File tree

9 files changed

+194
-0
lines changed

9 files changed

+194
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"exercise_name": "sensors-checkout",
3+
"tags": [
4+
"git-checkout"
5+
],
6+
"requires_git": true,
7+
"requires_github": true,
8+
"base_files": {},
9+
"exercise_repo": {
10+
"repo_type": "remote",
11+
"repo_name": "sensors",
12+
"repo_title": "gm-sensors",
13+
"create_fork": false,
14+
"init": null
15+
}
16+
}

sensors_checkout/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See https://git-mastery.github.io/lessons/checkout/exercise-sensors-checkout.html

sensors_checkout/__init__.py

Whitespace-only changes.

sensors_checkout/download.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def setup(verbose: bool = False): ...

sensors_checkout/res/answers.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Q: What's sum of values in south.csv on Jan 11th?
2+
A:
3+
4+
Q: What's sum of values in west.csv on Jan 09th?
5+
A:
6+
7+
Q: What's sum of values in north.csv on Jan 05th?
8+
A:

sensors_checkout/tests/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
from git_autograder.answers.rules.not_empty_rule import NotEmptyRule
2+
from git_autograder.answers.rules.has_exact_value_rule import HasExactValueRule
3+
from git_autograder.status import GitAutograderStatus
4+
from git_autograder.test_utils import assert_output
5+
from git_autograder import GitAutograderTestLoader
6+
7+
from ..verify import (
8+
QUESTION_ONE,
9+
QUESTION_TWO,
10+
QUESTION_THREE,
11+
CORRECT_ANSWER_Q1,
12+
CORRECT_ANSWER_Q2,
13+
CORRECT_ANSWER_Q3,
14+
SUCCESS_MESSAGE,
15+
verify,
16+
)
17+
18+
REPOSITORY_NAME = "sensors-checkout"
19+
20+
loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)
21+
22+
INCORRECT_ANSWER = "incorrect answer"
23+
24+
25+
def test_correct_answers():
26+
with loader.load(
27+
"specs/base.yml",
28+
mock_answers={
29+
QUESTION_ONE: CORRECT_ANSWER_Q1,
30+
QUESTION_TWO: CORRECT_ANSWER_Q2,
31+
QUESTION_THREE: CORRECT_ANSWER_Q3,
32+
},
33+
) as output:
34+
assert_output(output, GitAutograderStatus.SUCCESSFUL, [SUCCESS_MESSAGE])
35+
36+
37+
def test_incomplete_answers():
38+
with loader.load(
39+
"specs/base.yml",
40+
mock_answers={
41+
QUESTION_ONE: CORRECT_ANSWER_Q1,
42+
QUESTION_TWO: CORRECT_ANSWER_Q2,
43+
QUESTION_THREE: "",
44+
},
45+
) as output:
46+
assert_output(
47+
output,
48+
GitAutograderStatus.UNSUCCESSFUL,
49+
[
50+
NotEmptyRule.EMPTY.format(question=QUESTION_THREE),
51+
],
52+
)
53+
54+
55+
def test_no_answers():
56+
with loader.load(
57+
"specs/base.yml",
58+
mock_answers={
59+
QUESTION_ONE: "",
60+
QUESTION_TWO: "",
61+
QUESTION_THREE: "",
62+
},
63+
) as output:
64+
assert_output(
65+
output,
66+
GitAutograderStatus.UNSUCCESSFUL,
67+
[
68+
NotEmptyRule.EMPTY.format(question=QUESTION_ONE),
69+
NotEmptyRule.EMPTY.format(question=QUESTION_TWO),
70+
NotEmptyRule.EMPTY.format(question=QUESTION_THREE),
71+
],
72+
)
73+
74+
75+
def test_incorrect_q1():
76+
with loader.load(
77+
"specs/base.yml",
78+
mock_answers={
79+
QUESTION_ONE: INCORRECT_ANSWER,
80+
QUESTION_TWO: CORRECT_ANSWER_Q2,
81+
QUESTION_THREE: CORRECT_ANSWER_Q3,
82+
},
83+
) as output:
84+
assert_output(
85+
output,
86+
GitAutograderStatus.UNSUCCESSFUL,
87+
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_ONE)],
88+
)
89+
90+
91+
def test_incorrect_q2():
92+
with loader.load(
93+
"specs/base.yml",
94+
mock_answers={
95+
QUESTION_ONE: CORRECT_ANSWER_Q1,
96+
QUESTION_TWO: INCORRECT_ANSWER,
97+
QUESTION_THREE: CORRECT_ANSWER_Q3,
98+
},
99+
) as output:
100+
assert_output(
101+
output,
102+
GitAutograderStatus.UNSUCCESSFUL,
103+
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_TWO)],
104+
)
105+
106+
107+
def test_incorrect_q3():
108+
with loader.load(
109+
"specs/base.yml",
110+
mock_answers={
111+
QUESTION_ONE: CORRECT_ANSWER_Q1,
112+
QUESTION_TWO: CORRECT_ANSWER_Q2,
113+
QUESTION_THREE: INCORRECT_ANSWER,
114+
},
115+
) as output:
116+
assert_output(
117+
output,
118+
GitAutograderStatus.UNSUCCESSFUL,
119+
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_THREE)],
120+
)

sensors_checkout/verify.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from git_autograder import (
2+
GitAutograderOutput,
3+
GitAutograderExercise,
4+
GitAutograderStatus,
5+
)
6+
from git_autograder.answers.rules import (
7+
HasExactValueRule,
8+
NotEmptyRule,
9+
)
10+
11+
QUESTION_ONE = "What's sum of values in south.csv on Jan 11th?"
12+
QUESTION_TWO = "What's sum of values in west.csv on Jan 09th?"
13+
QUESTION_THREE = "What's sum of values in north.csv on Jan 05th?"
14+
SUCCESS_MESSAGE = "Great work traversing the revision history!"
15+
16+
CORRECT_ANSWER_Q1 = "110295"
17+
CORRECT_ANSWER_Q2 = "111175"
18+
CORRECT_ANSWER_Q3 = "113705"
19+
20+
21+
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
22+
# TODO: use reflog to verify that the student traversed the revision history
23+
(
24+
exercise.answers.add_validation(
25+
QUESTION_ONE,
26+
NotEmptyRule(),
27+
HasExactValueRule(CORRECT_ANSWER_Q1, is_case_sensitive=True),
28+
)
29+
.add_validation(
30+
QUESTION_TWO,
31+
NotEmptyRule(),
32+
HasExactValueRule(CORRECT_ANSWER_Q2, is_case_sensitive=True),
33+
)
34+
.add_validation(
35+
QUESTION_THREE,
36+
NotEmptyRule(),
37+
HasExactValueRule(CORRECT_ANSWER_Q3, is_case_sensitive=True),
38+
)
39+
.validate()
40+
)
41+
42+
return exercise.to_output([SUCCESS_MESSAGE], GitAutograderStatus.SUCCESSFUL)

0 commit comments

Comments
 (0)