stalin-sort
stalin-sort copied to clipboard
Test folder
I belive that would be good to have a folder with some default inputs and outputs, so anyone that wants to add some solution in any given language must post with it the outputs of his code too, its kind important to have some sort of validation to the added codes.
My idea is to create a folder with numbered folders in it, related to the number of the test, so if exists 20 tests, the folder tests will contain 20 folders numbered from 1 to 20.
stalin-sort/tests/1...20
In each of this folders will exist 2 .txt files, one called input and other one called output. This files will contain numbers with pipes ( | ) between them.
EXAMPLE
stalin-sort/tests/1
input.txt
1|2|3|4|5|2
output.txt
1|2|3|4|5
If implementations support reading from stdin we could create a testbench that feeds random sequences in and verifies it's correctness .
One testbench could be to verify it's sorted:
for i in `seq 1000`; do echo $RANDOM; done | CALL IMPL | sort -n -c
Example with awk StalinSort:
for i in `seq 1000`; do echo $RANDOM; done | awk '{if (f <= $1) { print $1; f=$1+0}}' | sort -c -n
Second step would be to compare the output to a known correct implementation.
A third step would be to verify that the output is truly O(n), which might be trickier.
I suggest :
# make test folder
mkdir test
# create 20 test files
# 1. Vertical (Each number is separated by a break line)
seq 20 | while read i;do shuf -rn100 -i1-1000 > test/$i;done
# 2. Horizontal (Each number is separated by a space)
seq 20 | while read i;do shuf -rn100 -i1-1000 | xargs > test/$i;done
That's enough.