You will find here my testers for weekly challenges.
- How to use?
- New tester (Challenge 73 and newer)
- Supported Python version
- Old tester (Challenge 72 and older)
- Some possible errors
- How to download individual challenge tester/file from GitHub?
Download tester file test_challenge_XX.py
and file with test cases test_cases.json
place them in same folder where is your file with solution.
Make sure Python has right to save to this folder.
This tester will create one file temp_solution_file.py
make sure there's no such
file in same folder or there's nothing important in it cos it will be overwritten!
You can configure tester editing tester file and changing CONFIGURATION
section or using command line arguments.
Run with flag -h
or --help
for more information how to use command line arguments.
python test_challenge_99.py --help
Change SOLUTION_SRC_FILE_NAME
to your file name in CONFIGURATION
section or use -s solution_file.py
.
Use -c command
or change OTHER_LANG_COMMAND
to command to run your solution for not compiled languages or to already compiled executable for compiled languages. For multiword command
command line argument surround it in quotes "multi word command"
OTHER_LANG_COMMAND = "Cpp/c99_cpp.exe" # relative to tester file path to compiled windows executable
OTHER_LANG_COMMAND = "/home/user/Dev/Challenge99/c99_c" # absolute path to compiled Linux executable
OTHER_LANG_COMMAND = "c99_rust.exe" # name of compiled file in same folder as tester
OTHER_LANG_COMMAND = "java -cp Java/ c99_java.Main" # command to run solution in non compiled language
OTHER_LANG_COMMAND = "" # leave empty if you want to test python solution
> python test_challenge_99.py -c "java -cp Java/ c99_java.Main"
$ python test_challenge_99.py -c Rust/c99_rust/target/release/c99_rust
If you want to see your solution length in other languages then Python change SOLUTION_FILE_NAME
to your solution source code file name.
If this tester wasn't prepared by me for the challenge you want to test, you may need to adjust other configuration settings. Read the comments on each.
If you want use own test_cases, they must be in json format.
[
[ # this list can be in separated file for inputs only
["test case 1"], # multiline case ["line_1", "line_2", ... ,"line_n"]
["test case 2"],
...
["test case n"]
],
[ # and this for output only
"output 1",
"output 2",
...
"output n"
]
]
All values must be strings! Cast all ints, floats, etc. to str before dumping json!
- Python 3.8+ works without modification
- Python 3.7 you need to comment out line
otter="\N{otter}",
- Python 3.6 you need to comment out lines:
from dataclasses import dataclass
- both lines that have
@dataclass
- comment out whole block starting with line
if Config.USE_EMOJI:
up to and includingelse:
and unindent next line
- older Python version not supported
Download tester file test_challenge_XX.py
and file with test cases test_cases_ch_XX.py
place them in same folder where is your file with solution.
Import your solution in line 92
, and run tester file
> python test_challenge_XX.py
If you see some weird chars instead of colors in output or don't want colors
switch COLOR_OUT
to False
in line 30
If there is more than one test_cases_ch_XXx.py
file you can change import in line 28
or rename test case file removing letter after challenge number to use it.
WARNING: My tester ignores printing in input()
but official tester FAILS if you print something in input()
Don't do that:
input("What is the test number?")
Use empty input: input()
-
None
in"Your output"
: Your solution didn't print for all cases. -
None
in"Input"
: Your solution print more times then there is cases.- If you see
None
in"Input"
or"Your output"
don't check failed cases until you fix problem with printing, cos "Input" and "Your output" are misaligned after first missing/extra print
- If you see
-
"Your Output"
looks like"Expected"
but tester show its wrong. Check if you print trailing spaces. -
StopIteration
: Your solution try to get more input then there is test cases- If you use
open(0)
instead ofinput
you getStopIteration
error in my tester or tester will hang waiting for EOF char not presented in input data - to avoid this use one of:
- set
OTHER_LANG_COMMAND = "python to_submit_ch_99.py"
- run
python test_challenge_99.py -c "python to_submit_ch_99.py"
- set
- If you use
-
If you call your functions inside
if __name__ == '__main__':
your functions wont be called by default cos your solution is imported.- to avoid this use one of:
- set
OTHER_LANG_COMMAND = "python to_submit_ch_99.py"
- run
python test_challenge_99.py -c "python to_submit_ch_99.py"
- or don't use
if __name__ == '__main__':
- set
- to avoid this use one of:
You can switch branch to branch with that challenge, then click Code
and Download ZIP
Or in Releases section click Challenge XX
and download source_code (...)
.
Or from command line:
# Linux
$ wget https://raw.githubusercontent.com/Pomroka/TWT_Challenges_Tester/master/Challenge_99/test_cases.json
# Windows 10
> curl -o test_cases.json https://raw.githubusercontent.com/Pomroka/TWT_Challenges_Tester/master/Challenge_99/test_cases.json
Or use https://downgit.github.io/#/home (ready to use link in Challenge_XX.md)