Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sensors_checkout/.gitmastery-exercise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"exercise_name": "sensors-checkout",
"tags": [
"git-checkout"
],
"requires_git": true,
"requires_github": true,
"base_files": {},
"exercise_repo": {
"repo_type": "remote",
"repo_name": "sensors",
"repo_title": "gm-sensors",
"create_fork": false,
"init": null
}
}
11 changes: 11 additions & 0 deletions sensors_checkout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# sensors-checkout

A system is using Git to record data received daily from for sensors, each monitoring one of directions east, west, north, south. Each sensor provides 20 integer values, which are stored in a csv file (e.g., values from the sensor monitoring the east direction are recorded as east.csv). Data for each day is recorded as one commit.

## Task

Traverse the revision history to answer the following questions in `answers.txt`.

## Hints

Tip: You can use the bash command `awk '{s+=$1} END {print s}' south.csv` to find the sum of values in `south.csv` (and so on). Alternatively, you can open the csv file in a spreadsheet program and use a feature of that program to find the sum.
Empty file added sensors_checkout/__init__.py
Empty file.
1 change: 1 addition & 0 deletions sensors_checkout/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def setup(verbose: bool = False): ...
8 changes: 8 additions & 0 deletions sensors_checkout/res/answers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Q: What's sum of values in south.csv on Jan 11th?
A:

Q: What's sum of values in west.csv on Jan 09th?
A:

Q: What's sum of values in north.csv on Jan 05th?
A:
Empty file.
6 changes: 6 additions & 0 deletions sensors_checkout/tests/specs/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
initialization:
steps:
- type: commit
empty: true
message: Empty commit
id: start
120 changes: 120 additions & 0 deletions sensors_checkout/tests/test_verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
from git_autograder.answers.rules.not_empty_rule import NotEmptyRule
from git_autograder.answers.rules.has_exact_value_rule import HasExactValueRule
from git_autograder.status import GitAutograderStatus
from git_autograder.test_utils import assert_output
from git_autograder import GitAutograderTestLoader

from ..verify import (
QUESTION_ONE,
QUESTION_TWO,
QUESTION_THREE,
CORRECT_ANSWER_Q3,
CORRECT_ANSWER_Q2,
CORRECT_ANSWER_Q1,
SUCCESS_MESSAGE,
verify,
)

REPOSITORY_NAME = "sensors-checkout"

loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)

INCORRECT_ANSWER = "incorrect answer"


def test_correct_answers():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_ANSWER_Q1,
QUESTION_TWO: CORRECT_ANSWER_Q2,
QUESTION_THREE: CORRECT_ANSWER_Q3,
},
) as output:
assert_output(output, GitAutograderStatus.SUCCESSFUL, [SUCCESS_MESSAGE])


def test_incomplete_answers():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_ANSWER_Q1,
QUESTION_TWO: CORRECT_ANSWER_Q2,
QUESTION_THREE: "",
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[
NotEmptyRule.EMPTY.format(question=QUESTION_THREE),
],
)


def test_no_answers():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: "",
QUESTION_TWO: "",
QUESTION_THREE: "",
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[
NotEmptyRule.EMPTY.format(question=QUESTION_ONE),
NotEmptyRule.EMPTY.format(question=QUESTION_TWO),
NotEmptyRule.EMPTY.format(question=QUESTION_THREE),
],
)


def test_incorrect_q1():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: INCORRECT_ANSWER,
QUESTION_TWO: CORRECT_ANSWER_Q2,
QUESTION_THREE: CORRECT_ANSWER_Q3,
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_ONE)],
)


def test_incorrect_q2():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_ANSWER_Q1,
QUESTION_TWO: INCORRECT_ANSWER,
QUESTION_THREE: CORRECT_ANSWER_Q3,
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_TWO)],
)


def test_incorrect_q3():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_ANSWER_Q1,
QUESTION_TWO: CORRECT_ANSWER_Q2,
QUESTION_THREE: INCORRECT_ANSWER,
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_THREE)],
)
42 changes: 42 additions & 0 deletions sensors_checkout/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from git_autograder import (
GitAutograderOutput,
GitAutograderExercise,
GitAutograderStatus,
)
from git_autograder.answers.rules import (
HasExactValueRule,
NotEmptyRule,
)

QUESTION_ONE = "What's sum of values in south.csv on Jan 11th?"
QUESTION_TWO = "What's sum of values in west.csv on Jan 09th?"
QUESTION_THREE = "What's sum of values in north.csv on Jan 05th?"
SUCCESS_MESSAGE = "Great work traversing the revision history!"

CORRECT_ANSWER_Q1 = "110295"
CORRECT_ANSWER_Q2 = "111175"
CORRECT_ANSWER_Q3 = "113705"


def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
# TODO: use reflog to verify that the student traversed the revision history
(
exercise.answers.add_validation(
QUESTION_ONE,
NotEmptyRule(),
HasExactValueRule(CORRECT_ANSWER_Q1, is_case_sensitive=True),
)
.add_validation(
QUESTION_TWO,
NotEmptyRule(),
HasExactValueRule(CORRECT_ANSWER_Q2, is_case_sensitive=True),
)
.add_validation(
QUESTION_THREE,
NotEmptyRule(),
HasExactValueRule(CORRECT_ANSWER_Q3, is_case_sensitive=True),
)
.validate()
)

return exercise.to_output([SUCCESS_MESSAGE], GitAutograderStatus.SUCCESSFUL)