SHARE
TWEET

shuffle_test.sh

a guest Jun 27th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. input=/tmp/shuffle_test0$$
  4. output=/tmp/shuffle_test1$$
  5. sorted_output=/tmp/shuffle_test2$$
  6. all_output=/tmp/shuffle_test3$$
  7.  
  8. number_of_lines=4
  9. number_of_test_runs=256
  10.  
  11. i=1
  12. factorial=1
  13. while test $i -le $number_of_lines
  14. do
  15.     echo $i
  16.     factorial=$(($factorial * $i))
  17.     i=$(($i + 1))
  18. done >$input
  19.  
  20. run=1
  21. while test $run -le $number_of_test_runs
  22. do
  23.     ./shuffle.pl <$input >$output
  24.     sort -n $output >$sorted_output
  25.  
  26.     if diff $sorted_output $input >/dev/null
  27.     then
  28.  
  29.         echo `cat $output` >>$all_output
  30.     else
  31.         echo Testing failed, input was:
  32.         cat $input
  33.         echo Testing failed, output was:
  34.         cat $output
  35.         exit 1
  36.     fi
  37.     run=$(($run + 1))
  38. done
  39.  
  40. n_different_outputs=`sort $all_output|uniq|wc -l`
  41. if test $n_different_outputs -eq $factorial
  42. then
  43.     echo All possible outputs produced
  44.     exit 0
  45. else
  46.     echo In $number_of_test_runs executions only $n_different_outputs of $factorial outputs produced
  47.     exit 1
  48. fi
  49.  
  50. rm -f $input $output $sorted_output $all_output
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top