Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veltman committed Sep 6, 2016
1 parent 422b241 commit 38199dc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion audiogram/waveform.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function processSamples(samples, numFrames, samplesPerFrame) {

var adjusted = unadjusted.map(function(frame){
return frame.map(function(point){
return [adjustment * point[0], adjustment * point[1]];
return point.map(function(p){ return adjustment * p; });
});
});

Expand Down
14 changes: 14 additions & 0 deletions test/probe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ tape("MP3 probe", function(test) {

});

tape("Mono probe", function(test) {

probe(path.join(__dirname, "data/glazed-donut-mono.mp3"), function(err, data){

test.error(err);
test.equal(typeof data.duration, "number");
test.equal(data.channels, 1);
test.assert(Math.abs(data.duration - 26.67) < 0.1);
test.end();

});

});

tape("WAV probe", function(test) {

probe(path.join(__dirname, "data/glazed-donut.wav"), function(err, data){
Expand Down
52 changes: 31 additions & 21 deletions test/waveform-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var tape = require("tape"),
path = require("path");

var getWaveform = require("../audiogram/waveform.js"),
var Audiogram = require("../audiogram/"),
getWaveform = require("../audiogram/waveform.js"),
probe = require("../lib/probe.js");

var sample = path.join(__dirname, "data/glazed-donut.mp3");
Expand All @@ -17,18 +18,17 @@ tape("Waveform", function(test) {

test.error(e1);

options.channels = data.channels;
options.numFrames = Math.floor(data.duration * options.framesPerSecond);

getWaveform(sample, options, function(e2, waveform){

test.error(e2);
test.assert(Array.isArray(waveform) && waveform.length === Math.floor(data.duration * options.framesPerSecond));

var firstMax = Math.max.apply(null, waveform[0].map(function(d){ return d[1]; }));

test.assert(firstMax <= 1);
test.assert(Array.isArray(waveform) && waveform.length === options.numFrames);

test.assert(waveform.every(function(frame){
return frame.length === options.samplesPerFrame && frame.every(function(f){
return f.length === 2 && typeof f[0] === "number" && typeof f[1] === "number" && f[0] <= 0 && f[0] >= -1 && f[1] >= 0 && f[1] <= firstMax;
return f.length === 3 && f.every(function(d){ return typeof d === "number"; }) && f[0] <= 0 && f[0] >= -1 && f[1] >= 0 && f[1] <= 1 && f[2] >= -1 && f[2] <= 1;
});
}));

Expand All @@ -42,33 +42,43 @@ tape("Waveform", function(test) {

tape("Max Duration Error", function(test) {

var options = {
framesPerSecond: 20,
samplesPerFrame: 10,
maxDuration: 20
var audiogram = new Audiogram("xyz");
audiogram.audioPath = sample;
audiogram.settings = {
theme: {
maxDuration: 20
}
};

getWaveform(sample, options, function(err, waveform){

audiogram.getWaveform(function(err, waveform){
test.assert(err);
test.assert(err.toString().match(/Exceeds max duration/));
test.end();

});

});

tape("Max Duration OK", function(test) {

var options = {
framesPerSecond: 20,
samplesPerFrame: 10,
maxDuration: 30
var audiogram = new Audiogram("xyz");
audiogram.audioPath = sample;
audiogram.settings = {
theme: {
samplesPerFrame: 10,
framesPerSecond: 20
}
};

getWaveform(sample, options, function(err, waveform){
probe(sample, function(err, data){
test.deepEqual(Math.round(data.duration), 27);
test.deepEqual(data.channels, 2);

test.error(err);
test.end();
audiogram.getWaveform(function(waveformErr, waveform){
test.error(waveformErr);
test.assert(Array.isArray(waveform));
test.deepEqual(waveform.length, Math.floor(data.duration * audiogram.settings.theme.framesPerSecond));
test.end();
});

});

Expand Down

0 comments on commit 38199dc

Please sign in to comment.