Reference¶
- class hsgrader.Equality(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Class with values that indicate how strict equality
- LOOSE¶
Combination of extra space and empty lines
- STRICT¶
Files should be exactly the same
- WITH_EMPTY_LINES¶
Extra empty lines are permitted
- WITH_EXTRA_SPACE¶
One or more white space characters count as one space
- class hsgrader.GraderBase¶
Class to be used as a base class for grading Haskell assignments
- build(name: str, main_file: str)¶
Build a program to be run later.
If this build fails, the output of the compiler will be shown to the user.
- Parameters:
name (str) – A name used by Prairielearn for reporting
main_file (str) – The name of the Haskell file that contains the main function. The file is relative to the tests directory.
- Returns:
a Program manager. That is some opaque type such that
prog
in the constructwith build(...) as prog
has typeProgram
.
- points_to_score(max_points: float, awarded: float) float ¶
This function computes the total score (between 0.0 and 1.0)
- Parameters:
max_points – the number of points that could be obtained
awarded – the number of points that were awarded
- Returns:
the score, a float between 0.0 and 1.0
This function divides awarded by max_points.
You may override this behaviour by overriding this function in your derived class. For instance, have a score of 1 if all points were awarded and of 0 in other cases.
- start() None ¶
The entry point of the class
The user of the class should call this method to start the tests. This will set things up, call tests and then return the results to Prairielearn. The user should not call any other methods from this class directly. They should be called from tests.
- tests() None ¶
Function that should be implemented in the subclass
- class hsgrader.Program(name: str, output: str, prog: str | None, result)¶
A class that contains a program that was built
- build_bonus(name: str, points: float = 1)¶
Award points if the build succeeded
- Parameters:
name (str) – A name used by Prairielearn for reporting
points (float) – The number of points awarded when this run succeeds. The default value 1.
- run_and_check(name: str, args: Iterable[str] | str, expected_output: str, /, points: float = 1, cmp: Equality = Equality.STRICT, expected_status: int | None = 0)¶
Run a program built earlier and check the output
The standard output written by the program is compared to the contents of a file. The results of this run are reported by Prairielearn.
- Parameters:
name (str) – A name used by Prairielearn for reporting
args ([str]) – The command line arguments that are provided to the program.
expected_output (str) – The file name, relative to directory tests/expected, that contains the expected content of the output.
points (float) – (keyword argument) The number of points awarded when this run succeeds (default: 1).
cmp (Equality) – (keyword argument) Influences how strict the comparison with the expected output is.
expected_status (int) – (keyword argument) The program status that indicates a succesful run (default: 0). If the value is None, the program status is not taken into account. Otherwise, the status must be this value, before proceeding to comparison of the content at all.
- run_with_status(name: str, args: Iterable[str] | str = [], /, points: float = 1, expected_status: int = 0)¶
Run a program built earlier and check the output status
The results of this run are reported by Prairielearn.
- Parameters:
name (str) – A name used by Prairielearn for reporting
args ([str]) – The command line arguments that are provided.
points (float) – The number of points awarded when this run succeeds. This is a keyword argument with default value 1.
expected_status – The program status that indicates a succesful run (default: 0, keyword argument)