A code runner, which uses the Tape.js unit-testing framework, that allows an individual student to check the correctness of his/her codes on the Command Line Interface (CLI).
The mainFunc
(where the students write the function solution) in the module.exports
object and the unit tests are passed into the Tape.js
driver "code_runner/code_runner.js". The driver runs the mainFunc
against the unit tests, and the output of the unit-testing is formatted by "code_runner/tap.js" before it is displayed on the Command Line Interface.
Ensure that the below dependencies are installed through npm
.
- tape.js (v4.9): tap-producing test harness for node and browsers
- cli-color (v1.2): Formatting for the console output.
Inside the problem folder, there should be four files:
- problem.js: Contains the problem and empty space for student's codes
- code_runner/code_runner.js: Driver of unit-tests
- code_runner/tap.js: Used for formatting the result in the command line
- code_runner/unit_test.js: Unit tests for students' codes
- code_runner/unit_test.js: Change the description of the unit tests, test cases and the expected results in the
module.exports
object. - code_runner/code_runner.js: Depending on the test cases (arguments) and the expected results, modify the line that equates expected answers to student code's output
t.equal(unitTest.answers[index], student.mainFunc(unitTest.testCases[index][0], unitTest.testCases[index][1]));
.
After writing the codes in the "problem.js" file, entering the directory code_runner and calling node tap.js code_runner.js
on his command line, the student will see the report in his CLI.
The student can go to "code_runner/unit_test.js" and modify two fields of module.exports
object:
- test cases in the
testCases
field - expected outputs in the
answers
field