Quick Start¶
Painless Test¶
Firstly, we need to create a new special judge function, like the following code in spj_demo.py
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | def spj_func(stdin, stdout): inputs = [int(item.strip()) for item in stdin.read().strip().split(' ') if item] _correct_sum = sum(inputs) outputs = stdout.read().strip().split(' ', maxsplit=2) if len(outputs) >= 1: _result = int(outputs[0]) else: return False, 'No output found.' if _result == _correct_sum: return True, 'Correct result.', 'Oh yeah, well done ^_^.' else: return False, 'Result {correct} expected but {actual} found.'.format( correct=repr(_correct_sum), actual=repr(_result) ) __spj__ = spj_func |
Then test a simple pair of input and output by the following command line.
1 | pyspj -i '1 2 3 4 5' -o 15 -s spj_demo |
The output should be
1 | {"correctness": true, "detail": "Oh yeah, well done ^_^.", "message": "Correct result."} |
But when wrong output is given like below
1 | pyspj -i '1 2 3 4 5' -o 16 -s spj_demo |
1 | {"correctness": false, "detail": "Result 15 expected but 16 found.", "message": "Result 15 expected but 16 found."} |
Use File Input/Ouput Instead¶
When the scale of input and output are too large, we can use -I
and -O
option to input from file or output to file.
Here is an example if input file input_demo.txt
1 | 1 2 3 4 5 6 7 8 9 10 |
And an output file output_demo.txt
1 | 55 |
When the following command is executed
1 | pyspj -I input_demo.txt -O output_demo.txt -s spj_demo |
The output result should be
1 | {"correctness": true, "detail": "Oh yeah, well done ^_^.", "message": "Correct result."} |
Pretty Print the Result¶
The output result is a json-formatted string, and it is placed in one line in default. So if you want it to be prettily printed, the following command can be used.
1 | pyspj -i '1 2 3 4 5' -o 15 -s spj_demo -p |
Its output should be
1 2 3 4 5 | { "correctness": true, "detail": "Oh yeah, well done ^_^.", "message": "Correct result." } |