gustavo-depaula / stalin-sort

Add a stalin sort algorithm in any language you like ❣️ if you like give us a ⭐️
MIT License
1.5k stars 174 forks source link

Test folder #41

Open gabrielcarneiro97 opened 5 years ago

gabrielcarneiro97 commented 5 years ago

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
ration commented 5 years ago

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.

eggplants commented 5 years ago

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.