This manual provides documentation for a simple Racket package for locally grading homework using RackUnit tests and a new raco grade command.
|(require rackunit/grade)||package: rackunit-grade|
If you have not installed the package yet, run the following command from the command-line:
raco pkg install rackunit-grade
Note that this package will require Racket v6.0 or newer to install.
Alternatively, you may use the GUI package manager from DrRacket to install the package.
To use RackUnit Grade, you first write a grading file, containing all required libraries, and all the tests you want to run. It is recommended to define an individual test-suite for each specific exercise in your homework. For example, let us consider the tests.rkt file, which defines tests for the my-power function:
(require rackunit) (require rackunit/grade) (define-test-suite tests-my-power (check-equal? (my-power 10 2) (expt 10 2)) (check-equal? (my-power 13 56) (expt 13 56))) (define (my-result-handler results failures numtests suite-name) (printf "~a got ~a failures out of ~a tests" suite-name failures numtests)) (evaluate-exercise tests-my-power my-result-handler)
(evaluate-exercise exercise-test result-handler) → void exercise-test : test-suite? result-handler : procedure??
results: the results object as used in fold-test-results.
failures: the number of tests that failed.
numtests: the total number of tests.
suite-name: the name of the test-suite.
Now let us consider the homework.rkt file, which contains the solution from a student:
Clearly this definition is wrong. Now, to combine the grading file with the student solution we need to use the new raco command raco grade:
raco grade homework.rkt tests.rkt
This command will generate a new file grade_homework_tests.rkt in the current directory, which is a simple copy of tests.rkt appended with a (require "homework.rkt") form. Also the new file is run, using dynamic-require. In order for this schema to work, it is required that student files provide all functions that are going to be graded.