Created
May 28, 2014 18:22
-
-
Save kernigh/db4e610e10b592286d86 to your computer and use it in GitHub Desktop.
test script for http://codegolf.stackexchange.com/q/28533/4065
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script compiles scramble.c and calculates the score. | |
# Before use, put scramble.c, $text, $pict in current directory. | |
text=pg100.txt | |
pict=filament.jpg | |
# Die if any command fails. | |
# Die if files are missing. | |
set -e | |
ls scramble.c $text $pict >/dev/null | |
dir=$(mktemp -d tmp.XXXXXXXXXX) | |
trap 'echo You may wish to rm -rf $dir' EXIT | |
echo [1/4] Compiling scramble... | |
gcc -O2 scramble.c -o $dir/scramble | |
echo [2/4] Scrambling files... | |
set +e # When scrambling, ignore exit status. | |
$dir/scramble <$text >$dir/$text.sc | |
$dir/scramble <$pict >$dir/$pict.sc | |
set -e | |
echo [3/4] Compressing scrambled files... | |
xz -kz5 $dir/$text.sc | |
xz -kz5 $dir/$pict.sc | |
echo [4/4] Checking descrambler... | |
set +e # When descrambling, ignore exit status. | |
xz -dc $dir/$text.sc.xz | $dir/scramble >$dir/$text.cp | |
xz -dc $dir/$pict.sc.xz | $dir/scramble >$dir/$pict.cp | |
set -e | |
cmp -- $text $dir/$text.cp | |
cmp -- $pict $dir/$pict.cp | |
# Grab file sizes. | |
sz() { wc -c <$1 | tr -d ' '; } | |
sz_scramble=$(sz scramble.c) | |
sz_text=$(sz $text) | |
sz_pict=$(sz $pict) | |
sz_t_sc=$(sz $dir/$text.sc) | |
sz_p_sc=$(sz $dir/$pict.sc) | |
sz_t_sx=$(sz $dir/$text.sc.xz) | |
sz_p_sx=$(sz $dir/$pict.sc.xz) | |
# Find absolute difference of original minus .sc sizes. | |
abs_minus() : $(( $1 = $2 - $3, $1 = $1 < 0 ? -$1 : $1 )) | |
abs_minus d_t_sc sz_text sz_t_sc | |
abs_minus d_p_sc sz_pict sz_p_sc | |
# Find non-negative difference of original minus .sc.xz sizes. | |
ge0_minus() : $(( $1 = $2 - $3, $1 = $1 < 0 ? 0 : $1 )) | |
ge0_minus d_t_sx sz_text sz_t_sx | |
ge0_minus d_p_sx sz_pict sz_p_sx | |
: $(( score = sz_scramble + d_t_sc + d_p_sc + d_t_sx + d_p_sx )) | |
echo SCORE: $score=$sz_scramble+$d_t_sc+$d_p_sc+$d_t_sx+$d_p_sx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment