view yetilab/vamp/test/test_vamp.yeti @ 194:8148422e9102

Rename truncatedTo to withDuration and make it able to extend as well as truncate
author Chris Cannam
date Mon, 06 May 2013 15:03:22 +0100
parents 4bd7fb9542ff
children 26111c11d8e4
line wrap: on
line source
module yetilab.vamp.test.test_vamp;

v = load yetilab.vamp.vamp;
synthetic = load yetilab.stream.syntheticstream;
filter = load yetilab.stream.filter;
mat = load yetilab.matrix.matrix;
block = load yetilab.block.block;

{ compare, compareUsing } = load yetilab.test.test;

testPluginKey = "vamp-test-plugin:vamp-test-plugin";

rate = 44100;

testStream () = filter.withDuration (rate * 20) (synthetic.whiteNoise rate);

processTest output = 
    v.processStreamStructured testPluginKey output (testStream ());

float n is number -> number =
    // round number to float precision (for comparison with floats)
   (arr = new float[1];
    arr[0] := n;
    arr[0]);

floats nn = map float nn;

tests =
[

"version": \(
    case v.loadPlugin rate testPluginKey of
    Error e: (eprintln "version: Error: \(e)"; false);
    OK plugin: compare plugin.version 1;
    esac
),

"instants": \(
    case processTest "instants" of
    Instants ii:
        compare (map (.time) ii) [ 0, 1.5, 3, 4.5, 6, 7.5, 9, 10.5, 12, 13.5 ];
    other: failWith "wrong structure type: expected Instants tag, got \(other)";
    esac
),

"curve-oss": \(
    case processTest "curve-oss" of
    Series s:
        compare s.start 0 and
        //!!! want to specify step and block size for processing
            compare s.step (2048/rate) and
            compare s.values (floats (map (* 0.05) [0..19]));
    other: failWith "wrong structure type: expected Series tag, got \(other)";
    esac
),

"curve-fsr": \(
    case processTest "curve-fsr" of
    Curve c:
        compare (map (.time) c) (map (* 0.4) [0..9]) and
           compare (map (.value) c) (floats (map (* 0.1) [0..9]));
/*
        compare s.start 0 and
            compare s.step 0.4 and
            compare s.values (floats (map (* 0.1) [0..9]));
*/
    other: failWith "wrong structure type: expected Series tag, got \(other)";
    esac
),
    
"curve-fsr-timed": \(
    case processTest "curve-fsr-timed" of
    Curve c:
        compare (map (.time) c) [ 0, 0, 0, 0.4, 2, 2, 2, 2.4, 4, 4 ] and
           compare (map (.value) c) (floats (map (* 0.1) [0..9]));
    other: failWith "wrong structure type: expected Curve tag, got \(other)";
    esac
),

"curve-vsr": \(
    case processTest "curve-vsr" of
    Curve c:
        compare (map (.time) c) (map (* 0.75) [0..9]) and
           compare (map (.value) c) (floats (map (* 0.1) [0..9]));
    other: failWith "wrong structure type: expected Curve tag, got \(other)";
    esac
),

"grid-oss": \(
    case processTest "grid-oss" of //!!! test spacing?
    Grid g:
        compareUsing mat.equal g 
           (mat.newMatrix (ColumnMajor ())
               (map do x:
                   (block.fromList . floats) (map do y:
                        (x + y + 2) / 30
                        done [0..9])
                    done [0..19]));
    other: failWith "wrong structure type: expected Grid tag, got \(other)";
    esac
),

"grid-fsr": \(
    case processTest "grid-fsr" of //!!! test spacing?
    Grid g:
        compareUsing mat.equal g 
           (mat.newMatrix (ColumnMajor ())
               (map do x:
                   (block.fromList . floats) (map do y:
                        (x + y + 2) / 20
                        done [0..9])
                    done [0..9]));
    other: failWith "wrong structure type: expected Grid tag, got \(other)";
    esac
),

"notes-regions": \(
    case processTest "notes-regions" of
    Regions rr:
        compare (map (.time) rr) [0..9] and
           compare (map (.duration) rr) (map do i: Time (if i % 2 == 0 then 1.75 else 0.5 fi) done [0..9]) and
           compare (map (.values) rr) (map do i: array [float i] done (map (* 0.1) [0..9]));
    other: failWith "wrong structure type: expected Curve tag, got \(other)";
    esac
),
    
];

// Check we have the test plugin. Without it, all the tests must fail

if contains? testPluginKey v.pluginKeys then 
    tests
else
    eprintln
"** The test plugin is not installed, or the Vamp module is totally broken.
   Ensure vamp-test-plugin is in the Vamp path or set $VAMP_PATH to point to it.
   (The path is currently \(v.pluginPath).)
   All Vamp plugin tests will fail until this is fixed.";
    mapIntoHash id \\false (keys tests)
fi is hash<string, () -> boolean>;