aboutsummaryrefslogtreecommitdiffstats
path: root/__sum/__test
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-23 18:58:48 +0100
committerMattias Andrée <maandree@kth.se>2016-03-23 18:58:48 +0100
commitacbb72170d41f56e3b400cb3611608b52ca4f50c (patch)
tree74805025b2d6df7414b2971f568344e55d06bb7f /__sum/__test
parentimprove gitignore (diff)
downloadbase-util-tests-acbb72170d41f56e3b400cb3611608b52ca4f50c.tar.gz
base-util-tests-acbb72170d41f56e3b400cb3611608b52ca4f50c.tar.bz2
base-util-tests-acbb72170d41f56e3b400cb3611608b52ca4f50c.tar.xz
Some checksum tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '__sum/__test')
-rwxr-xr-x__sum/__test152
1 files changed, 152 insertions, 0 deletions
diff --git a/__sum/__test b/__sum/__test
new file mode 100755
index 0000000..c08cd9b
--- /dev/null
+++ b/__sum/__test
@@ -0,0 +1,152 @@
+#!/bin/bash
+
+cd -- "$(dirname "$0")"
+N=14
+if test -z "$tool"; then
+ tool=../${algo}sum
+fi
+s="$PREFIX $tool"
+
+report ()
+{
+ if test $1 = 0; then
+ printf "\033[1;32mTest %s OK\033[m\n" "$2"
+ else
+ printf "\033[1;31mTest %s FAILED\033[m\n" "$2"
+ fi
+}
+
+multiple_files_order ()
+{
+ $s $(seq 1 $N) | tr '[A-F]' '[a-f]' | sed -e 's/[\t ]*/ /' | cut -d ' ' -f 2 > tmp1
+ < $algo sed -e 's/ */ /' | cut -d ' ' -f 2 > tmp2
+ diff tmp1 tmp2 > /dev/null
+ report $? "multiple_files_order"
+ rm tmp1 tmp2
+}
+
+multiple_files_delim ()
+{
+ $s $(seq 1 $N) | tr '[A-F]' '[a-f]' | sed -e 's/^[0-9a-f]*//' | sort > tmp1
+ seq 1 $N | sed -e 's/^/ /' | sort > tmp2
+ diff tmp1 tmp2 > /dev/null
+ report $? "multiple_files_delim"
+ rm tmp1 tmp2
+}
+
+multiple_files_sum ()
+{
+ $s $(seq 1 $N) | tr '[A-F]' '[a-f]' | sed -e 's/\t/ /' | cut -d ' ' -f 1 | sort > tmp1
+ < $algo cut -d ' ' -f 1 | sort > tmp2
+ diff tmp1 tmp2 > /dev/null
+ report $? "multiple_files_sum"
+ rm tmp1 tmp2
+}
+
+multiple_files ()
+{
+ $s $(seq 1 $N) | tr '[A-F]' '[a-f]' > tmp1
+ diff tmp1 $algo > /dev/null
+ report $? "multiple_files"
+ rm tmp1
+}
+
+one_file ()
+{
+ $s 1 | tr '[A-F]' '[a-f]' > tmp1
+ < $algo head -n 1 > tmp2
+ diff tmp1 tmp2 > /dev/null
+ report $? "one_file"
+ rm tmp1
+}
+
+stdin ()
+{
+ $s < 1 | tr '[A-F]' '[a-f]' | sed 's/[\t ]/ /' | cut -d ' ' -f 1 > tmp1
+ < $algo head -n 1 | cut -d ' ' -f 1 > tmp2
+ diff tmp1 tmp2 > /dev/null
+ report $? "stdin"
+ rm tmp1
+}
+
+dash ()
+{
+ $s - < 1 | tr '[A-F]' '[a-f]' | sed 's/[\t ]/ /' | cut -d ' ' -f 1 > tmp1
+ < $algo head -n 1 | cut -d ' ' -f 1 > tmp2
+ diff tmp1 tmp2 > /dev/null
+ report $? "dash"
+ rm tmp1
+}
+
+check_file_match ()
+{
+ $s $(seq 1 $N) > tmp1
+ $s -c tmp1 > /dev/null
+ report $? "check_file_match"
+ rm tmp1
+}
+
+check_stdin_match ()
+{
+ $s $(seq 1 $N) > tmp1
+ $s -c < tmp1 > /dev/null
+ report $? "check_stdin_match"
+ rm tmp1
+}
+
+check_dash_match ()
+{
+ $s $(seq 1 $N) > tmp1
+ $s -c - < tmp1 > /dev/null
+ report $? "check_dash_match"
+ rm tmp1
+}
+
+check_file_mismatch ()
+{
+ $s $(seq 1 $N) | tr '[a-f]' '[1-6]' | tr '[A-F]' '[1-6]' > tmp1
+ ! $s -c tmp1 > /dev/null 2> /dev/null
+ report $? "check_file_mismatch"
+ rm tmp1
+}
+
+check_stdin_mismatch ()
+{
+ $s $(seq 1 $N) | tr '[a-f]' '[1-6]' | tr '[A-F]' '[1-6]' > tmp1
+ ! $s -c < tmp1 > /dev/null 2> /dev/null
+ report $? "check_stdin_mismatch"
+ rm tmp1
+}
+
+check_dash_mismatch ()
+{
+ $s $(seq 1 $N) | tr '[a-f]' '[1-6]' | tr '[A-F]' '[1-6]' > tmp1
+ ! $s -c - < tmp1 > /dev/null 2> /dev/null
+ report $? "check_dash_mismatch"
+ rm tmp1
+}
+
+check_case ()
+{
+ $s $(seq 1 $N) | tr '[A-F]' '[a-f]' > tmp1
+ tr '[a-f]' '[A-F]' < tmp1 > tmp2
+ $s -c tmp1 > /dev/null && $s -c tmp2 > /dev/null
+ report $? "check_case"
+ rm tmp1 tmp2
+}
+
+
+if test $# = 0; then
+ set multiple_files_order multiple_files_delim multiple_files_sum multiple_files one_file \
+ stdin dash check_file_match check_stdin_match check_dash_match check_file_mismatch \
+ check_stdin_mismatch check_dash_mismatch check_case
+fi
+(
+for f in $@; do
+ $f
+done
+) | tee result
+! grep FAILED < result >/dev/null
+ret=$?
+rm result
+exit $ret