some minor test file restructuring

This commit is contained in:
Spencer Russell 2014-08-11 18:09:51 -04:00
parent 89043b80c9
commit 10802a61f3
3 changed files with 11 additions and 46 deletions

View file

@ -9,24 +9,6 @@ const TEST_BUF_SIZE = 1024
include("testhelpers.jl")
# convenience function to calculate the mean-squared error
function mse(arr1::Array, arr2::Array)
@assert length(arr1) == length(arr2)
N = length(arr1)
err = 0.0
for i in 1:N
err += (arr2[i] - arr1[i])^2
end
err /= N
end
mse(X::AbstractArray, thresh=1e-8) = Y::AbstractArray -> begin
if size(X) != size(Y)
return false
end
return mse(X, Y) < thresh
end
type TestAudioStream <: AudioIO.AudioStream
root::AudioIO.AudioMixer
@ -99,27 +81,6 @@ facts("AudioNode Stopping") do
@fact process(test_stream) => zeros(AudioIO.AudioSample, TEST_BUF_SIZE)
end
facts("WAV file write/read") do
fname = Pkg.dir("AudioIO", "test", "sinwave.wav")
samplerate = 44100
freq = 440
t = [0 : 2 * samplerate - 1] / samplerate
phase = 2 * pi * freq * t
reference = int16((2 ^ 15 - 1) * sin(phase))
AudioIO.open(fname, "w") do f
write(f, reference)
end
AudioIO.open(fname) do f
@fact f.sfinfo.channels => 1
@fact f.sfinfo.frames => 2 * samplerate
actual = read(f, 2 * samplerate)
@fact reference => mse(actual)
end
end
facts("Audio Device Listing") do
# there aren't any devices on the Travis machine so just test that this doesn't crash
@fact get_audio_devices() => issubtype(Array)

View file

@ -2,12 +2,8 @@ module TestAudioIONodes
using FactCheck
using AudioIO
import AudioIO.AudioSample
import AudioIO.AudioBuf
import AudioIO.AudioRenderer
import AudioIO.AudioNode
import AudioIO.DeviceInfo
import AudioIO.render
import AudioIO: AudioSample, AudioBuf, AudioRenderer, AudioNode
import AudioIO: DeviceInfo, render
include("testhelpers.jl")

View file

@ -1,5 +1,5 @@
# convenience function to calculate the mean-squared error
function mse(arr1::Array, arr2::Array)
function mse(arr1::AbstractArray, arr2::AbstractArray)
@assert length(arr1) == length(arr2)
N = length(arr1)
err = 0.0
@ -9,6 +9,14 @@ function mse(arr1::Array, arr2::Array)
err /= N
end
mse(X::AbstractArray, thresh=1e-8) = Y::AbstractArray -> begin
if size(X) != size(Y)
return false
end
return mse(X, Y) < thresh
end
issubtype(T::Type) = x -> typeof(x) <: T
lessthan(rhs) = lhs -> lhs < rhs
greaterthan(rhs) = lhs -> lhs > rhs