annotate tests/test-summaries.sh @ 16:0f7c8b9410ef sonic-annotator-0.2

* update tests
author Chris Cannam
date Fri, 20 Mar 2009 17:31:40 +0000
parents 03a02c1f0a9f
children 102bb1729184
rev   line source
Chris@0 1 #!/bin/bash
Chris@0 2
Chris@0 3 mypath=`dirname $0`
Chris@3 4 r=$mypath/../runner/sonic-annotator
Chris@0 5
Chris@0 6 infile=$mypath/audio/3clicks8.wav
Chris@0 7 tmpfile=$mypath/tmp_1_$$
Chris@0 8 tmpcanonical=$mypath/tmp_2_$$
Chris@16 9 tmpcmp1=$mypath/tmp_3_$$
Chris@16 10 tmpcmp2=$mypath/tmp_4_$$
Chris@0 11
Chris@16 12 trap "rm -f $tmpfile $tmpcanonical $tmpcmp1 $tmpcmp2" 0
Chris@0 13
Chris@0 14 fail() {
Chris@0 15 echo "Test failed: $1"
Chris@0 16 if [ -n "$2" -a -n "$3" ]; then
Chris@0 17 echo "Output follows:"
Chris@0 18 echo "--"
Chris@0 19 cat $2
Chris@0 20 echo "--"
Chris@0 21 echo "Expected output follows:"
Chris@0 22 echo "--"
Chris@0 23 cat $3
Chris@0 24 echo "--"
Chris@0 25 echo "Diff:"
Chris@0 26 echo "--"
Chris@0 27 diff -u $2 $3
Chris@0 28 echo "--"
Chris@0 29 fi
Chris@0 30 exit 1
Chris@0 31 }
Chris@0 32
Chris@16 33 compare() {
Chris@16 34 a=$1
Chris@16 35 b=$2
Chris@16 36 sort $a > $tmpcmp1
Chris@16 37 sort $b > $tmpcmp2
Chris@16 38 cmp -s $tmpcmp1 $tmpcmp2
Chris@16 39 }
Chris@16 40
Chris@0 41 # transform to which we have to add summarisation on command line
Chris@0 42 transform=$mypath/transforms/transforms-nosummaries-percussiononsets-detectionfunction.n3
Chris@0 43 expected=$mypath/expected/transforms-summaries-percussiononsets
Chris@0 44
Chris@0 45 stransform=$mypath/transforms/transforms-summaries-percussiononsets-detectionfunction.n3
Chris@0 46 sexpected=$mypath/expected/transforms-summaries-percussiononsets-from-rdf
Chris@0 47
Chris@0 48 $r -t $transform -w csv --csv-stdout $infile > $tmpfile 2>/dev/null || \
Chris@0 49 fail "Fails to run transform $transform"
Chris@0 50
Chris@16 51 compare $tmpfile ${expected}.csv || \
Chris@0 52 fail "Output mismatch for transform $transform" $tmpfile ${expected}.csv
Chris@0 53
Chris@0 54 $r -t $transform -w csv --csv-stdout -S mean $infile > $tmpfile 2>/dev/null || \
Chris@0 55 fail "Fails to run transform $transform with summary type mean"
Chris@0 56
Chris@16 57 compare $tmpfile ${expected}-with-mean.csv || \
Chris@0 58 fail "Output mismatch for transform $transform with summary type mean" $tmpfile ${expected}-with-mean.csv
Chris@0 59
Chris@0 60 $r -t $transform -w csv --csv-stdout -S min -S max -S mean -S median -S mode -S sum -S variance -S sd -S count --summary-only $infile > $tmpfile 2>/dev/null || \
Chris@0 61 fail "Fails to run transform $transform with all summary types and summary-only"
Chris@0 62
Chris@16 63 compare $tmpfile ${expected}-all-summaries-only.csv || \
Chris@0 64 fail "Output mismatch for transform $transform with all summary types and summary-only" $tmpfile ${expected}-all-summaries-only.csv
Chris@0 65
Chris@0 66 $r -t $stransform -w csv --csv-stdout $infile > $tmpfile 2>/dev/null || \
Chris@0 67 fail "Fails to run transform $stransform with CSV output"
Chris@0 68
Chris@16 69 compare $tmpfile ${sexpected}.csv || \
Chris@0 70 fail "Output mismatch for transform $stransform" $tmpfile ${sexpected}.csv
Chris@0 71
Chris@0 72 $r -t $stransform -w rdf --rdf-stdout $infile > $tmpfile 2>/dev/null || \
Chris@0 73 fail "Fails to run transform $stransform with RDF output"
Chris@0 74
Chris@3 75 rapper -i turtle $tmpfile -o turtle 2>/dev/null | grep -v '^@prefix :' | grep -v 'file:/' > $tmpcanonical ||
Chris@0 76 fail "Fails to produce parseable RDF/TTL for transform $stransform"
Chris@0 77
Chris@16 78 compare $tmpcanonical ${sexpected}.n3 || \
Chris@0 79 fail "Output mismatch for canonicalised version of transform $stransform" $tmpcanonical ${sexpected}.n3
Chris@0 80
Chris@0 81 exit 0
Chris@0 82