annotate tests/test-summaries.sh @ 105:76d9d86ae6cd

Add summary test with segments
author Chris Cannam
date Wed, 01 Oct 2014 17:50:58 +0100
parents fae326c22df5
children 8b4924a9a072
rev   line source
Chris@0 1 #!/bin/bash
Chris@0 2
Chris@0 3 mypath=`dirname $0`
Chris@42 4 r=$mypath/../sonic-annotator
Chris@0 5
Chris@0 6 infile=$mypath/audio/3clicks8.wav
Chris@105 7 infile2=$mypath/audio/6clicks8.wav
Chris@0 8 tmpfile=$mypath/tmp_1_$$
Chris@0 9 tmpcanonical=$mypath/tmp_2_$$
Chris@59 10 expcanonical=$mypath/tmp_exp_2_$$
Chris@16 11 tmpcmp1=$mypath/tmp_3_$$
Chris@16 12 tmpcmp2=$mypath/tmp_4_$$
Chris@0 13
Chris@59 14 trap "rm -f $tmpfile $tmpcanonical $expcanonical $tmpcmp1 $tmpcmp2" 0
Chris@0 15
Chris@28 16 . test-include.sh
Chris@28 17
Chris@28 18 faildiff() {
Chris@0 19 echo "Test failed: $1"
Chris@0 20 if [ -n "$2" -a -n "$3" ]; then
Chris@0 21 echo "Output follows:"
Chris@0 22 echo "--"
Chris@0 23 cat $2
Chris@0 24 echo "--"
Chris@0 25 echo "Expected output follows:"
Chris@0 26 echo "--"
Chris@0 27 cat $3
Chris@0 28 echo "--"
Chris@0 29 echo "Diff:"
Chris@0 30 echo "--"
Chris@28 31 sdiff -w78 $2 $3
Chris@0 32 echo "--"
Chris@0 33 fi
Chris@0 34 exit 1
Chris@0 35 }
Chris@0 36
Chris@16 37 compare() {
Chris@16 38 a=$1
Chris@16 39 b=$2
Chris@16 40 sort $a > $tmpcmp1
Chris@16 41 sort $b > $tmpcmp2
Chris@28 42 csvcompare $tmpcmp1 $tmpcmp2
Chris@16 43 }
Chris@16 44
Chris@0 45 # transform to which we have to add summarisation on command line
Chris@0 46 transform=$mypath/transforms/transforms-nosummaries-percussiononsets-detectionfunction.n3
Chris@0 47 expected=$mypath/expected/transforms-summaries-percussiononsets
Chris@0 48
Chris@0 49 stransform=$mypath/transforms/transforms-summaries-percussiononsets-detectionfunction.n3
Chris@0 50 sexpected=$mypath/expected/transforms-summaries-percussiononsets-from-rdf
Chris@0 51
Chris@0 52 $r -t $transform -w csv --csv-stdout $infile > $tmpfile 2>/dev/null || \
Chris@0 53 fail "Fails to run transform $transform"
Chris@0 54
Chris@16 55 compare $tmpfile ${expected}.csv || \
Chris@28 56 faildiff "Output mismatch for transform $transform" $tmpfile ${expected}.csv
Chris@0 57
Chris@0 58 $r -t $transform -w csv --csv-stdout -S mean $infile > $tmpfile 2>/dev/null || \
Chris@0 59 fail "Fails to run transform $transform with summary type mean"
Chris@0 60
Chris@16 61 compare $tmpfile ${expected}-with-mean.csv || \
Chris@28 62 faildiff "Output mismatch for transform $transform with summary type mean" $tmpfile ${expected}-with-mean.csv
Chris@0 63
Chris@0 64 $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 65 fail "Fails to run transform $transform with all summary types and summary-only"
Chris@0 66
Chris@16 67 compare $tmpfile ${expected}-all-summaries-only.csv || \
Chris@28 68 faildiff "Output mismatch for transform $transform with all summary types and summary-only" $tmpfile ${expected}-all-summaries-only.csv
Chris@0 69
Chris@0 70 $r -t $stransform -w csv --csv-stdout $infile > $tmpfile 2>/dev/null || \
Chris@0 71 fail "Fails to run transform $stransform with CSV output"
Chris@0 72
Chris@16 73 compare $tmpfile ${sexpected}.csv || \
Chris@28 74 faildiff "Output mismatch for transform $stransform" $tmpfile ${sexpected}.csv
Chris@0 75
Chris@102 76 $r -t $stransform -w csv --csv-stdout --summary-only $infile > $tmpfile 2>/dev/null || \
Chris@102 77 fail "Fails to run transform $stransform with CSV output and summary-only"
Chris@102 78
Chris@102 79 compare $tmpfile ${expected}-from-rdf-summaries-only.csv || \
Chris@102 80 faildiff "Output mismatch for transform $stransform with summary-only" $tmpfile ${expected}-from-rdf-summaries-only.csv
Chris@102 81
Chris@105 82 $r -t $transform -w csv --csv-stdout --summary-only -S median --segments 0,9.9 $infile2 > $tmpfile 2>/dev/null || \
Chris@105 83 fail "Fails to run transform $stransform with CSV output and segments"
Chris@105 84
Chris@105 85 compare $tmpfile ${expected}-segments.csv || \
Chris@105 86 faildiff "Output mismatch for transform $stransform with segments" $tmpfile ${expected}-segments.csv
Chris@105 87
Chris@0 88 $r -t $stransform -w rdf --rdf-stdout $infile > $tmpfile 2>/dev/null || \
Chris@0 89 fail "Fails to run transform $stransform with RDF output"
Chris@0 90
Chris@3 91 rapper -i turtle $tmpfile -o turtle 2>/dev/null | grep -v '^@prefix :' | grep -v 'file:/' > $tmpcanonical ||
Chris@0 92 fail "Fails to produce parseable RDF/TTL for transform $stransform"
Chris@0 93
Chris@59 94 rapper -i turtle ${sexpected}.n3 -o turtle 2>/dev/null | grep -v '^@prefix :' | grep -v 'file:/' > $expcanonical ||
Chris@59 95 fail "Internal error: Failed to canonicalise expected output file $expected.n3"
Chris@59 96
Chris@59 97 compare $tmpcanonical $expcanonical || \
Chris@59 98 faildiff "Output mismatch for canonicalised version of transform $stransform" $tmpcanonical $expcanonical
Chris@0 99
Chris@0 100 exit 0
Chris@0 101