User:MaintenanceRequired/Scripts/Shell scripts/Testing

= allTestsPassed=true
 * 1) !/bin/sh

red=`tput setaf 1` green=`tput setaf 2` reset=`tput sgr0`

rm -rf "tests" mkdir "tests"

echo "Running tests"


 * 1) creates 100 files from 1-100. No. of lines are randomised.

for t in {1..10} do shuf -i 1-100 -n $(($RANDOM % 31)) > tests/$t done
 * 1) test 1: random numbers

for w in {11..20} do seq $(($RANDOM % 31)) $(($RANDOM % 31)) $(($RANDOM % 31 + 31)) > tests/$w done
 * 1) test 2: sequential ordering of numbers

seq 10 1 9 > tests/21 # will print an empty file
 * 1) test 3: empty file.

for w in {22..30} do seq $(($RANDOM % 31 + 31)) -$(($RANDOM % 31)) $(($RANDOM % 31)) > tests/$w done
 * 1) test 4: reversed ordering of numbers

for s in {1..30} do sort -n < tests/$s > tests/$s.expected ./useIntList < tests/$s > tests/$s.observed diff tests/$s.expected tests/$s.observed > /dev/null if [ $? -eq 0 ] then tput setaf 2; echo "test $s .. passed$(tput sgr 0)" else tput setaf 1; echo "test $s .. failed$(tput sgr 0)" sdiff tests/$s.expected tests/$s.observed $allTestsPassed = false fi done
 * 1) compare loop.

if $allTestsPassed; then echo "All tests passed! You are awesome :-)" fi

rm -rf "tests"
 * 1) cleans directory.

Documentation

 * Bash/Shell script for automated testing. Creates 100 files with random numbers in it (assumption: at least 1 number) and sorts it in ascending order.
 * ./useIntList is written in C.