1.1.0 • Published 6 years ago
scratch-judge v1.1.0
scratch-judge
A custom scratch-vm used to watch program status and output result about the program.
Usage (English)
By Bash:
npm i -g scratch-judge
scj -h
scj src/index.js -p test/test.sb3 -d test/ -o 3
# Do your own :DBy NodeJS:
const judge = require('scratch-judge')
judge({
projectFile: 'path/to/your/scratch/project/file',
fileNameFormat: '#{n}',
testFolder: 'path/to/your/test/folder',
testpoints: 10,
time: 1000,
mem: 40960,
turbo: true,
format: false
}).then((evt) => {
evt.on('point', (result) => {
// Emit when a point is finished its test.
}).on('error', (err) => {
// Emit when a point occurs an error.
}).once('end', (results) => {
// Emit when all the points are finished their test.
// Result is an array contains all the result.
})
})CLI Description
Run scj -h to check usage.
API Description
Promise judge(Object options) Start a test.
If runs as command, it will output the testing result to stdout.
Or if be invoke as module, it will return a Promise and resolve the result types of JSON.
Here is a list of available options:
String projectFilePath to the scratch project which is supported by the Scratch 3.0 and needs to be tested.String fileNameFormatOptional. The format of the file name. Will replace#{n}to the testing point number. Such asP1000-#{n}will be translated toP1000-1.inandP1000-1.out. Default is#{n}.String testFolderPath to your test folder which is included your input file like1.in1.outin order.Number testpointsOptional. The amount of testing points will be run. Default is10.Number timeOptional. Time that each testing points can use. The unit is milliseconds. Default is1000.Number memOptional. Memory that each testing points can use. The unit is kilobytes. Default is25600(25MB) iftraceFullMemoryistrue, or it's40960(4MB).Boolean turboOptional. Using turbo mode to test. Default istrue.Boolean debugOptional. Output debug message to stdout. Default isfalse.Boolean formatOptional. Output formatted json result after test. Only be used in cli. Default isfalse, output unformatted result.Boolean traceFullMemoryOptional. Trace memory of the NodeJS runtime. Or it will subtract from the memory scratch-vm running to the memory before start testing. Default istrue.
Then it will return a promise will reslove with a JudgeEvent extends on EventEmitter,
it will emit these events while testing:
pointJudgeTestingPointResultEmit when a point is finished its test. It will return a value contain the result.endJudgeTestingPointResult[]Emit when all points are finished their tests. It will return a array contains all result each testing point.errorErrorEmit when a point occurred an error. But the other testing points will not stop and continue running.
JudgeTestingPointResult struct:
numberidPoint number.stringstatusResult of the test. Such asAC,RE,TLE,MLE,WA.stringdetailsDetail of result, it will contain error string ifstatusisRE, or line number of wrong answer ifstatusisWA.ErrorerrorAn error object ifstatusisRE.numberusedTimeTime that testing point has used. In milliseconds.numberusedMemoryMemory that testing point has used. In kilobytes.string[]answerAn array of project output ifstatusisWA.
Like this project?
Feel free to give tips to me! Chinese link. (I don't have patreon sry ;-;)